-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.Datatypes.vb
4089 lines (3453 loc) · 141 KB
/
2.Datatypes.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.Web.Script.Serialization
Imports System.Windows.Forms
Imports SystemExtensions.AI_SDK_EXTENSIONS.Strings
Imports SystemExtensions.Datatypes.Syllogism
Namespace Datatypes
Namespace Intents
''' <summary>
''' Data Required to full-fill action
''' </summary>
Public Structure Slot
#Region "Fields"
Public ConfirmationPhrase As String
Public Data As String
Public EntityType As String
Public Filled As Boolean
#End Region
End Structure
End Namespace
''' <summary>
''' QuestionTypes are
'''place 'Where is X - Returns Answer to Question (Where is becomes the subject) X is at location of Subject
'''time 'When was - Returns Answer to Question (when was X) X was Subject
'''person 'Who is - Returns Answer to Question - Object becomes the search term for answer replaced by Subject
'''reason 'Why is - Returns Answer to Question
'''description 'What is - Returns Answer to Question
'''instruction 'How do - Returns Answer to Question
'''Choice 'Which X, either X or Y - Returns Selected choice from input (Which becomes the Subject X and Y are both the objects)
'''Possession 'Whose X is? - returns Question about Ownership (Whose is the subject X is the object) X belongs to object
''' </summary>
Public Enum _QuestionType
place 'Where is - Returns Answer to Question
time 'When was - Returns Answer to Question
person 'Who is - Returns Answer to Question
reason 'Why is - Returns Answer to Question
description 'What is - Returns Answer to Question
instruction 'How do - Returns Answer to Question
Choice 'Which X, either X or Y - Returns Selected choice from input
Possession 'Whose X is? - returns Question about Ownwership
End Enum
''' <summary>
''' These are the standard concept types / The future types will be a list collected fromt the
''' database the database will only have dynamic predicate types
''' </summary>
Public Enum ConceptType
'Thing
CapeableOf 'Something that A can typically do is B.
ConceptuallyRelatedTo 'The most general relation. There is some positive relationship between A and B, but ConceptNet can't determine what that relationship is based on the data. This was called "ConceptuallyRelatedTo" in
CapableOfReceivingAction ' Subject A can be eaten, can be washed
DefinedAs 'A and B overlap considerably in meaning, and B is a more explanatory version of A. (This is similar to TranslationOf, but within one language.)
DesireOf 'A is a conscious entity that typically wants B. Many assertions of this type use the appropriate language's word for "person" as A
DesirousEffectOf 'Jump / is to land
EffectOf 'Singing / is to Entertain
IsA 'A is a subtype or a specific instance of B; every A is a B. (We do not make the type-token distinction, because people don't usually make that distinction.) This is the hyponym relation in WordNet.
MadeOf 'A has composition property's of
MotivationOf 'Someone does A because they want result B; A is a step toward accomplishing the goal B.
PartOf 'A is a part of B. This is the part meronym relation in WordNet.
PropertyOf 'A has B as a property; A can be described as B.
UsedFor 'A is used for B; the purpose of A is B.
'Event
FirstSubEventOf 'A is an event that begins with subevent B.
LastSubEventOf 'A is an event that concludes with subevent B.
PreRequisiteOf 'In order for A to happen, B needs to happen; B is a dependency of A.
SubeventOf 'A and B are events, and B happens as a subevent of A.
'Place
LocationOf 'A is a typical location for B, or A is the inherent location of B. Some instances of this would be considered meronyms in WordNet.
End Enum
Public Enum CorrelationResult
Positive = 1
PositiveHigh = 0.9
PositiveLow = 0.5
None = 0
NegativeLow = -0.5
NegativeHigh = -0.9
Negative = -1
End Enum
''' <summary>
''' Neural network Layer types
''' </summary>
''' <remarks></remarks>
Public Enum LayerType
Input
Hidden
Output
End Enum
''' <summary>
'''can '– ability, permission, possibility, request
'''could '– ability, permission, possibility, request, suggestion
'''may '– permission, probability, request
'''might '– possibility, probability, suggestion
'''must '– deduction, necessity, obligation, prohibition
'''shall '– decision, future, offer, question, suggestion
'''should '– advice, necessity, prediction, recommendation
'''will '– decision, future, intention, offer, prediction, promise, suggestion
'''would '– conditional, habit, invitation, permission, preference, request, question, suggestion
''' </summary>
''' <remarks></remarks>
Public Enum ModalMeanings
Ability
Request
Permission
Possibility
Obligation
Prohibition
Lack_Of_necessity
Advice
probability
Conditional
Invitation
Suggestion
deduction
Question
necsessity
prediction
offer
promise
decision
Prefference
intention
Instruction
End Enum
Public Enum ModalType
can '– ability, permission, possibility, request
could '– ability, permission, possibility, request, suggestion
may '– permission, probability, request
might '– possibility, probability, suggestion
must '– deduction, necessity, obligation, prohibition
shall '– decision, future, offer, question, suggestion
should '– advice, necessity, prediction, recommendation
will '– decision, future, intention, offer, prediction, promise, suggestion
would '– conditional, habit, invitation, permission, preference, request, question, suggestion
Unknown
End Enum
''' <summary>
''' These are the different object types available these object types are the highest level
''' objects of which most things sub objects or combined types
''' </summary>
''' <remarks></remarks>
Public Enum ObjectType
_Location
_Event
_Thing
_Animal
_Plant
_Person
End Enum
''' <summary>
''' Used to indicate how the data within should be assessed
''' </summary>
Public Enum ResponseType
''' <summary>
''' An Object was Detected ; Perhaps nyms were missing;
''' A question maybe prepared to be returned to the user to seek knowledge about the subject within.
''' It maybe the data within is just to be used as pointers?, So that the Query that can be sent to the user be direct or random
''' </summary>
SeekKnowledge
''' <summary>
''' User has asked a Question
''' </summary>
UserQuestion
''' <summary>
''' User has made a statment
''' </summary>
UserStatement
''' <summary>
''' Input was undetermined or Null
''' </summary>
Null
End Enum
''' <summary>
''' Category of sentence
''' </summary>
Public Enum SentenceCatagory
SimpleSentence
CompoundSentence
ComplexSentence
End Enum
''' <summary>
''' Used to denote tense
''' </summary>
''' <remarks></remarks>
Public Enum tense
Past = 0
Present = 1
Future = 2
Unknown = 3
End Enum
''' <summary>
''' These are the options of transfer functions available to the network
''' This is used to select which function to be used:
''' The derivative function can also be selected using this as a marker
''' </summary>
Public Enum TransferFunctionType
none
sigmoid
HyperbolTangent
BinaryThreshold
RectifiedLinear
Logistic
StochasticBinary
Gaussian
Signum
End Enum
''' <summary>
''' Used to hold Answers to Questions posed ;
''' There may be many answers a random answer can be returned
''' </summary>
Public Structure Answer
#Region "Fields"
''' <summary>
''' Placeholder for current Question
''' </summary>
Public CurrentQuestion As AssociatedQuestion
''' <summary>
''' A list of known knowledge for Question(Nym Specific or All Answers)
''' </summary>
Public HeldAnswers As List(Of Cept)
''' <summary>
''' Current object
''' </summary>
Public ObjectStr As String
#End Region
#Region "Methods"
''' <summary>
''' Returns Random Answer from
''' </summary>
''' <returns></returns>
Public Function GetRandomAnswer() As String
Dim rnd = New Random()
If HeldAnswers.Count > 0 Then
Return HeldAnswers(rnd.Next(0, HeldAnswers.Count)).DefinedStr
Else
Return Nothing
End If
End Function
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
#End Region
End Structure
''' <summary>
''' Used to hold Associated Questions;
''' these are used to detect questions as well as store questions related to learning information related to a particular nym
''' these may also be used to ask questions to gain information from the user.
''' Questions are in the format of "What IS A A#","IS A"
''' </summary>
Public Structure AssociatedQuestion
#Region "Fields"
Public NymStr As String
Public Question As String
#End Region
#Region "Methods"
''' <summary>
''' Checks if Nym is in set
''' </summary>
''' <param name="Questions"></param>
''' <param name="Nymstr"></param>
''' <returns></returns>
Public Shared Function CheckIfNymExists(ByRef Questions As List(Of AssociatedQuestion), ByRef Nymstr As String) As Boolean
CheckIfNymExists = False
For Each item In Questions
If item.NymStr = Nymstr Then
Return True
End If
Next
End Function
Public Shared Function GetQuestionByNym(ByRef Questions As List(Of AssociatedQuestion), ByRef NymStr As String) As List(Of AssociatedQuestion)
Dim lst As New List(Of AssociatedQuestion)
If Questions.Count > 0 Then
For Each item In Questions
If item.NymStr = NymStr Then
lst.Add(item)
Else
End If
Next
Return lst
Else
Return Nothing
End If
End Function
Public Shared Function UpdateObjectStr(ByRef Question As AssociatedQuestion, ByRef ObjectStr As String) As AssociatedQuestion
Question.Question.Replace("A#", ObjectStr)
Return Question
End Function
Public Function FilterQuestionsByNym(ByRef Questions As List(Of AssociatedQuestion), ByRef NymStr As String) As List(Of AssociatedQuestion)
Dim Lst As New List(Of AssociatedQuestion)
For Each item In Questions
If item.NymStr = NymStr Then
Lst.Add(item)
End If
Next
If Lst.Count > 0 Then
Return Lst
Else
Return Nothing
End If
End Function
Public Function GetRandomQuestion(ByRef Questions As List(Of AssociatedQuestion)) As AssociatedQuestion
Dim rnd = New Random()
If Questions.Count > 0 Then
Return Questions(rnd.Next(0, Questions.Count))
Else
Return Nothing
End If
End Function
Public Function InsertSubjectIntoQuestions(ByRef Questions As List(Of AssociatedQuestion), ByRef Subject As String) As List(Of AssociatedQuestion)
For Each item In Questions
item.Question.Replace("A#", Subject)
Next
Return Questions
End Function
Public Function InsertWildCardIntoQuestions(ByRef Questions As List(Of AssociatedQuestion)) As List(Of AssociatedQuestion)
For Each item In Questions
item.Question.Replace("A#", "*")
Next
Return Questions
End Function
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
Public Function UpdateObjectStr(ByRef ObjectStr As String) As AssociatedQuestion
Me.Question.Replace("A#", ObjectStr)
Return Me
End Function
#End Region
End Structure
''' <summary>
''' Used to retrieve or hold on to concept records
''' Object / Nym / Defined
''' </summary>
Public Structure Cept
#Region "Fields"
Public DefinedStr As String
''' <summary>
''' Used to hold the semantic pattern which detected it
''' </summary>
Public DetectedSearchPattern As SemanticPattern
''' <summary>
''' Predicate (item between Subjects)
''' </summary>
Public NymStr As String
Public ObjectStr As String
''' <summary>
''' Holds Original Sentences / detected sentence
''' </summary>
Public OriginalSentence As String
#End Region
#Region "Methods"
''' <summary>
''' Returns all Records Cepts from Given Table
''' </summary>
''' <param name="TableName">Table Name</param>
''' <param name="iConnectionStr">Custome Connection Str</param>
''' <returns></returns>
Public Shared Function GetDBCepts(ByRef iConnectionStr As String, ByRef TableName As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
Dim SQL As String = "SELECT * FROM " & TableName
Using conn = New System.Data.OleDb.OleDbConnection(iConnectionStr)
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
conn.Open()
Try
Dim dr = cmd.ExecuteReader()
While dr.Read()
Dim NewKnowledge As New Cept With {
.ObjectStr = dr("Object").ToString(),
.NymStr = dr("Nym").ToString(),
.DefinedStr = dr("Defined").ToString()
}
Lst.Add(NewKnowledge)
End While
Catch e As Exception
' Do some logging or something.
MessageBox.Show("There was an error accessing your data. GetDBCepts: " & e.ToString())
End Try
End Using
End Using
Return Lst
End Function
''' <summary>
''' Get all Cepts table by nym
''' </summary>
''' <param name="iConnectionStr"></param>
''' <param name="TableName"></param>
''' <param name="NymStr"></param>
''' <returns></returns>
Public Shared Function GetDBCeptsByNym(ByRef iConnectionStr As String, ByRef TableName As String, ByRef NymStr As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
Dim SQL As String = "SELECT * FROM " & TableName & " Where Nym='" & NymStr & "'"
Using conn = New System.Data.OleDb.OleDbConnection(iConnectionStr)
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
conn.Open()
Try
Dim dr = cmd.ExecuteReader()
While dr.Read()
Dim NewKnowledge As New Cept With {
.ObjectStr = dr("Object").ToString(),
.NymStr = dr("Nym").ToString(),
.DefinedStr = dr("Defined").ToString()
}
Lst.Add(NewKnowledge)
End While
Catch e As Exception
' Do some logging or something.
MessageBox.Show("There was an error accessing your data. GetDBCeptsByNym: " & e.ToString())
End Try
End Using
End Using
Return Lst
End Function
''' <summary>
''' Get Cepts from table by object
''' </summary>
''' <param name="iConnectionStr"></param>
''' <param name="TableName"></param>
''' <param name="ObjectStr"></param>
''' <returns></returns>
Public Shared Function GetDBCeptsByObject(ByRef iConnectionStr As String, ByRef TableName As String, ByRef ObjectStr As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
Dim SQL As String = "SELECT * FROM " & TableName & " Where Object='" & ObjectStr & "'"
Using conn = New System.Data.OleDb.OleDbConnection(iConnectionStr)
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
conn.Open()
Try
Dim dr = cmd.ExecuteReader()
While dr.Read()
Dim NewKnowledge As New Cept With {
.ObjectStr = dr("Object").ToString(),
.NymStr = dr("Nym").ToString(),
.DefinedStr = dr("Defined").ToString()
}
Lst.Add(NewKnowledge)
End While
Catch e As Exception
' Do some logging or something.
MessageBox.Show("There was an error accessing your data. GetDBCeptsByObject: " & e.ToString())
End Try
End Using
End Using
Return Lst
End Function
''' <summary>
''' Get Cepts from table by Query
''' </summary>
''' <param name="iConnectionStr"></param>
''' <param name="Query"></param>
''' <returns></returns>
Public Shared Function GetDBCeptsByQuery(ByRef iConnectionStr As String, ByRef Query As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
Dim SQL As String = Query
Using conn = New System.Data.OleDb.OleDbConnection(iConnectionStr)
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
conn.Open()
Try
Dim dr = cmd.ExecuteReader()
While dr.Read()
Dim NewKnowledge As New Cept
NewKnowledge.ObjectStr = dr("Object").ToString()
NewKnowledge.NymStr = dr("Nym").ToString()
NewKnowledge.DefinedStr = dr("Defined").ToString()
Lst.Add(NewKnowledge)
End While
Catch e As Exception
' Do some logging or something.
MessageBox.Show("There was an error accessing your data. GetDBCeptsByQuery: " & e.ToString())
End Try
End Using
End Using
Return Lst
End Function
''' <summary>
''' Adds new Nym into table
''' </summary>
''' <param name="NymStr">Must not Exist</param>
Public Function AddNym(ByRef iConnectionStr As String, ByRef Tablename As String, ByRef NymStr As String) As Boolean
AddNym = False
If NymStr IsNot Nothing Then
Dim SQL = "INSERT INTO " & Tablename & " Nym VALUES ('" & NymStr & "')"
Using conn = New System.Data.OleDb.OleDbConnection(iConnectionStr)
Using cmd = New System.Data.OleDb.OleDbCommand(SQL, conn)
conn.Open()
Try
cmd.ExecuteNonQuery()
AddNym = True
Catch ex As Exception
MessageBox.Show("There was an error accessing your data. AddNym: " & ex.ToString())
End Try
End Using
End Using
Else
End If
End Function
''' <summary>
''' Checks given list to see if nym exists in set
''' </summary>
''' <param name="Knowledge"></param>
''' <param name="NymStr"></param>
''' <returns></returns>
Public Function CheckIfNymExists(ByRef Knowledge As List(Of Cept), ByRef NymStr As String) As Boolean
Dim lst As New List(Of Cept)
For Each item In Knowledge
If item.NymStr = NymStr Then
lst.Add(item)
End If
Next
If lst.Count > 0 Then
Return True
Else
Return False
End If
End Function
Public Function FilterCepts(ByRef Cepts As List(Of Cept), ByRef ObjectStr As String, ByRef NymStr As String) As List(Of Cept)
Dim ObjLst As List(Of Cept) = FilterCeptsByNym(FilterCeptsByObject(Cepts, ObjectStr), NymStr)
If ObjLst.Count > 0 Then
Return ObjLst
Else
Return Nothing
End If
End Function
Public Function FilterCeptsByNym(ByRef Cepts As List(Of Cept), ByRef NymStr As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
For Each item In Cepts
If item.NymStr = NymStr Then
Lst.Add(item)
End If
Next
If Lst.Count > 0 Then
Return Lst
Else
Return Nothing
End If
End Function
Public Function FilterCeptsByObject(ByRef Cepts As List(Of Cept), ByRef ObjectStr As String) As List(Of Cept)
Dim Lst As New List(Of Cept)
For Each item In Cepts
If item.ObjectStr = ObjectStr Then
Lst.Add(item)
End If
Next
If Lst.Count > 0 Then
Return Lst
Else
Return Nothing
End If
End Function
''' <summary>
''' Return set from list by nym
''' This is used to segment cept Lists
''' </summary>
''' <param name="Knowledge"></param>
''' <param name="NymStr"></param>
''' <returns></returns>
Public Function GetByNym(ByRef Knowledge As List(Of Cept), ByRef NymStr As String) As List(Of Cept)
Dim lst As New List(Of Cept)
For Each item In Knowledge
If item.NymStr = NymStr Then
lst.Add(item)
End If
Next
Return lst
End Function
''' <summary>
''' Returns a random Cept from List
''' </summary>
''' <param name="Cepts"></param>
''' <returns></returns>
Public Function GetRandomCept(ByRef Cepts As List(Of Cept)) As Cept
Dim rnd = New Random()
If Cepts.Count > 0 Then
Return Cepts(rnd.Next(0, Cepts.Count))
Else
Return Nothing
End If
End Function
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
#End Region
End Structure
''' <summary>
''' Concept Structure Detected : With Learning Pattern which detected detected the concept
''' Type in the text
''' </summary>
Public Structure DiscoveredConcept
#Region "Fields"
''' <summary>
''' Detected Learning Pattern (Sentence as Predicate) Enables for Predicate is not Required
''' </summary>
Public DetectedPat As String
Public DetectedResponseType As ResponseType
''' <summary>
''' Used to hold the semantic pattern which detected it
''' </summary>
Public DetectedSearchPattern As SemanticPattern
''' <summary>
''' Nym
''' </summary>
Public NymStr As String
''' <summary>
''' USed to hold the original sentence state
''' </summary>
Public OriginalSentence As String
''' <summary>
''' Used to hold Predicate in sentence
''' </summary>
Public Predicate As String
''' <summary>
''' Subject A detected
''' </summary>
Public SubjectA As String
''' <summary>
''' Subject B detected
''' </summary>
Public SubjectB As String
#End Region
#Region "Properties"
''' <summary>
''' Type of response generated by Anaylasis
''' Unables for understanding of the results gained
''' </summary>
''' <returns></returns>
Public ReadOnly Property ResponseTypeStr As String
Get
Select Case DetectedResponseType
Case ResponseType.SeekKnowledge
Return "SeekKnowledge"
Case ResponseType.UserQuestion
Return "UserQuestion"
Case ResponseType.UserStatement
Return "UserStatement"
Case ResponseType.Null
Return "Null"
End Select
Return Nothing
End Get
End Property
#End Region
#Region "Methods"
''' <summary>
''' Checks given list to see if nym exists in set
''' </summary>
''' <param name="Knowledge"></param>
''' <param name="NymStr"></param>
''' <returns></returns>
Public Function CheckIfNymExists(ByRef Knowledge As List(Of DiscoveredConcept), ByRef NymStr As String) As Boolean
Dim lst As New List(Of DiscoveredConcept)
For Each item In Knowledge
If item.NymStr = NymStr Then
lst.Add(item)
End If
Next
If lst.Count > 0 Then
Return True
Else
Return False
End If
End Function
''' <summary>
''' Filters list by Object and Nym
''' </summary>
''' <param name="Cepts">List to be searched</param>
''' <param name="ObjectStr">Object </param>
''' <param name="NymStr">Nym</param>
''' <returns></returns>
Public Function FilterCepts(ByRef Cepts As List(Of DiscoveredConcept), ByRef ObjectStr As String, ByRef NymStr As String) As List(Of DiscoveredConcept)
Dim ObjLst As List(Of DiscoveredConcept) = FilterCeptsByNym(FilterCeptsByObject(Cepts, ObjectStr), NymStr)
If ObjLst.Count > 0 Then
Return ObjLst
Else
Return Nothing
End If
End Function
''' <summary>
''' Filter List by Nym
''' </summary>
''' <param name="Cepts">List to be filtered</param>
''' <param name="NymStr">Nym</param>
''' <returns></returns>
Public Function FilterCeptsByNym(ByRef Cepts As List(Of DiscoveredConcept), ByRef NymStr As String) As List(Of DiscoveredConcept)
Dim Lst As New List(Of DiscoveredConcept)
For Each item In Cepts
If item.NymStr = NymStr Then
Lst.Add(item)
End If
Next
If Lst.Count > 0 Then
Return Lst
Else
Return Nothing
End If
End Function
''' <summary>
''' Filter list by object
''' </summary>
''' <param name="Cepts">List to be searched</param>
''' <param name="ObjectStr">object</param>
''' <returns></returns>
Public Function FilterCeptsByObject(ByRef Cepts As List(Of DiscoveredConcept), ByRef ObjectStr As String) As List(Of DiscoveredConcept)
Dim Lst As New List(Of DiscoveredConcept)
For Each item In Cepts
If item.SubjectA = ObjectStr Then
Lst.Add(item)
End If
Next
If Lst.Count > 0 Then
Return Lst
Else
Return Nothing
End If
End Function
''' <summary>
''' Return set from list by nym
''' This is used to segment cept Lists
''' </summary>
''' <param name="Knowledge"></param>
''' <param name="NymStr"></param>
''' <returns></returns>
Public Function GetByNym(ByRef Knowledge As List(Of DiscoveredConcept), ByRef NymStr As String) As List(Of DiscoveredConcept)
Dim lst As New List(Of DiscoveredConcept)
For Each item In Knowledge
If item.NymStr = NymStr Then
lst.Add(item)
End If
Next
Return lst
End Function
''' <summary>
''' Returns a random Cept from List
''' </summary>
''' <param name="Cepts"></param>
''' <returns></returns>
Public Function GetRandomCept(ByRef Cepts As List(Of DiscoveredConcept)) As DiscoveredConcept
Dim rnd = New Random()
If Cepts.Count > 0 Then
Return Cepts(rnd.Next(0, Cepts.Count))
Else
Return Nothing
End If
End Function
Public Function ToCept() As Cept
Dim NewCept As New Cept With {
.DefinedStr = Me.SubjectB,
.NymStr = Me.NymStr,
.ObjectStr = Me.SubjectA
}
Return NewCept
End Function
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
#End Region
End Structure
''' <summary>
''' Extract Entities from text using Named Entity Recognition (NER).
''' NER labels sequences of words in a text which are the names of things,
''' such as person and company names.
''' By creating lists On specific topics such As a list Of names / Locations , Organizations etc.
''' These can be used To identify these words In the text, As the entity type.
''' The entity's extracted can be extracted or the sentence containing the entity.
''' this structure is used to hold extracted Entity's and their associated sentences, and keywords
''' </summary>
Public Structure DiscoveredEntity
#Region "Fields"
''' <summary>
''' Discovered Entity
''' </summary>
Dim DiscoveredKeyWord As String
''' <summary>
''' Associated Sentence
''' </summary>
Dim DiscoveredSentence As String
''' <summary>
''' Theme of Entitys in List / name of associated list
''' </summary>
Public EntityList As String
#End Region
#Region "Methods"
''' <summary>
''' Outputs Structure to Jason(JavaScriptSerializer)
''' </summary>
''' <returns></returns>
Public Function ToJson() As String
Dim Converter As New JavaScriptSerializer
Return Converter.Serialize(Me)
End Function
#End Region
End Structure
''' <summary>
''' List of Syllogisms held in database
''' </summary>
Public Structure MasterList
Public ConnectionStr As String
''' <summary>
''' Gets all of the premises stored in the table
''' </summary>
Private Shared ReadOnly mMasterList As List(Of Syllogism) = GetDBPremises()
''' <summary>
''' List of The Stored Premises
''' </summary>
''' <returns></returns>
Public Shared ReadOnly Property MasterList As List(Of Syllogism)
Get
Return mMasterList
End Get
End Property
''' <summary>
''' Checks the syllogism presented to see if the Consequent and Antecedent Match
''' Although copulas may not match
''' </summary>
''' <param name="Andecedant"></param>
''' <param name="Consequent"></param>
''' <param name="Premises"></param>
''' <returns></returns>
Public Shared Function CheckSyllogismExists(ByRef Andecedant As String, ByRef Consequent As String,
ByVal Premises As List(Of Syllogism)) As Boolean
CheckSyllogismExists = False
For Each Premise As Syllogism In Premises
If Premise.Consequent = Consequent And
Premise.Antecedant = Andecedant = True Then
Return True
Else
CheckSyllogismExists = False
End If
Next
Return CheckSyllogismExists
End Function
Public Shared Function CheckSyllogismExists(ByRef Premise As Syllogism,
ByVal Premises As List(Of Syllogism)) As Boolean
CheckSyllogismExists = False
For Each item As Syllogism In Premises
If Compare(item, Premise) = True Then
CheckSyllogismExists = True
End If
Next
Return CheckSyllogismExists
End Function
''' <summary>
''' Checks if term exists in Premises
''' </summary>
''' <param name="term"></param>
''' <param name="searchlist"></param>
''' <returns></returns>
Public Shared Function CheckTermExists(ByRef term As String, ByVal searchlist As List(Of Syllogism)) As Boolean
CheckTermExists = False
If ContainsAndecedant(term, searchlist) = True Or
ContainsConsequent(term, searchlist) = True Then
Return True
End If
End Function
''' <summary>
''' Searches Premise list of syllogisms to see if antecedent is contained within as an antecedent
''' </summary>
''' <param name="SearchAndecedant"></param>
''' <param name="Relations"></param>