On 08/08/14 03:08, Wang Darrell wrote:
here is part of my ontology
- ( Stevie_Wonder - hasMusicalRole - wordnet_synthesist_110687231 )
- ( Stevie_Wonder - hasMusicalRole - wordnet_bass_guitar_102804123 )
- ( Stevie_Wonder - hasMusicalRole - wordnet_piano_103928116 )
Can I use something like
(?x :hasMusicalRole ?y)
and get a count like 3 , then produce a new fact like
( Stevie_Wonder - can - playMutipleInstrument )
while we know he can play 3 kind of instrument.
No, as I said in my last reply the rules can't count the number of times
they fire or would fire without a lot of messing with non-monotonic
rules and arithmetic.
Or is there any way to use Sparql in rules?
like
[ rule:
SELECT count(?y) WHERE { ?s yago:hasMusicalRole ?y . }
->
( Stevie_Wonder - can - playMutipleInstrument )
]
There isn't a way to do that directly at the moment. There is a Google
Summer of Code project exploring the possibility of this but it is a
separate experiment and not part of the main Jena codebase.
However, for just counting it would be pretty easy to create a rules
builtin, something like:
countMatches(?s, ?p, ?o, ?count)
which would do this. The countMatches implementation could use SPARQL
but since it only needs to count triples then just doing it using the
API would be easier. Remember to mark the builtin as non-monotonic.
Dave