This document describes how inferences are performed with the Fuseki triplestore in the MICA project. It also defines a framework based on Junit to test that inferences are correctly performed.
# Declaration additional assembler items. [] ja:loadClass "org.apache.jena.tdb.TDB" . # TDB tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset . tdb:GraphTDB rdfs:subClassOf ja:Model .
After these modifications the config.ttl file looks like:
# Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0 ## Fuseki Server configuration file. @prefix : <#> . @prefix fuseki: <http://jena.apache.org/fuseki#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> . @prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> . [] rdf:type fuseki:Server . # Example:: # Server-wide query timeout. # # Timeout - server-wide default: milliseconds. # Format 1: "1000" -- 1 second timeout # Format 2: "10000,60000" -- 10s timeout to first result, # then 60s timeout for the rest of query. # # See javadoc for ARQ.queryTimeout for details. # This can also be set on a per dataset basis in the dataset assembler. # # ja:context [ ja:cxtName "arq:queryTimeout" ; ja:cxtValue "30000" ] ; # Add any custom classes you want to load. # Must have a "public static void init()" method. # ja:loadClass "your.code.Class" ; # End triples. # Declaration additional assembler items. [] ja:loadClass "org.apache.jena.tdb.TDB" . # TDB tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset . tdb:GraphTDB rdfs:subClassOf ja:Model .
The inference rules are created according to the model and the ontology.
For example, a concept c1 has skos:broader a concept c2, it means that a concept c2 has skos:narrower a concept c1.
the rule of this inference is the following:
@prefix skos: <http://www.w3.org/2004/02/skos/core#> . # R1: create the narrower property [broaderNarrowerRule: (?A skos:broader ?B) -> (?B skos:narrower ?A) ]
After you define all the rules, the rules file looks like this:
@prefix skos: <http://www.w3.org/2004/02/skos/core#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix micamodel: <https://w3id.org/mica/ontology/MicaModel#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix micavocab: <https://w3id.org/mica/ontology/MicaOntology/> . # R1: create the narrower property [broaderNarrowerRule: (?A skos:broader ?B) -> (?B skos:narrower ?A) ] # R2: create the directly broaderTransitive property [broaderRule: (?A skos:broader ?B) -> (?A skos:broaderTransitive ?B) ] # R3: create the hierarchical broaderTransitive property [broaderTransitiveRule: (?A skos:broaderTransitive ?B),(?B skos:broaderTransitive ?C) -> (?A skos:broaderTransitive ?C) ] # R4: create the directly narrowerTransitive property [narrowerRule: (?A skos:narrower ?B) -> (?A skos:narrowerTransitive ?B) ] # R5: create the hierarchical narrowerTransitive property [narrowerTransitiveRule: (?A skos:narrowerTransitive ?B),(?B skos:narrowerTransitive ?C) -> (?A skos:narrowerTransitive ?C) ] # R6: create the reflexive broaderTransitive and narrowerTransitive [conceptReflexiveRule: (?A rdf:type skos:Concept) -> (?A skos:broaderTransitive ?A), (?A skos:narrowerTransitive ?A) ] # R7: create the symetric property for related concept [relatedRule: (?A skos:related ?B) -> (?B skos:related ?A) ] # R8: create Heritage on data [ dataHeritageRule: (?A rdf:type ?B ),(?B rdfs:subClassOf ?C ) -> (?A rdf:type ?C )] # R9: create heritage on class [ subClassRule: (?A rdfs:subClassOf ?B ),(?B rdfs:subClassOf ?C )-> (?A rdfs:subClassOf ?C )] # R10: create Heritage on property [ propertyHeritageRule: (?P rdfs:subPropertyOf ?Q ),(?A ?P ?B )-> (?A ?Q ?B ) ] # R11: create the symetric property for relatedTo MICAResource [ relatedToRule: (?A micamodel:relatedTo ?B) -> (?B micamodel:relatedTo ?A)] # R12: create the DomainConcept [ DomainConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:DomainScheme ) -> (?A rdf:type micamodel:DomainConcept)] # R13: create the MethodConcept [ MethodConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:MethodScheme ) -> (?A rdf:type micamodel:MethodConcept)] # R14: create the DataConcept [ DataConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:DataScheme ) -> (?A rdf:type micamodel:DataConcept)] # R15: create the TemporalConcept [ TemporalConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:TemporalScheme ) -> (?A rdf:type micamodel:TemporalConcept)] # R16: create the SpatialConcept [ SpatialConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:SpatialScheme ) -> (?A rdf:type micamodel:SpatialConcept)] # R17:create the CommodityConcept [ CommodityConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:CommodityScheme ) -> (?A rdf:type micamodel:CommodityConcept)] # R18: create the ValueSupplyChainConcept [ ValueSupplyChainConceptRule: (?A rdf:type skos:Concept ),(?A skos:inScheme micavocab:ValueSupplyChainScheme ) -> (?A rdf:type micamodel:ValueSupplyChainConcept)]
replace
:tdb_dataset_readwrite a tdb:DatasetTDB ; tdb:location "/srv/fuseki/databases/testMicaOntology" .
by
:tdb_dataset_readwrite rdf:type ja:RDFDataset ; ja:defaultGraph :modelInf . :modelInf a ja:InfModel ; ja:reasoner [ ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner> ; ja:rulesFrom <file:./MICA.rules> ; ] ; ja:baseModel :dataGraph . :dataGraph a tdb:GraphTDB ; tdb:location "/srv/fuseki/databases/testMicaOntology" ;
after these modifications testMicaOntolgy.ttl looks like
@prefix : <http://base/#> . @prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix fuseki: <http://jena.apache.org/fuseki#> . :service_tdb_all a fuseki:Service ; rdfs:label "TDB testMicaOntology" ; fuseki:dataset :tdb_dataset_readwrite ; fuseki:name "testMicaOntology" ; fuseki:serviceQuery "query" , "sparql" ; fuseki:serviceReadGraphStore "get" ; fuseki:serviceReadWriteGraphStore "data" ; fuseki:serviceUpdate "update" ; fuseki:serviceUpload "upload" . :tdb_dataset_readwrite rdf:type ja:RDFDataset ; ja:defaultGraph :modelInf . :modelInf a ja:InfModel ; ja:reasoner [ ja:reasonerURL <http://jena.hpl.hp.com/2003/GenericRuleReasoner> ; ja:rulesFrom <file:./MICA.rules> ; ] ; ja:baseModel :dataGraph . :dataGraph a tdb:GraphTDB ; tdb:location "/srv/fuseki/databases/testMicaOntology" ;