Exemple #1
0
    def buildRules(self, indexedFormula):
        rules = []
        for rule in indexedFormula.statementsMatching(
                pred=indexedFormula.store.implies):
            subj, predi, obj = rule.spo()

            if not isinstance(subj, formula.Formula) or \
               not isinstance(obj, formula.Formula):
                continue
            head = []
            tail = []
            for fr, to in (subj, tail), (obj, head):
                self.extra = self.dumpLists(
                    fr)  #use extra for the list-related triples
                for quad in fr:
                    #if not isinstance(quad.subject(), term.NonEmptyList):
                    s, p, o = [
                        self.convType(x, indexedFormula, fr)
                        for x in quad.spo()
                    ]  #to get variables.
                    #Not good enough for Lists
                    #                    print "spo:", s,p,o
                    for f in (self.extra + [(s, p, o)]):
                        to.append(terms.Pattern(*f))
            rules.append(terms.Rule(tail, head, (subj, predi, obj)))

        return rules
Exemple #2
0
 def testPychinko(self):
     rules = []
     for s, p, o in self.g.triples((None, LOG.implies, None)):
         lhs = list(patterns(s))
         rhs = list(patterns(o))
         rules.append(terms.Rule(lhs, rhs, (s, p, o)))
     interp = Interpreter(rules)
     f = Graph()
     f.parse("http://eikeon.com/")
     source = f
     source = self.g
     interp.addFacts(set(facts(source)), initialSet=True)
     interp.run()