jena icon indicating copy to clipboard operation
jena copied to clipboard

Unable to use ja:schema in InfModels

Open chrisanun opened this issue 1 month ago • 3 comments

Version

5.6.0

What happened?

I created an assembler file which produces the error below (config used included). The schema I wish to use for inference is called Schema_Ontology.ttl but whenever the relevant line is un-commented I receive the error at the bottom. I'm not sure if this is a bug or my configuration is wrong. Any assistance will be appreciated!

Assembler (example.ttl)

# Fuseki configuration

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 tdb2:    <http://jena.apache.org/2016/tdb#>
PREFIX ja:      <http://jena.hpl.hp.com/2005/11/Assembler#>

[] rdf:type fuseki:Server ;
        fuseki:services (
                <#read_write_service>
                <#read_only_service>
        ) .

# Writable service - direct access to TDB dataset
<#read_write_service> rdf:type fuseki:Service ;
        rdfs:label      "Example TDB2 Service (RW)" ;
        fuseki:name       "tdb2-database" ;
        fuseki:serviceQuery     "query" ;
        fuseki:serviceQuery     "sparql" ;
        fuseki:serviceUpdate    "update" ;
        fuseki:serviceReadWriteGraphStore       "data" ;
        fuseki:serviceReadGraphStore    "get" ;
        fuseki:dataset <#tdb_dataset_readwrite> ;
        .

# Read-only service - access via inference model
<#read_only_service> rdf:type fuseki:Service ;
        rdfs:label      "Example TDB2 Service (RO with Inference)" ;
        fuseki:name       "tdb2-inference" ;
        fuseki:serviceQuery     "query" ;
        fuseki:serviceQuery     "sparql" ;
        fuseki:serviceReadGraphStore    "get" ;
        fuseki:dataset  <#inference_dataset> ;
        .

# Dataset wrapper for inference model
<#inference_dataset> rdf:type ja:RDFDataset ;
        ja:defaultGraph <#inference_model> ;
        .

# Inference model that reads from TDB graph
<#inference_model> rdf:type ja:InfModel ;
        ja:baseModel <#tdb_base_graph> ;
        ja:reasoner [
                ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner>
        ] ;
        ja:schema <file:///fuseki/data/schema/Schema_Ontology.ttl>
        .

# TDB graph (model) - this is the key change
<#tdb_base_graph> rdf:type tdb2:GraphTDB ;
        tdb2:dataset <#tdb_dataset_readwrite> ;
        .

# The underlying TDB dataset storage
<#tdb_dataset_readwrite> rdf:type tdb2:DatasetTDB ;
        tdb2:location   "Example" ;
        .

Error

