Dato questo modello molto semplice:Come fare un conteggio nel SPARQL
@prefix : <http://example.org/tags#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
:tag rdf:type rdf:Property .
:item1
rdf:type owl:Thing ;
:tag "a"^^xsd:string .
:item2
rdf:type owl:Thing ;
:tag "a"^^xsd:string , "b"^^xsd:string .
:item3
rdf:type owl:Thing ;
:tag "a"^^xsd:string , "b"^^xsd:string , "c"^^xsd:string .
Sto cercando di ottenere un elenco degli elementi e il conteggio dei tag che ognuno ha:
item tagCount
===== ========
item1 1
item2 2
item3 3
Qui è la mia domanda:
SELECT ?item (count(?tag) as ?tagcount)
WHERE {
?item :tag ?tag
}
Tuttavia sta tornando:
item tagCount
===== ========
6
Da quello che ho letto, questo dovrebbe funzionare. Sto usando Jena 2.6.4
'CONTO' non fa parte della specifica SPARQL 1.0, è stato aggiunto in 1.1. Alcune implementazioni lo supportano nonostante ciò. Sto solo dicendo –
Suvviato per domande chiaramente espresse e formattazione corretta! – cygri