使用 Jena 规则创建多个 skolems

Create multiple skolems with Jena rules

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

[ 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 使用任意数量的参数,因此您也可以使 child 依赖于母亲。例如,这会给你一个独一无二的 child per mother:

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

基于此,如果您可以集成某种计数,例如生成一个索引,那么您可以为每个母亲生成一个 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 处理器会抱怨。