RDFLib / FuXi

Chimezie Ogbuji's FuXi reasoner. NON-FUNCTIONING, RETAINED FOR ARCHIVAL PURPOSES. For working code plus version and associated support requirements see:
http://code.google.com/p/fuxi/
51 stars 28 forks source link

Rules appear not to be properly constructed #14

Open doriantaylor opened 8 years ago

doriantaylor commented 8 years ago

Currently trying to get the OWL rules to be processed correctly. dct.n3 is just http://purl.org/dc/terms/ to use as input fodder.

pdb `which FuXi` -d  --input-format=n3   --rules  http://www.agfa.com/w3c/euler/rdfs-rules.n3 --rules http://www.agfa.com/w3c/euler/owl-rules.n3  /tmp/dct.n3

Running the FuXi script (bare and in the debugger) gives me a bunch of these:

/…/FuXi/Rete/CommandLine.py:443: SyntaxWarning: Integrity constraints (rules with empty heads) are not supported: Forall ?X ?A ( And(  ) :- And( owl:equivalentClass(?A owl:Nothing) ?A(?X) ) )

…and then crashes with a KeyError here: https://github.com/RDFLib/FuXi/blob/master/lib/Rete/Network.py#L360

I added the following condition in my test code:

        try:
            flhs = self.ruleStore.formulae[lhs]
            frhs = self.ruleStore.formulae[rhs]
        except KeyError as e:
            import warnings
            warnings.warn("Could not find rule %s in rule store" % rule,
                SyntaxWarning, 2)
            raise e

This spits out the offending rule as something like:

(Pdb) p rule
Forall _:N58f3fe0d6efa485eb833f4518991fa8b ?X _:N0cdcf914557f4059bf7c5d114e004be3 ?M ( Exists _:N58f3fe0d6efa485eb833f4518991fa8b _:N58e667762cb3452bb0330582592477e4 _:N43a8f967776a40208352e3912c6e1b02 _:N0cdcf914557f4059bf7c5d114e004be3 ( And( notItem(rdf:nil N58e667762cb3452bb0330582592477e4) rdf:first(rdf:nil N58e667762cb3452bb0330582592477e4) rdf:rest(rdf:nil N58f3fe0d6efa485eb833f4518991fa8b) rdf:first(N58f3fe0d6efa485eb833f4518991fa8b N43a8f967776a40208352e3912c6e1b02) rdf:rest(N58f3fe0d6efa485eb833f4518991fa8b N0cdcf914557f4059bf7c5d114e004be3) rdf:first(N0cdcf914557f4059bf7c5d114e004be3 1) rdf:rest(N0cdcf914557f4059bf7c5d114e004be3 rdf:nil) ) ) :- )

That smiley-face looking construct at the tail of the rule is, from my reading, a syntax error in RIF. Likewise is And( ) in the SyntaxWarning above. If we inspect the rule's body:

(Pdb) p rule.formula.body
And(  )
(Pdb) p rule.formula.body.__dict__
{'nsMgr': <rdflib.namespace.NamespaceManager object at 0x98fcdcc>, 'nsDict': {}, 'naf': False, 'formulae': []}

My tentative conclusion is that something in the process is generating these illegal empty And( ) constructs. I have a hunch that it has something to do with the fact that certain terms evaluate to False, as I found in issue #13.