简体   繁体   中英

Create multiple skolems with Jena rules

What is an easy way to create multiple skolems without copying the rule multiple times?

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

The output is:

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==

I want to have five childens. Is here counting possible? I am a bit lost here.

You can use as many arguments to the skolem as you want, so you can make the child dependent on the mother, too. Eg, this would get you one unique 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)
]

Based on this, if you could integrate some sort of counting, eg, to produce an index, then you could generate a child per index per mother:

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

As an aside, you shouldn't use properties in the namespace that the standard doesn't define, such as in:

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

Some reasoners and RDF processors will complain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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