def buildFacts(self, indexedFormula): facts = [] for f in self.dumpLists(indexedFormula): facts.append( terms.Fact(convertBNodeToFact(f.s), f.p, convertBNodeToFact(f.o))) # for alphaNode in self.interp.rete.alphaNodeStore: # print alphaNode # i = alphaNode.pattern.noneBasedPattern() # pattern = self.convFromRete(i[0]), self.convFromRete(i[1]), self.convFromRete(i[2]) # print "pattern:", pattern # for quad in indexedFormula.statementsMatching( # subj=pattern[0], # pred=pattern[1], # obj =pattern[2]): ## print "quad:", quad # if isinstance(subj, formula.Formula) or isinstance(obj, formula.Formula): # print "The RETE engine cannot process nested formulas currently" # continue # # s, p, o = [self.convType(x, indexedFormula, None) for x in quad.spo()] # # alphaNode.add(terms.Fact(s,p,o)) for fact in indexedFormula.statements: subj, predi, obj = fact.spo() # ignore formulas for now if isinstance(subj, formula.Formula) or \ isinstance(obj, formula.Formula): print "The RETE cannot process nested formulas at the time - use it for ntriples only" # raise NotImplementedError continue # only get top level facts head = [] tail = [] s, p, o = [ self.convType(x, indexedFormula, None) for x in fact.spo() ] #to get variables. #Not good enough for Lists, but they're taken care of earlier facts.append(terms.Fact(s, p, o)) self.interp.addFacts(Set(facts), initialSet=True) return facts
def facts(g): for s, p, o in g: if p != LOG.implies and not isinstance( s, BNode) and not isinstance(o, BNode): yield terms.Fact(_convert(s), _convert(p), _convert(o))