Create multiple skolems with Jena rules

242 views Asked by At

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.

1

There are 1 answers

2
Joshua Taylor On BEST ANSWER

You can use as many arguments to the skolem as you want, so you can make the child dependent on the mother, too. E.g., 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, e.g., 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.