Long story short - I had two problems, but the primary is that Jena
requires parenthesis and named var:

SELECT (COUNT(?resource) AS ?count)
FROM <http://id.nlm.nih.gov/mesh>
WHERE {
  ?resource a meshv:Descriptor .
  ?resource rdfs:label ?label .
  ?label bif:contains "Pyrin" .
}

The second problem was that ORDER BY screws up the results, because it
prevented an automated grouping.

On Sat, Mar 23, 2019 at 10:28 PM Dan Davis <dansm...@gmail.com> wrote:

> I've now designed a unit test for the code above, and it works mostly as
> intended.  I still don't see how to get Count queries work as a
> transformation.   The documentation is clear that this should be supported,
> as is the EBNF of the Sparql 1.1 specification.
>
> The next step was to make sure that I was telling qparse to treat my query
> as sparql11:
>
>        ~/tools/apache-jena/bin/qparse --query countquery --syntax=sparql11
> --print=op
>
> Finding the values of Syntax were not that easy, because the --help
> doesn't provide the valid values of the syntax.  Jshell did crack it
> eventually: Syntax.querySyntaxNames.keys()
>
> Sigh - I'd rather be programming Python, but that's OK.
>
> On Fri, Mar 22, 2019 at 5:55 PM Dan Davis <dansm...@gmail.com> wrote:
>
>>
>> Hi guys, I'm writing my first Transform, and I'm having trouble with a
>> count query.
>> arq.qparse doesn't parse and print my count query, so  I cannot get much
>> feedback whether I'm doing the right thing or not.
>>
>> A limit query seems simple enough, however:
>>
>>
>> package gov.nih.nlm.lode.service;
>>
>> import com.hp.hpl.jena.sparql.algebra.Op;
>> import com.hp.hpl.jena.sparql.algebra.TransformBase;
>> import com.hp.hpl.jena.sparql.algebra.op.OpProject;
>> import com.hp.hpl.jena.sparql.algebra.op.OpSlice;
>>
>> public class LimitTransform extends TransformBase {
>>     private long offset;
>>     private long limit;
>>
>>     public LimitTransform(long limit, long offset) {
>>         this.limit = limit;
>>         this.offset = offset;
>>     }
>>     public LimitTransform(long limit) {
>>         this(limit, 0);
>>     }
>>
>>     @Override
>>     public Op transform(OpProject opProject, Op subOp) {
>>         return new OpSlice(opProject, offset, limit);
>>     }
>> }
>>
>>
>>
>>
>>

Reply via email to