public bool plfcEntails(KnowledgeBase kb, Symbol q) { List <HornClause> hornClauses = asHornClauses(kb.getSentences()); while (agenda.Count != 0) { Symbol p = agenda.Pop(); while (!inferred(p)) { _inferred.Add(p, true); for (int i = 0; i < hornClauses.Count; i++) { HornClause hornClause = hornClauses[i]; if (hornClause.premisesContainsSymbol(p)) { decrementCount(hornClause); if (countisZero(hornClause)) { if (hornClause.head().Equals(q)) { return(true); } else { agenda.Push(hornClause.head()); } } } } } } return(false); }
public override bool Equals(Object o) { if (this == o) { return(true); } if ((o == null) || (this.GetType() != o.GetType())) { return(false); } HornClause ohc = (HornClause)o; if (premiseSymbols.Count != ohc.premiseSymbols.Count) { return(false); } //bool result = true; foreach (Symbol s in premiseSymbols) { if (!ohc.premiseSymbols.Contains(s)) { return(false); } } return(true); }
public override bool Equals(Object o) { if (this == o) { return(true); } if ((o == null) || !(o is PLFCEntails)) { return(false); } HornClause ohc = (HornClause)o; if (premiseSymbols.Count != ohc.premiseSymbols.Count) { return(false); } foreach (Symbol s in premiseSymbols) { if (!ohc.premiseSymbols.Contains(s)) { return(false); } } return(true); }
private List<HornClause> asHornClauses(List<Sentence> sentences) { List<HornClause> hornClauses = new List<HornClause>(); for (int i = 0; i < sentences.Count; i++) { Sentence sentence = (Sentence)sentences[i]; HornClause clause = new HornClause(sentence,this); hornClauses.Add(clause); } return hornClauses; }
public bool Equals(HornClause other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.premiseSymbols, this.premiseSymbols) && Equals(other.Head, this.Head)); }
private List <HornClause> asHornClauses(List <Sentence> sentences) { List <HornClause> hornClauses = new List <HornClause>(); for (int i = 0; i < sentences.Count; i++) { Sentence sentence = (Sentence)sentences[i]; HornClause clause = new HornClause(sentence, this); hornClauses.Add(clause); } return(hornClauses); }
private void decrementCount(HornClause hornClause) { int value = (int.Parse(_count[hornClause].ToString())); if (_count.Contains(hornClause)) { _count[hornClause] = value - 1; } else { _count.Add(hornClause, value - 1); } }
private ArrayList asHornClauses(ArrayList sentences) { ArrayList hornClauses = new ArrayList(); for (int i = 0; i < sentences.Count; i++) { Sentence sentence = (Sentence)sentences[i]; //TODO - don't know if i am supposed to pass in the agenda or stack //or whether the inner class is just supposed to create new ones //what does java do? HornClause clause = new HornClause(sentence, this._agenda, this._count, this._inferred); hornClauses.Add(clause); } return(hornClauses); }
public ConcurrentDictionary <int, HornClause> GetHornClauses() { ConcurrentDictionary <int, HornClause> hornClauses; if (hornClauseCache.TryGetValue(kifFilePath ?? kifString, out hornClauses)) { } else { // it's not in the in-memory cache so lets see if it's been serialized to disk var binFilePath = Path.GetDirectoryName(kifFilePath) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(kifFilePath) + ".bin"; if (File.Exists(binFilePath) && (File.GetLastWriteTime(kifFilePath ?? kifString).CompareTo(File.GetLastWriteTime(binFilePath)) < 0)) { return(HornClause.SerializeFromFile(binFilePath)); } hornClauses = new ConcurrentDictionary <int, HornClause>(); string error; foreach (KeyValuePair <int, TFTree <ParseTreeNodeData> > keyValuePair in parseTrees.OrderBy(n => n.Key)) { var collapsedTree = keyValuePair.Value.Root.CreateCollapsedTree( (n => n.Data.TheGoal.Symbol.TheSymbol == "Sentences" || n.Data.TheGoal.Symbol.TheSymbol == "Sentence" || n.Data.TheGoal.Symbol.TheSymbol == "Terms" || n.Data.TheGoal.Symbol.TheSymbol == "Term" || n.Data.TheGoal.Symbol.TheSymbol == "RelWord" || n.Data.TheGoal.Symbol.TheSymbol == "LeftParen" || n.Data.TheGoal.Symbol.TheSymbol == "RightParen")); var hornClause = ParseTreeNodeData.CreateHornClause(collapsedTree, out error); if (hornClause != null) { hornClauses[keyValuePair.Key] = hornClause; } } hornClauseCache.TryAdd(kifFilePath ?? kifString, hornClauses); HornClause.SerializeToFile(hornClauses, binFilePath); } return(hornClauses); }
private void decrementCount(HornClause hornClause) { count[hornClause]--; }
private bool countisZero(HornClause hornClause) { return(int.Parse(_count[hornClause].ToString()) == 0); }
private bool countisZero(HornClause hornClause) { return(count[hornClause] == 0); }
static public HornClause CreateHornClause(TFTreeNode <ParseTreeNodeData> node, out string error) { HornClause hornClause = null; Predicate head = null; Predicate[] body = null; if (node.Data.TheGoal.Symbol.TheSymbol == "LogSent") { // a LogSent will become a rule if (node.Children.Count < 2) { error = "LogSent has fewer than two children"; return(null); } if (node.Children[0].Data.TheGoal.Symbol.TheSymbol != "ImplicationToLeft") { error = "First child of LogSent is not ImplicationToLeft"; return(null); } if (node.Children[1].Data.TheGoal.Symbol.TheSymbol != "RelSent" && node.Children[1].Data.TheGoal.Symbol.TheSymbol != "Word") { error = "Second child of LogSent is not RelSent or Word"; return(null); } else { head = CreatePredicate(node.Children[1], out error); if (head == null) { return(null); } if (head.Functor.ToString() == "next") { ; } body = new Predicate[node.Children.Count - 2]; hornClause = new HornClause(head, body); } int count = 0; foreach (TFTreeNode <ParseTreeNodeData> childNode in node.Children.Skip(2)) { if (childNode.Data.TheGoal.Symbol.TheSymbol != "RelSent" && childNode.Data.TheGoal.Symbol.TheSymbol != "Word") { error = "A child of LogSent is not RelSent or Word"; return(null); } else { hornClause.Body[count] = CreatePredicate(node.Children[count + 2], out error); if (hornClause.Body[count] == null) { return(null); } } count++; } } else if (node.Data.TheGoal.Symbol.TheSymbol == "RelSent") { // a RelSent will become a fact if (node.Children.Count < 1) { error = "RelSent doesn't have any children"; return(null); } head = CreatePredicate(node, out error); if (head == null) { return(null); } hornClause = new HornClause(head); } else { error = "HornClause does not have either a LogSent or RelSent"; return(null); } hornClause = hornClause.RemoveFunctor(new Atom("true")); error = string.Empty; return(hornClause); }
private void DecrementCount(HornClause hornClause) { int value = (count[hornClause]); count[hornClause] = value - 1; }
private bool CountIsZero(HornClause hornClause) { return((count[hornClause]) == 0); }
private bool countisZero(HornClause hornClause) { return count[hornClause] == 0; }