Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph not initialized from a TopDownSPARQLEntailingStore #8

Open
RomainEndelin opened this issue Feb 20, 2014 · 2 comments
Open

Graph not initialized from a TopDownSPARQLEntailingStore #8

RomainEndelin opened this issue Feb 20, 2014 · 2 comments

Comments

@RomainEndelin
Copy link

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 pushed a commit that referenced this issue Jul 23, 2015
@ghost
Copy link

ghost commented Jul 23, 2015

I added a test for this issue: aeaf433

@ghost
Copy link

ghost commented Nov 12, 2021

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')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant