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

Graph not initialized from a TopDownSPARQLEntailingStore #8

Open RomainEndelin opened 10 years ago

RomainEndelin commented 10 years ago

I try to follow the tutorial, and I passed the Magic Set Method, but I am now stuck in Backward-chaining Inference section.

I followed the steps :

>>> from FuXi.SPARQL.BackwardChainingStore import TopDownSPARQLEntailingStore
>>> from FuXi.Horn.HornRules import HornFromN3
>>> from rdflib import Graph
>>> from rdflib import Namespace
>>> import pprint

>>> famNs = Namespace('http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#')
>>> nsMapping = {u'fam' : famNs}
>>> rules = HornFromN3('http://dev.w3.org/2000/10/swap/test/cwm/fam-rules.n3')
>>> factGraph = Graph().parse('http://dev.w3.org/2000/10/swap/test/cwm/fam.n3', format='n3')
>>> factGraph.bind(u'fam',famNs)
>>> dPreds = [famNs.ancestor]

>>> topDownStore = TopDownSPARQLEntailingStore(factGraph.store,
...                                            factGraph,
...                                            idb=rules,
...                                            derivedPredicates=dPreds,
...                                            nsBindings=nsMapping)
>>> targetGraph = Graph(topDownStore)
>>> targetGraph.bind(u'ex', famNs)
>>> pprint(list(targetGraph.query('''SELECT ?ANCESTOR { fam:david fam:ancestor ?ANCESTOR }''',initNs=nsMapping)))
[]

After checking a bit, it appears that topDownStore is correctly initialized:

>>> topDownStore.edb.serialize(format='n3')
@prefix : <http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#> .
@prefix fam: <http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

fam:albert fam:begat fam:bevan,
        fam:bill .

fam:bertha fam:begat fam:carol,
        fam:charlie .

fam:bevan fam:begat fam:chaude,
        fam:christine .

fam:bill fam:begat fam:carol,
        fam:charlie .

fam:christine fam:begat fam:david,
        fam:diana,
        fam:douglas .

But the problem rather comes when initializing the targetGraph:

>>> targetGraph = Graph(topDownStore)
>>> targetGraph.bind(u'ex', famNs)

>>> targetGraph.serialize(format='n3')
@prefix ex: <http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#> .
@prefix fam: <http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

I suppose there had been some changes in the way rdflib.Graph deals with store, but I wasn't able to find anything relevant about it...

Thanks

ghost commented 9 years ago

I added a test for this issue: aeaf43369e4f7ef766b5b09414ae6abed8d705cc

ghost commented 2 years ago

Just for clarity, the tutorial reports that the results should be:

    >>> pprint(list(targetGraph.query(
        'SELECT ?ANCESTOR { fam:david fam:ancestor ?ANCESTOR }',initNs=nsMapping)))
    [rdflib.URIRef('http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#albert'),
     rdflib.URIRef('http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#bevan'),
     rdflib.URIRef('http://dev.w3.org/2000/10/swap/test/cwm/fam.n3#christine')]