public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { Sentence substFirst = (Sentence)sentence.getFirst().accept(this, arg); Sentence substSecond = (Sentence)sentence.getSecond() .accept(this, arg); return new ConnectedSentence(sentence.getConnector(), substFirst, substSecond); }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { sentence.getFirst().accept(this, arg); sentence.getSecond().accept(this, arg); return arg; }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { ArgData ad = (ArgData)arg; Sentence first = sentence.getFirst(); Sentence second = sentence.getSecond(); first.accept(this, arg); if (Connectors.isAND(sentence.getConnector())) { ad.clauses.Add(new Clause()); } second.accept(this, arg); return sentence; }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { // Distribute V over ^: // This will cause flattening out of nested ^s and Vs Sentence alpha = (Sentence)sentence.getFirst().accept(this, arg); Sentence beta = (Sentence)sentence.getSecond().accept(this, arg); // (alpha V (beta ^ gamma)) equivalent to // ((alpha V beta) ^ (alpha V gamma)) if (Connectors.isOR(sentence.getConnector()) && beta is ConnectedSentence) { ConnectedSentence betaAndGamma = (ConnectedSentence)beta; if (Connectors.isAND(betaAndGamma.getConnector())) { beta = betaAndGamma.getFirst(); Sentence gamma = betaAndGamma.getSecond(); return new ConnectedSentence(Connectors.AND, (Sentence)(new ConnectedSentence(Connectors.OR, alpha, beta)).accept(this, arg), (Sentence)(new ConnectedSentence(Connectors.OR, alpha, gamma)).accept(this, arg)); } } // ((alpha ^ gamma) V beta) equivalent to // ((alpha V beta) ^ (gamma V beta)) if (Connectors.isOR(sentence.getConnector()) && alpha is ConnectedSentence) { ConnectedSentence alphaAndGamma = (ConnectedSentence)alpha; if (Connectors.isAND(alphaAndGamma.getConnector())) { alpha = alphaAndGamma.getFirst(); Sentence gamma = alphaAndGamma.getSecond(); return new ConnectedSentence(Connectors.AND, (Sentence)(new ConnectedSentence(Connectors.OR, alpha, beta)).accept(this, arg), (Sentence)(new ConnectedSentence(Connectors.OR, gamma, beta)).accept(this, arg)); } } return new ConnectedSentence(sentence.getConnector(), alpha, beta); }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { return new ConnectedSentence(sentence.getConnector(), (Sentence)sentence.getFirst().accept(this, arg), (Sentence)sentence.getSecond().accept(this, arg)); }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { Sentence alpha = (Sentence)sentence.getFirst().accept(this, arg); Sentence beta = (Sentence)sentence.getSecond().accept(this, arg); // Eliminate <=>, bi-conditional elimination, // replace (alpha <=> beta) with (~alpha V beta) ^ (alpha V ~beta). if (Connectors.isBICOND(sentence.getConnector())) { Sentence first = new ConnectedSentence(Connectors.OR, new NotSentence(alpha), beta); Sentence second = new ConnectedSentence(Connectors.OR, alpha, new NotSentence(beta)); return new ConnectedSentence(Connectors.AND, first, second); } // Eliminate =>, implication elimination, // replacing (alpha => beta) with (~alpha V beta) if (Connectors.isIMPLIES(sentence.getConnector())) { return new ConnectedSentence(Connectors.OR, new NotSentence(alpha), beta); } return new ConnectedSentence(sentence.getConnector(), alpha, beta); }
private Sentence parseParanthizedSentence() { match("("); Sentence sen = parseSentence(); while (binaryConnector(lookAhead(1))) { String connector = lookAhead(1).getText(); consume(); Sentence other = parseSentence(); sen = new ConnectedSentence(connector, sen, other); } match(")"); return sen; /* new ParanthizedSentence */ }
public AnswerHandler(FOLKnowledgeBase kb, Sentence aQuery, long maxQueryTime, FOLModelElimination folModelElimination) { finishTime = System.DateTime.UtcNow.Ticks + maxQueryTime; Sentence refutationQuery = new NotSentence(aQuery); // Want to use an answer literal to pull // query variables where necessary Literal answerLiteral = kb.createAnswerLiteral(refutationQuery); answerLiteralVariables = kb.collectAllVariables(answerLiteral .getAtomicSentence()); // Create the Set of Support based on the Query. if (answerLiteralVariables.Count > 0) { Sentence refutationQueryWithAnswer = new ConnectedSentence( Connectors.OR, refutationQuery, (Sentence)answerLiteral .getAtomicSentence().copy()); sos = folModelElimination.createChainsFromClauses(kb .convertToClauses(refutationQueryWithAnswer)); answerChain.addLiteral(answerLiteral); } else { sos = folModelElimination.createChainsFromClauses(kb .convertToClauses(refutationQuery)); } foreach (Chain s in sos) { s.setProofStep(new ProofStepGoal(s)); } }
// // START-InferenceProcedure public InferenceResult ask(FOLKnowledgeBase KB, Sentence alpha) { List<Clause> sos = new List<Clause>(); List<Clause> usable = new List<Clause>(); // Usable set will be the set of clauses in the KB, // are assuming this is satisfiable as using the // Set of Support strategy. foreach (Clause c in KB.getAllClauses()) { Clause c2 = KB.standardizeApart(c); c2.setStandardizedApartCheckNotRequired(); usable.AddRange(c2.getFactors()); } // Ensure reflexivity axiom is added to usable if using paramodulation. if (isUseParamodulation()) { // Reflexivity Axiom: x = x TermEquality reflexivityAxiom = new TermEquality(new Variable("x"), new Variable("x")); Clause reflexivityClause = new Clause(); reflexivityClause.addLiteral(new Literal(reflexivityAxiom)); reflexivityClause = KB.standardizeApart(reflexivityClause); reflexivityClause.setStandardizedApartCheckNotRequired(); usable.Add(reflexivityClause); } Sentence notAlpha = new NotSentence(alpha); // Want to use an answer literal to pull // query variables where necessary Literal answerLiteral = KB.createAnswerLiteral(notAlpha); List<Variable> answerLiteralVariables = KB .collectAllVariables(answerLiteral.getAtomicSentence()); Clause answerClause = new Clause(); if (answerLiteralVariables.Count > 0) { Sentence notAlphaWithAnswer = new ConnectedSentence(Connectors.OR, notAlpha, answerLiteral.getAtomicSentence()); foreach (Clause c in KB.convertToClauses(notAlphaWithAnswer)) { Clause c2 = KB.standardizeApart(c); c2.setProofStep(new ProofStepGoal(c2)); c2.setStandardizedApartCheckNotRequired(); sos.AddRange(c2.getFactors()); } answerClause.addLiteral(answerLiteral); } else { foreach (Clause c in KB.convertToClauses(notAlpha)) { Clause c2 = KB.standardizeApart(c); c2.setProofStep(new ProofStepGoal(c2)); c2.setStandardizedApartCheckNotRequired(); sos.AddRange(c2.getFactors()); } } // Ensure all subsumed clauses are removed foreach (Clause c in SubsumptionElimination.findSubsumedClauses(usable)) { usable.Remove(c); } foreach (Clause c in SubsumptionElimination.findSubsumedClauses(sos)) { sos.Remove(c); } OTTERAnswerHandler ansHandler = new OTTERAnswerHandler(answerLiteral, answerLiteralVariables, answerClause, maxQueryTime); IndexedClauses idxdClauses = new IndexedClauses( getLightestClauseHeuristic(), sos, usable); return otter(ansHandler, idxdClauses, sos, usable); }
public Object visitConnectedSentence(ConnectedSentence sentence, Object arg) { throw new NotImplementedException( "visitConnectedSentence() should not be called."); }
public void testQuantifiedSentenceWithPathologicalParanthising() { Sentence qs = parser .parse("(( (EXISTS x,y (King(x) AND (BrotherOf(x) = y)) ) ))"); List<Variable> vars = new List<Variable>(); vars.Add(new Variable("x")); vars.Add(new Variable("y")); ConnectedSentence cse = new ConnectedSentence("AND", getKingPredicate(new Variable("x")), new TermEquality( getBrotherOfFunction(new Variable("x")), new Variable( "y"))); Assert.AreEqual(qs.ToString(), new QuantifiedSentence("EXISTS", vars, cse).ToString()); }
// // START-InferenceProcedure public InferenceResult ask(FOLKnowledgeBase KB, Sentence alpha) { // clauses <- the set of clauses in CNF representation of KB ^ ~alpha List<Clause> clauses = new List<Clause>(); foreach (Clause c in KB.getAllClauses()) { Clause c2 = KB.standardizeApart(c); c2.setStandardizedApartCheckNotRequired(); clauses.AddRange(c2.getFactors()); } Sentence notAlpha = new NotSentence(alpha); // Want to use an answer literal to pull // query variables where necessary Literal answerLiteral = KB.createAnswerLiteral(notAlpha); List<Variable> answerLiteralVariables = KB .collectAllVariables(answerLiteral.getAtomicSentence()); Clause answerClause = new Clause(); if (answerLiteralVariables.Count > 0) { Sentence notAlphaWithAnswer = new ConnectedSentence(Connectors.OR, notAlpha, answerLiteral.getAtomicSentence()); foreach (Clause c in KB.convertToClauses(notAlphaWithAnswer)) { Clause c2 = KB.standardizeApart(c); c2.setProofStep(new ProofStepGoal(c2)); c2.setStandardizedApartCheckNotRequired(); clauses.AddRange(c2.getFactors()); } answerClause.addLiteral(answerLiteral); } else { foreach (Clause c in KB.convertToClauses(notAlpha)) { Clause c2 = KB.standardizeApart(c); c2.setProofStep(new ProofStepGoal(c2)); c2.setStandardizedApartCheckNotRequired(); clauses.AddRange(c2.getFactors()); } } TFMAnswerHandler ansHandler = new TFMAnswerHandler(answerLiteral, answerLiteralVariables, answerClause, maxQueryTime); // new <- {} List<Clause> newClauses = new List<Clause>(); List<Clause> toAdd = new List<Clause>(); // loop do int noOfPrevClauses = clauses.Count; do { if (null != tracer) { tracer.stepStartWhile(clauses, clauses.Count, newClauses .Count); } newClauses.Clear(); // for each Ci, Cj in clauses do Clause[] clausesA = new Clause[clauses.Count]; clausesA = clauses.ToArray(); // Basically, using the simple T)wo F)inger M)ethod here. for (int i = 0; i < clausesA.Length; i++) { Clause cI = clausesA[i]; if (null != tracer) { tracer.stepOuterFor(cI); } for (int j = i; j < clausesA.Length; j++) { Clause cJ = clausesA[j]; if (null != tracer) { tracer.stepInnerFor(cI, cJ); } // resolvent <- FOL-RESOLVE(Ci, Cj) List<Clause> resolvents = cI.binaryResolvents(cJ); if (resolvents.Count > 0) { toAdd.Clear(); // new <- new <UNION> resolvent foreach (Clause rc in resolvents) { toAdd.AddRange(rc.getFactors()); } if (null != tracer) { tracer.stepResolved(cI, cJ, toAdd); } ansHandler.checkForPossibleAnswers(toAdd); if (ansHandler.isComplete()) { break; } newClauses.AddRange(toAdd); } if (ansHandler.isComplete()) { break; } } if (ansHandler.isComplete()) { break; } } noOfPrevClauses = clauses.Count; // clauses <- clauses <UNION> new clauses.AddRange(newClauses); if (ansHandler.isComplete()) { break; } // if new is a <SUBSET> of clauses then finished // searching for an answer // (i.e. when they were added the # clauses // did not increase). } while (noOfPrevClauses < clauses.Count); if (null != tracer) { tracer.stepFinished(clauses, ansHandler); } return ansHandler; }