Reasoning with Fuseki, TDB and named graphs?

前端 未结 2 979
囚心锁ツ
囚心锁ツ 2020-12-10 07:42

I\'m serving a dataset containing 10-20 named graphs from a TDB dataset in Fuseki 2. I\'d like to use a reasoner to do inference on my data. The behaviour I\'d like to see i

2条回答
  •  隐瞒了意图╮
    2020-12-10 08:44

    I'm facing (or faced) the same problems on my code, but I have a partial solution. Unfortunately the link provided in the comments did not really help the issues I'm still facing, but this answers part of the problem.

    The final view of the data I see is only a very tiny subset of the data (it appears that all the named graphs are dropped somewhere along this pipeline, and only the tiny default graph is left). Using tdb:unionDefaultGraph seems to have no effect on this.

    The workaround I found for this is to explicitly 'register' your named graphs in the configuration file. I don't really know if it is the best way (and did not found any documentation or example for this exact context). A working example on my setup (Fuseki 2.4):

    [usual configuration start]
    
    # TDB Dataset
    :tdb_dataset_readwrite
            a             tdb:DatasetTDB ;
            tdb:unionDefaultGraph true ; 
            #if you want all data to available in the default graph
            #without 'FROM-NAMing them' in the SPARQL query
            tdb:location  "your/dataset/path" .
    
    # Underlying RDF Dataset
    <#dataset> 
        rdf:type    ja:RDFDataset ;
        ja:defaultGraph <#model> ;
        ja:namedGraph [
            ja:graphName     ;
            ja:graph        <#graphVar> 
        ] ;
    
        [repeat for other named graphs]
        .      
    
    
    ######
    # Default Model : Inference rules (OWL, here)
    <#model> a ja:InfModel;
        ja:baseModel <#tdbGraph>;
        ja:reasoner
        [ ja:reasonerURL 
            
        ]
        .
    
    # Graph for the default Model
    <#tdbGraph> rdf:type tdb:GraphTDB;
        tdb:dataset :tdb_dataset_readwrite .
    
    ######
    # Named Graph
    <#graphVar> rdf:type tdb:GraphTDB ;
        tdb:dataset :tdb_dataset_readwrite ;
        tdb:graphName  
        .
    

    Then, you can run a query like this one

    [prefixes]
    
    SELECT ?graph ?predicate ?object
    WHERE {
      GRAPH ?graph {[a specific entity identifier] ?predicate ?object}
    }
    LIMIT 50
    

    And it will display (in this case) properties and values, and the source graph where they were found.

    BUT: in this example, even if the default graph supposedly imported inference rules (that should be applied globally, especially since the unionDefaultGraph parameter is enabled), they are not applied in a "cross-graph" manner, and that is the problem I am still facing.

    Normally, if you add the inference engine to every graph, this should work, according to Andy Seaborne's post here, but it doesn't work in my case.

    Hope this helps nevertheless.

提交回复
热议问题