【发布时间】:2014-03-31 02:41:03
【问题描述】:
我有一个包含很多人的本体,并使用 Jena 推理器来获取有关他们的信息。我的目标是根据规则内的给定信息创建新个体,并为他们分配属性。个人不必命名,但他们需要一个类型并且必须是一些属性的一部分。目前我可以创建匿名个人(在mailing list post 的帮助下),但我只能给他们一种类型或一种属性。
这是我的问题的一个小例子;我的规则是这样的(本体和推断结果可以在底部找到):
[test2: (?X rdf:type NS:Test1) ->
[(?Y rdf:type NS:Test2)
这意味着当找到一个 Test1 个体时,将创建一个新的空白节点,然后将类型 Test2 赋予该节点。它工作正常,但我想给这个新个体一个分类和一个指向 ?X(Test1 个体)的指针(属性)。
以下内容不起作用,因为“向后规则只允许一个头子句”。不过,它的每个子句都可以正常工作。
[test2: (?X rdf:type NS:Test1) ->
[(?Y rdf:type NS:Test2), (?Y NS:hasClassification 'test'),
这是我的本体:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns="file:/Test#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="file:/Test#hasClassification">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#TestProp">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#testInd">
<rdf:type rdf:resource="file:/Test#Test1"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#testInd2">
<rdf:type rdf:resource="file:/Test#Test1"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#Test1">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#Test2">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
</rdf:Description>
</rdf:RDF>
这是第一条规则的结果(ID 为 A0 和 A1 的空白节点是新个体):
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns="file:/Test#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >
<rdf:Description rdf:about="file:/Test#hasClassification">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A0">
<rdf:type rdf:resource="file:/Test#Test2"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#TestProp">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#testInd">
<rdf:type rdf:resource="file:/Test#Test1"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#testInd2">
<rdf:type rdf:resource="file:/Test#Test1"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#Test1">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test#Test2">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A1">
<rdf:type rdf:resource="file:/Test#Test2"/>
</rdf:Description>
<rdf:Description rdf:about="file:/Test">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
</rdf:Description>
</rdf:RDF>
【问题讨论】:
-
我使用了后向链接规则,因为在 makeSkolum() 之前,我使用过仅在后向/混合规则中可用的 makeInstance()。在尝试使用 makeInstance() 一整天后,我没有考虑使用 makeSkolum() 的简单前向规则。虽然它工作得很好,所以非常好(也适用于你的第二个解释)。关于耶拿,我还有很多东西要学,我很感谢你第二次帮助了我。希望我在不久的将来不再需要帮助。你想回答这个问题,以便我可以将其标记为已解决并给予你应得的信任吗?
-
我很高兴这有帮助!我已经添加了它的本质作为答案。
标签: rdf jena owl blank-nodes jena-rules