semsol / arc2

ARC RDF Classes for PHP
Other
332 stars 89 forks source link

COUNT doesn't work with local endpoint #120

Closed saphiree closed 6 years ago

saphiree commented 6 years ago

Hai, I want to ask, I made a query using count, but I didn't get the result. This is the query test, that I've tried

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX mpasi: <http://www.semanticweb.org/astrid/ontologies/mpasi#>
SELECT ?food 
WHERE {
      ?food mpasi:foodFor ?babyAge.
      ?foodSource mpasi:data_memerlukanBahan ?memerlukanBahan.
      ?food ?memerlukanBahan ?value.
      ?foodSource2 mpasi:data_menghindari_bahan ?menghindari_bahan. 
      ?food2 ?menghindari_bahan ?value2. 
      FILTER regex (str(?babyAge),"6-8month" ).
      FILTER regex (str(?menghindari_bahan),"mango").
      FILTER (regex (str(?memerlukanBahan),"banana")||regex (str(?memerlukanBahan),"apple")). 
      FILTER (str(?food) = str(?food2)).
}
GROUP BY ?food 
HAVING (count(?memerlukanBahan )  > 1)

Then, I've tried to make simple count query, but I didn't get any result. This is the simple query count

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX mpasi: <http://www.semanticweb.org/astrid/ontologies/mpasi#>
SELECT(COUNT(?fooda) AS ?foodd)
WHERE {
    ?fooda rdf:type ?type
    ?type rdfs:subClassOf mpasi:foodSource
}

How to solve this? Thank you

EDIT by @k00ni: Add syntax highlighting to SPARQL queries.

saphiree commented 6 years ago

Sorry, It worked, when I tried using simple COUNT ^^ .. But, when I have "having" it shows error ... How to solve that? thanks

k00ni commented 6 years ago

Hi @saphiree, as far as i know ARC2 doesn't support HAVING in SPARQL. Source: https://github.com/semsol/arc2/wiki/SPARQL-

saphiree commented 6 years ago

Ah, I see .. thanks @k00ni ^^

k00ni commented 6 years ago

You're welcome.