Exemple #1
0
 def testUnionSkolemization(self):
     network = ReteNetwork(self.ruleStore)  # ,nsMap = self.ruleStore.nsMgr)
     p = network.setupDescriptionLogicProgramming(self.tBoxGraph)
     for p in p:
         self.failIf(
             p.formula.body.arg[-1].find(SKOLEMIZED_CLASS_NS) > -1,
             "Rule has a skolem term when it shouldn't!: %s" % p,
         )
Exemple #2
0
 def testUnionSkolemization(self):
     network = ReteNetwork(self.ruleStore)  # ,nsMap = self.ruleStore.nsMgr)
     p = network.setupDescriptionLogicProgramming(self.tBoxGraph)
     for p in p:
         if hasattr(p.formula.body, 'arg'):
             self.failIf(
                 p.formula.body.arg[-1].find(SKOLEMIZED_CLASS_NS) > -1,
                 "Rule has a skolem term when it shouldn't!: %s" % p)
         else:
             print("%s - find(SKOLEMIZED_CLASS_NS)" % p.formula.body)
def build_network2(rules):
    graph = ConjunctiveGraph()
    graph.load(StringIO(rules), publicID='test', format='n3')
    rule_store, rule_graph = SetupRuleStore(
        StringIO(rules),
        additionalBuiltins={STRING_NS.startsWith: StringStartsWith})
    from FuXi.Rete.Network import ReteNetwork
    network = ReteNetwork(rule_store)
    network.feedFactsToAdd(generateTokenSet(extractBaseFacts(graph)))
    return network
def build_network2(rules):
    graph = ConjunctiveGraph()
    graph.load(StringIO(rules), publicID='test', format='n3')
    rule_store, rule_graph = SetupRuleStore(
        StringIO(rules),
        additionalBuiltins={STRING_NS.startsWith: StringStartsWith})
    from FuXi.Rete.Network import ReteNetwork
    network = ReteNetwork(rule_store)
    network.feedFactsToAdd(generateTokenSet(extractBaseFacts(graph)))
    return network
 def testExistentials(self):
     store = plugin.get('IOMemory', Store)()
     store.open('')
     ruleStore = N3RuleStore()
     ruleGraph = Graph(ruleStore)
     ruleGraph.parse(StringIO(N3_PROGRAM), format='n3')
     factGraph = Graph(store)
     factGraph.parse(StringIO(N3_FACTS), format='n3')
     deltaGraph = Graph(store)
     network = ReteNetwork(ruleStore,
                           initialWorkingMemory=generateTokenSet(factGraph),
                           inferredTarget=deltaGraph)
     inferenceCount = 0
     for inferredFact in network.inferredFacts.subjects(
             predicate=RDF.type,
             object=URIRef('http://example.com/#Inference')):
         inferenceCount = inferenceCount + 1
     print(network.inferredFacts.serialize(format='n3'))
     self.failUnless(inferenceCount > 1,
                     'Each rule firing should introduce a new BNode!')