Skip to content

Graph not initialized from a TopDownSPARQLEntailingStore #8

Description

@RomainEndelin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions