Jena:推理规则的标签定义错误

Jena: Error upon labels definition for inference rule

我正在尝试为 Apache Jena 定义以下推理规则。我在混合模式下使用 GeneralRuleReasoner

[ 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)
]

我也用单引号试过同样的方法。这失败并出现此错误:

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

我也试过这样定义

[ 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)
]

这实际上不起作用,因为显然 lang 仅适用于查询 DSL。 我还尝试执行以下操作:我在 ontology 中定义了另一个 class,它带有我无法在推理规则中定义的标签和主要标签,并添加了一个 onto: 属性到 派生 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)

]

从某种意义上说,推理规则 IS 在尝试查询 (SPARQL) 三元组时创建了 BUT,无论是标签不是派生的主要标签 class 出现了。不过,我可以看到 anotherR test.

相关

所以我的问题是:在推理规则中定义标签(包括语言规范)的正确方法是什么?

Jena 支持推理规则的特定语言文字定义。要克服这个问题:

  1. 您可以自定义 BaseBuiltin 手动创建特定于语言的节点:

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

  2. 创建另一个 class,其中包含您想要的语言特定标签,并引用另一个 class。但这还不够,因为您将不得不创建 另一个 推理规则,将新 class 的标签分配给引用者 class。这种关系看起来像这样: 从推理规则

    a meta:refersTo b

在ontology定义中

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

在另一个推理规则中

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