Search code examples
labeljenardfsinference-engine

Jena: Error upon labels definition for inference rule


I am trying to define the following inference rule for Apache Jena. I am using a GeneralRuleReasoner in hybrid mode

[ aName:
        (?aRelation meta:refersTo meta:SomeOntologyClass)
        (?test rdfs:type dummy)
           -> (?anotherRelation rdfs:type meta:SomeType)
              (?anotherRelation meta:mainLabel "a"@fr)
              (?anotherRelation meta:mainLabel "b"@en)
              (?anotherRelation meta:mainLabel "c"@de)
              (?anotherRelation rdfs:label "a"@fr)
              (?anotherRelation rdfs:label "b"@en)
              (?anotherRelation rdfs:label "c"@de)
              (?test meta:has ?anotherRelation)
]

I also tried the same with single quotes. This fails with this error:

[error] - 2020-01-23 17:10:14,655 [play-dev-mode-akka.actor.default-dispatcher-58] ERROR controllers.IndexController - Triple with 4 nodes!

I also tried to define it like

[ aName:
        (?aRelation meta:refersTo meta:SomeOntologyClass)
        (?test rdfs:type dummy)
           -> (?anotherRelation rdfs:type meta:SomeType)
              (?anotherRelation meta:mainLabel "a" lang:fr)
              (?anotherRelation meta:mainLabel "b" lang:en)
              (?anotherRelation meta:mainLabel "c" lang:de)
              (?anotherRelation rdfs:label "a" lang:fr)
              (?anotherRelation rdfs:label "b" lang:en)
              (?anotherRelation rdfs:label "c" lang:de)
              (?test meta:has ?anotherRelation)
]

This does not really work since apparently lang only works for query DSL. I also tried doing the following: I defined another class in the ontology that carries the labels and main labels that I cannot define in the inference rule and add a onto: property to the derived class.

[ aName:
        (?aRelation meta:refersTo meta:SomeOntologyClass)
        (?test rdfs:type dummy)
           -> (?anotherRelation rdfs:type meta:SomeType)
              (?anotherRelation meta:refersTo onto:UtilityClassCarryngLabels)
              (?test meta:has ?anotherRelation)

]

This works in the sense that the inference rule IS created BUT when tried to query (SPARQL) for the triples, neither the labels not the main labels for the derived class came up. Nevertheless, I can see that anotherR has been correlated with test.

So my question is: What is the right way to define labels(including language specification) in an inference rule?


Solution

  • Jena does not support language specific literal definition for inference rules. To overcome this:

    1. You could define a custom BaseBuiltin that creates language specific node manually:

      NodeFactory.createLiteral(string.getLiteral.getLexicalForm, lang.getLiteral.getLexicalForm)

    2. Create another class that holds the language specific labels you want and refer to this other class. This will not be enough though since you're going to have to create another inference rule that assigns the labels of new class to the referrer class. The relation would look like this: From the inference rule

      a meta:refersTo b

    In the ontology definition

    b rdfs:label "foo"@de , "bar"@fr ;
    

    In another inference rule

    ?referrer meta:refersTo b
        -> [(?class rdfs:label ?label)
                      <- (b rdfs:label ?label)]