Code Samples

HarryHome Flow GUI Structures Functions Procedures Status Code UserGuide AdminGuide Download Bugs



 

Function Converse(Message As String)
    
    Protocol = "director"
        If Message = "" Then Message = "hello. what time is it?"
getstatement:
    If linkrec.Count("tblQuestions") > 0 Then
        Protocol = "investigator"
    Else
            InputRec = Routing.Acquire("", Message) 'acquire statement
            Message = ""
            If InputRec = "" Then 'check for end of session
                temp = Routing.Express("Thank you.")
                Exit Function
            End If
        Paragraph = InputRec
NextSentence:
        If Len(InputRec) > 0 Then
            Sentence = ExtractSentence(Paragraph)
            PriorSentence = Sentence
            Sentence = ExtractClauses(Sentence)
            Sentence = Routing.Convert(Sentence, "tblEnglish") 'transform input statement into command statement format
            Sentence = Routing.Intent(Sentence, "tblEnglish") 'determine intent
            temp = Routing.Interpret(Sentence, "tblEnglish") 'interpret statement
            If Protocol <> "director" Then Intention = Protocol
             Protocol = Routing.Director(Intention, Sentence) 'Direct process
            temp = Routing.Consolidate(Sentence, "tblinterpretation", "tblKnowledge") 'for a term
            temp = Routing.CreateSentences("tblinterpretation", "sentence results") 'create sentences from file of standard format
            temp = Routing.SpeakFile("sentence results")
            If Len(Paragraph) > 0 Then GoTo NextSentence
            GoTo getstatement 'get next statement
        Else
            GoTo getstatement 'get next statement
        End If

    End If
    GoTo getstatement
End Function

Function ExtractSentence(Paragraph As String)
'extract first sentence and remove sentence from paragraph
Dim endpos As Integer

endpos = Len(Paragraph)
nextone:
If InStr(Paragraph, ".") < Len(Paragraph) Then
    If InStr(Paragraph, ". ") Then
        ExtractSentence = Left(Paragraph, InStr(Paragraph, ". "))
        Paragraph = Right(Paragraph, Len(Paragraph) - (InStr(Paragraph, ". ") + 1))
    Else
        ExtractSentence = Paragraph
        Paragraph = ""
    End If
Else
    ExtractSentence = Paragraph
    Paragraph = ""
End If
End Function

Function ExtractClauses(Sentence As String)
'parse all Clauses using paterns from language table

PriorStatement = ""
NewStatement = Sentence
If olinkrec.Count("tblConvClauses") > 0 Then
    temp = olinkrec.GetFields("tblConvClauses", obj1clas, obj1, Relation, obj2clas, obj2, 1)
    NewStatement = obj2
    temp = olinkrec.DeleteRecord("tblConvClauses", "x", "x", "x", "x", obj2)
End If
NewStatement = ResolveSynonym(NewStatement)
Set linkrec = db.OpenRecordset("tblEnglish")
'replace statement with object2 of matching object1 field in tbllanguage with relation transformin
With linkrec
    .MoveFirst
    Do Until .EOF
        If .Fields("Object1 Class") = "sentence" And .Fields("Relation") = "parses to" And .Fields("Object2 Class") = "syllogism" Then
            If .Fields("Object1") Like "*|*" Then
                'Parse into comparefield and replacefield
                FindLoc = InStr(.Fields("Object1"), "|")
                ReplaceField = Left(.Fields("Object1"), FindLoc - 1)
                CompareField = Mid(.Fields("Object1"), FindLoc + 1, Len(.Fields("Object1")) - FindLoc)
            Else
                ReplaceField = .Fields("Object1")
                CompareField = ReplaceField
            End If
            If NewStatement Like "*" & CompareField & "*" Then
                NewStatement = clsString.fReplace(NewStatement, ReplaceField, .Fields("Object2"))
                ArrayPtr = clsString.fParse(",", NewStatement)
                For ArrayCnt = 0 To 9
                    If ArrayPtr(ArrayCnt) = "" Then Exit For
                    obj1array(ArrayCnt) = ArrayPtr(ArrayCnt)
                    temp = olinkrec.Add("tblclauses", "x", "x", "x", "x", obj1array(ArrayCnt))
                Next ArrayCnt
                NewStatement = obj1array(ArrayCnt - 1)
                temp = olinkrec.DeleteRecord("tblclauses", "x", "x", "x", "x", obj1array(ArrayCnt - 1))
                Exit Do
            End If
        End If
        If .Fields("Object1 Class") = "sentence" And .Fields("Relation") = "parses to" And .Fields("Object2 Class") = "clauses" Then
            If NewStatement Like "*" & .Fields("Object1") & " *" Then
                ArrayPtr = clsString.fParse(.Fields("Object1") & " ", NewStatement)
                For ArrayCnt = 0 To 9
                    If ArrayPtr(ArrayCnt) = "" Then Exit For
                    obj1array(ArrayCnt) = ArrayPtr(ArrayCnt)
                    temp = olinkrec.Add("tblclauses", "x", "x", "x", "x", obj1array(ArrayCnt))
                Next ArrayCnt
                NewStatement = obj1array(0)
                NewStatement = NewStatement & "."
                temp = olinkrec.DeleteRecord("tblclauses", "x", "x", "x", "x", obj1array(0))
                Exit Do
            End If
        End If
        .MoveNext
    Loop
    .Close
End With
ExtractClauses = NewStatement
End Function