PS C:\Users\Username\Documents\projects\rdf\jena-fuseki-docker-5.6.0> docker-compose run --rm --name BuildingModels --service-ports fuseki --update
time="2025-11-08T10:01:35+11:00" level=warning msg="C:\\Users\\Username\\Documents\\projects\\rdf\\jena-fuseki-docker-5.6.0\\docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion"
[2025-11-07 23:01:37] INFO  Config          :: Fuseki Base = /fuseki/run
[2025-11-07 23:01:37] INFO  Config          :: Load configuration: file:///fuseki/run/configuration/example2.ttl
Exception in thread "main" org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException: cannot find a most specific type for :inference_model, which has as possibilities: ja:InfModel ja:ReasonerFactory.
  doing:
    root: file:///fuseki/run/configuration/example2.ttl#inference_dataset with type: http://jena.hpl.hp.com/2005/11/Assembler#RDFDataset assembler class: class org.apache.jena.sparql.core.assembler.DatasetAssemblerGeneral

        at org.apache.jena.assembler.assemblers.AssemblerGroup$PlainAssemblerGroup.open(AssemblerGroup.java:145)
        at org.apache.jena.assembler.assemblers.AssemblerGroup$ExpandingAssemblerGroup.open(AssemblerGroup.java:96)
        at org.apache.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:39)
        at org.apache.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:35)
        at org.apache.jena.assembler.assemblers.AssemblerGroup.openModel(AssemblerGroup.java:44)
        at org.apache.jena.sparql.core.assembler.DatasetAssemblerGeneral.createDataset(DatasetAssemblerGeneral.java:53)
        at org.apache.jena.sparql.core.assembler.NamedDatasetAssembler.createNamedDataset(NamedDatasetAssembler.java:49)
        at org.apache.jena.sparql.core.assembler.DatasetAssembler.open(DatasetAssembler.java:42)
        at org.apache.jena.sparql.core.assembler.DatasetAssembler.open(DatasetAssembler.java:33)
        at org.apache.jena.assembler.assemblers.AssemblerGroup$PlainAssemblerGroup.openBySpecificType(AssemblerGroup.java:160)
        at org.apache.jena.assembler.assemblers.AssemblerGroup$PlainAssemblerGroup.open(AssemblerGroup.java:147)
        at org.apache.jena.assembler.assemblers.AssemblerGroup$ExpandingAssemblerGroup.open(AssemblerGroup.java:96)
        at org.apache.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:39)
        at org.apache.jena.assembler.assemblers.AssemblerBase.open(AssemblerBase.java:35)
        at org.apache.jena.fuseki.build.FusekiConfig.getDataset(FusekiConfig.java:694)
        at org.apache.jena.fuseki.build.FusekiConfig.buildDataService(FusekiConfig.java:443)
        at org.apache.jena.fuseki.build.FusekiConfig.buildDataAccessPoint(FusekiConfig.java:431)
        at org.apache.jena.fuseki.build.FusekiConfig.readConfiguration(FusekiConfig.java:408)
        at org.apache.jena.fuseki.build.FusekiConfig.readConfigurationDirectory(FusekiConfig.java:386)
        at org.apache.jena.fuseki.mod.admin.FMod_Admin.prepare(FMod_Admin.java:149)
        at org.apache.jena.fuseki.main.sys.FusekiModuleStep.lambda$prepare$0(FusekiModuleStep.java:38)
        at java.base/java.lang.Iterable.forEach(Unknown Source)
        at org.apache.jena.fuseki.main.sys.FusekiModules.forEach(FusekiModules.java:106)
        at org.apache.jena.fuseki.main.sys.FusekiModuleStep.prepare(FusekiModuleStep.java:38)
        at org.apache.jena.fuseki.main.FusekiServer$Builder.build(FusekiServer.java:1389)
        at org.apache.jena.fuseki.server.FusekiServerRunner.construct(FusekiServerRunner.java:79)
        at org.apache.jena.fuseki.main.cmds.FusekiServerCmd.main(FusekiServerCmd.java:50)

Relevant output and stacktrace


Are you interested in making a pull request?

None

chrisanun avatar Nov 07 '25 23:11 chrisanun

Hi @chrisanun

ja:schema is associated with the reasoner so it should be:

<#inference_model> rdf:type ja:InfModel ;
        ja:baseModel <#tdb_base_graph> ;
        ja:reasoner [
                ja:reasonerURL <http://jena.hpl.hp.com/2003/OWLFBRuleReasoner> ;
                ja:schema <#schema>
        ] ;
        .

The error you are getting is because ja:schema has domain reasonserFactory so <#inference_model> is inferred to be ja:ReasonerFactory as well as ja:InfModel.

Also - the schema object is a model (this could be inline):

<#schema> a ja:MemoryModel ;
    ja:content [
        ja:externalContent <file:///fuseki/data/schema/Schema_Ontology.ttl>
    ] .

afs avatar Nov 11 '25 10:11 afs

Thanks for that! It got rid of the error. Now that Jena starts successfully, querying the inferred model produces zero results, let alone the inferred relationships I'm hoping will be viewable from there as well.

Imported models will prefix Schema_Ontology.ttl and the aim here is to import a model that is processed in the light of the ontology the results of which can be queried in the inference_dataset.

I was unable to work this out from the available docs!

chrisanun avatar Nov 12 '25 20:11 chrisanun

If the Fuseki log file is clean, it sounds like the setup in Fuseki is now correct so it might be the ontology.

Have you tried a simpler setup, e.g. put data and ontology in one test file, and not use ja:schema?

afs avatar Nov 15 '25 11:11 afs