I just try to rewrite the builtin - print()

public boolean bodyCall(final Node[] args, int length, RuleContext context)
{
 Triple t = new Triple(args[0], args[1], args[2]);
 GraphBase graphBase = new GraphBase() {
 @Override
protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) {
return null;
}
};
 ExtendedIterator<Triple> ts = graphBase.find(t);
if (ts!=null) {
System.out.println(ts.toList().size());
}
else{
System.out.println("ts is null");
}

return true;
}

I look into the GraphBase class and want to use the graphbaseFind() , I
think it's the method I want to use.
If I don't think it in wrong way , I can get a match iterator and get the
size of it.
But it says I need to override the graphBaseFind method .

I just confused about the override. Don't know how can I continue deal with
it.


2014-08-11 15:39 GMT+08:00 Dave Reynolds <[email protected]>:

> On 11/08/14 07:39, Wang Darrell wrote:
>
>> so I need to figure out how the bulitin work in code and built a new one
>> that kind of countMatch?
>>
>
> If you really need to do this in rules then yes.
>
>
>  What is that mean you said API would be eaiser than SPARQL?
>>
>
> Just that, given the info you have available in a builtin, it will be easy
> to create a Triple pattern than you can pass to Graph.find and then just
> count the number of results. You could create and run a full SPARQL query
> but it's not necessary.
>
>
>  and should I
>> know about register the new builtin to somewhere ?
>>
>
> Yes, there's a brief mention of the details at:
> https://jena.apache.org/documentation/inference/#extensions
>
> Looking at the code for RuleMap (which defines a registers a "Deduce"
> builtin) would probably help.
>
> Dave
>
>
>  2014-08-08 15:14 GMT+08:00 Dave Reynolds <[email protected]>:
>>
>>  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
>>>
>>>
>>>
>>>
>>
>

Reply via email to