static private Result BCRecursive(KnowledgeBase knowledgeBase, string target) { List <Clause> statements = knowledgeBase.InConclusion(target); List <string> symbolsEntailed = new List <string>(); List <bool> results = new List <bool>(); foreach (Clause c in statements) { bool result = true; foreach (string s in c.Premise) { Result r = BCRecursive(knowledgeBase, s); result &= r.Success; if (r.Success) { symbolsEntailed = r.Symbols; } } results.Add(result); if (!symbolsEntailed.Contains(c.Conclusion)) { symbolsEntailed.Add(c.Conclusion); } } return(new Result(results.All(r => r) && results.Count != 0, symbols: symbolsEntailed)); }
static private short BCRecursive(KnowledgeBase knowledgeBase, string target, List <Sentence> sentencesChecked, ref List <string> symbolsEntailed) { List <Sentence> statements = knowledgeBase.InConclusion(target); short results = 0; foreach (Sentence c in statements) { if (!sentencesChecked.Contains(c)) { sentencesChecked.Add(c); short result = 1; foreach (string s in c.Premise) { List <Sentence> sentencesCheckedCopy = new List <Sentence>(sentencesChecked); short r = BCRecursive(knowledgeBase, s, sentencesCheckedCopy, ref symbolsEntailed); result = r; if (r != 1) { break; // can break out of loop cause all statements must be true } } if (!symbolsEntailed.Contains(c.Conclusion)) { symbolsEntailed.Add(c.Conclusion); } if (result != 0) { results = result; } else { break; } } else if (results == 0) { results = -1; // to indicate overflow on branch so no inference can be drawn from it } } return(results); }