Beispiel #1
0
    def evaluate(self, subj, obj):

        # need an N3 loader to get rules and facts first

        f = Formula()
        for conjunct in subj:
            f.patterns.extend(conjunct.patterns)               

        f.rules = list(f.getRules())
        f.facts = list(f.getFacts())
        
        
        return f
Beispiel #2
0
    def evaluate(self, subj, obj):
        #this is trickier:
        #create a rete, run it until no more new facts are found
        #return back the formula
        print "here!"

        
        rules = subj.rules
        #there may be facts in the rules file
        facts = subj.facts
                
        interp = Interpreter(rules)

        #print "patterns:"
        # for i in  subj.patterns:
        #    print i
        for i in rules:
            print "rule:", i
        #print "Ground fact(s): ", len(facts)
        #print facts
                
        
        interp.addFacts(Set(facts), initialSet=True)
        
        
        interp.run()

        print "interpreter sucessfully ran"
        print len(interp.inferredFacts)

        #create a new formula with the new facts + the stuff in subj and return it
        f = Formula()
        # copy all of the patterns
        f.patterns.extend(subj.patterns)

        #add the new ones
        for i in interp.inferredFacts:
            f.patterns.append(Pattern(i.s, i.p, i.o))
                        
        f.rules = f.getRules()
        f.facts = f.getFacts()

        return f        
Beispiel #3
0
    def evaluate(self, subj, obj):

        if not subj.startswith('http://'):
            subj = pathname2url(subj)

        p = N3Loader()
        p.parse(subj, format='n3')

        f = Formula(p)

        return f
Beispiel #4
0
    def evaluate(self, subj, obj):

        # need an N3 loader to get rules and facts first

        f = Formula()
        for conjunct in subj:
            f.patterns.extend(conjunct.patterns)

        f.rules = list(f.getRules())
        f.facts = list(f.getFacts())

        return f
Beispiel #5
0
    def evaluate(self, subj, obj):
        #this is trickier:
        #create a rete, run it until no more new facts are found
        #return back the formula
        print "here!"

        rules = subj.rules
        #there may be facts in the rules file
        facts = subj.facts

        interp = Interpreter(rules)

        #print "patterns:"
        # for i in  subj.patterns:
        #    print i
        for i in rules:
            print "rule:", i
        #print "Ground fact(s): ", len(facts)
        #print facts

        interp.addFacts(Set(facts), initialSet=True)

        interp.run()

        print "interpreter sucessfully ran"
        print len(interp.inferredFacts)

        #create a new formula with the new facts + the stuff in subj and return it
        f = Formula()
        # copy all of the patterns
        f.patterns.extend(subj.patterns)

        #add the new ones
        for i in interp.inferredFacts:
            f.patterns.append(Pattern(i.s, i.p, i.o))

        f.rules = f.getRules()
        f.facts = f.getFacts()

        return f