var o:Ontology = new Ontology(); Sort.clear(); var xmlhttp:XMLHttpRequest = new XMLHttpRequest(); xmlhttp.overrideMimeType("text/xml"); xmlhttp.open("GET", "data/shrdluontology.xml", false); xmlhttp.send(); o.loadSortsFromXML(xmlhttp.responseXML.documentElement); xmlhttp = new XMLHttpRequest(); xmlhttp.overrideMimeType("text/xml"); xmlhttp.open("GET", "data/nlpatternrules.xml", false); xmlhttp.send(); var parser:NLParser = NLParser.fromXML(xmlhttp.responseXML.documentElement, o); var posParser:POSParser = parser.posParser; var testAI:RuleBasedAI = new RuleBasedAI(o, parser, 12, 0, DEFAULT_QUESTION_PATIENCE_TIMER); var term_unification_l:[string,string,boolean][] = [ ["actionverb([character])", "actionverb([character])", true], ["actionverb([character])", "actionverb([character],[any])", false], ["actionverb([character])", "action.talk([character])", true], ["performative([character])", "actionverb([character])", false], ["actionverb('1'[number])", "actionverb('2'[number])", false], ["actionverb('1'[number])", "actionverb('1'[actionverb])", false], ["actionverb('1'[number])", "actionverb([number])", true], ["actionverb(action.talk([number]))", "actionverb(action.talk([number]))", true], ["actionverb(action.talk([number]))", "actionverb(action.take([number]))", false], ["actionverb([number])", "actionverb('2'[number])", true], ["actionverb([number])", "actionverb([actionverb])", false], ["actionverb(X:[number],X)", "actionverb('1'[number],'1'[number])", true], ["actionverb(X:[number],X)", "actionverb('1'[number],'2'[number])", false], /*["actionverb(X:[any],any(X))", "actionverb(any(Y:[any]),Y)", false],*/ // this one is commented out, since I've deactivated the occurs check ["actionverb([character],[any])", "action.talk('david'[character],perf.greet(Z:[any]))", true], ["action.talk(T:[number], X:[character], perf.greet('self'[character]))", "action.talk('615'[number], 'david'[character], 'hello':[symbol])", false], ["action.talk(T:[number], X:[character], perf.greet('self'[character]))", "action.talk('615'[number], 'david'[character], perf.greet(X:[character]))", true], ["action.talk(T:[number], X:[character], perf.greet('self'[character]))", "action.talk('615'[number], 'David'[character], perf.greet('chair'[object]))", false], ]; /* var sentence_text_l:string[] = ["~action.talk(T:[number], X:[character], perf.greet(Y:'self'[character])) ; intention(action.talk(Y, perf.greet(X)))"]; for(let str of sentence_text_l) { var s:Sentence = Sentence.fromString(str, o); console.log("parsed sentence:\n" + s); } */ /* console.log("-------------------------"); var term1_text:string = "#and(V0:#and(V1:#not(V2:=(V:[any], V4:'etaoin'[#id])), V5:#and(V6:#not(V7:=(V, V8:'player'[#id])), V9:character(V))), V10:space.at(V, V11:'location-aurora-station'[#id]))"; var parsed_term1:Term = Term.fromString(term1_text, o); var sentences_from_term1:Sentence[] = Term.termToSentences(parsed_term1, o); console.log("Term: " + parsed_term1); console.log("Sentences: " + sentences_from_term1); if (sentences_from_term1.length != 4) { console.error("parse is not what was expected when turning term to sentence for term: " + parsed_term1); } console.log("-------------------------"); */ // inference test, it checks whether the query_str contradicts KB_str function resolutionTest(KB_str:string[], query_str_l:string[], expectedResult:boolean, o:Ontology) { resolutionTest2(KB_str, [], query_str_l, expectedResult, o); } // inference test, it checks whether the query_str contradicts KB_str function resolutionTest2(KB_str:string[], AS_str:string[], query_str_l:string[], expectedResult:boolean, o:Ontology) { // DEBUG_resolution = true; let KB:SentenceContainer = new SentenceContainer(); for(let str of KB_str) { let s:Sentence = Sentence.fromString(str, o); // console.log("parsed KB sentence: " + s.toString()); KB.addSentence(s, "background", 1, 0); } let additionalSentences:Sentence[] = []; for(let str of AS_str) { let s:Sentence = Sentence.fromString(str, o); additionalSentences.push(s); } let query:Sentence[] = []; for(let query_str of query_str_l) { query.push(Sentence.fromString(query_str, o)); } // console.log("parsed query sentence: " + query.toString()); let r:InterruptibleResolution = new InterruptibleResolution(KB, additionalSentences, query, true, true, testAI); // let steps:number = 0; while(!r.step()) { // steps++; // if (steps>=5) break; } let result:boolean = r.endResults.length > 0; if (result != expectedResult) { console.error("failed resolutionTest, query: " + query_str_l); } else { console.log("resolutionTest ok! ("+r.total_resolutions+" inference steps)"); } /* if (r.endResults.length > 0) { let baseSentences:Sentence[] = r.endResults[0].getBaseSentences(query); console.log("Base sentences ("+baseSentences.length+"):"); for(let s of baseSentences) { console.log(" - " + s.toString()); } } */ } function resolutionQueryTest(KB_str:string[], query_str_l:string[], numberOfExpectedResults:number, o:Ontology) { resolutionQueryTest2(KB_str, [], query_str_l, numberOfExpectedResults, o); } function resolutionQueryTest2(KB_str:string[], AS_str:string[], query_str_l:string[], numberOfExpectedResults:number, o:Ontology) { resolutionQueryTest2ForAll(KB_str, AS_str, query_str_l, [], numberOfExpectedResults, o); } function resolutionQueryTest2ForAll(KB_str:string[], AS_str:string[], query_str_l:string[], forall_str_l:string[], numberOfExpectedResults:number, o:Ontology) { //DEBUG_resolution = true; let KB:SentenceContainer = new SentenceContainer(); for(let str of KB_str) { let s:Sentence = Sentence.fromString(str, o); // console.log("parsed KB sentence: " + s.toString()); KB.addSentence(s, "background", 1, 0); } let additionalSentences:Sentence[] = []; for(let str of AS_str) { let s:Sentence = Sentence.fromString(str, o); additionalSentences.push(s); } let query:Sentence[] = []; let queryVariables:string[] = []; for(let query_str of query_str_l) { let s:Sentence = Sentence.fromString(query_str, o); query.push(s); for(let v of s.getAllVariables()) { if (queryVariables.indexOf(v.name) == -1) queryVariables.push(v.name); } } // console.log("parsed query sentence: " + query.toString()); let forAlls:[VariableTermAttribute, Term][] = []; for(let forAll_str of forall_str_l) { let forAll_term:Term = Term.fromString(forAll_str, o); forAlls.push([(forAll_term.attributes[0]), ((forAll_term.attributes[1])).term]); let idx:number = queryVariables.indexOf(((forAll_term.attributes[0])).name); if (idx != -1) queryVariables.splice(idx,1); } // for(let v of queryVariables) { // console.log("query variable: " + v); // } let r:InterruptibleResolution = new InterruptibleResolution(KB, additionalSentences, query, true, true, testAI); while(!r.stepAccumulatingResults(true)); for(let i:number = 0;i