繁体   English   中英

使用 Jena 规则创建多个 skolems

[英]Create multiple skolems with Jena rules

无需多次复制规则即可创建多个 skolems 的简单方法是什么?

[ AddingMother:
    makeSkolem(?mother, "a mother")
    ->
(?mother rdf:title "mother") (?mother rdf:type _:Mother)
]

[ AddingChild:
    (?mother rdf:type _:Mother) makeSkolem(?child, "a child")
    ->
    (?child rdf:title "child") (?child rdf:type _:Child) (?child rdf:hasMother ?mother) (?mother rdf:hasChild ?child)
]

输出是:

OYJ0Aokli2TZDVAK4EQzVA==  --{title}->  mother
OYJ0Aokli2TZDVAK4EQzVA==  --{type}->  :Mother
OYJ0Aokli2TZDVAK4EQzVA==  --{hasChild}->  8xEXOwnWH/tgxFN+HBwNeg==
8xEXOwnWH/tgxFN+HBwNeg==  --{title}->  child
8xEXOwnWH/tgxFN+HBwNeg==  --{type}->  :Child
8xEXOwnWH/tgxFN+HBwNeg==  --{hasMother}->  OYJ0Aokli2TZDVAK4EQzVA==

我想要五个孩子。 这里可以计数吗? 我有点迷失在这里。

您可以根据需要对 skolem 使用尽可能多的参数,这样您也可以让孩子依赖于母亲。 例如,这将使您每个母亲都拥有一个独特的孩子:

[ AddingChild:
    (?mother rdf:type _:Mother) makeSkolem(?child, "a child", ?mother)
    ->
    (?child rdf:title "child") (?child rdf:type _:Child) (?child rdf:hasMother ?mother) (?mother rdf:hasChild ?child)
]

基于此,如果您可以集成某种计数,例如生成索引,那么您可以为每个母亲的每个索引生成一个孩子:

[ AddingChild:
    (?mother :hasChildIndex ?index)
    (?mother rdf:type _:Mother)
    makeSkolem(?child, "a child", ?mother, ?index)
    ->
    (?child rdf:title "child")
    (?child rdf:type _:Child)
    (?child rdf:hasMother ?mother)
    (?mother rdf:hasChild ?child)
]

顺便说一句,您不应在标准未定义的命名空间中使用属性,例如:

    (?child rdf:title "child")
    (?child rdf:hasMother ?mother)
    (?mother rdf:hasChild ?child)

一些推理器和 RDF 处理器会抱怨。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM