コード例 #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
コード例 #2
0
ファイル: builtins.py プロジェクト: AwelEshetu/cwm
    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
コード例 #3
0
ファイル: conclusion.py プロジェクト: AwelEshetu/cwm
    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        
コード例 #4
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