sorry for the irrevelant title, I'm French and I didn't know how to expose my problem. I think the best way to explain it is with an example.
I have some RDF sets like this one:
prefix p: <http://localhost/rdf/>
p:set p:hasTitle p:val1 .
p:set p:hasTitle p:val2 .
p:set p:hasAuthor p:val3 .
p:set p:hasAuthor p:val4 .
p:val1 p:hasValue "Harry Peter" .
p:val1 p:hasScore 0.30 .
p:val2 p:hasValue "Harry Potter" .
p:val2 p:hasScore 0.90 .
p:val3 p:hasValue "J. K. Rowling".
p:val3 p:hasScore 0.90 .
p:val4 p:hasValue "Joanne Rowling" .
p:val4 p:hasScore 0.50 .
I want to construct another graph with a sparql query, with only the values with the best score for each distinct property. In this example, the query is supposed to return this:
prefix p: <http://localhost/rdf/>
p:set p:hasTitle p:val2 .
p:set p:hasAuthor p:val3 .
p:val2 p:hasValue "Harry Potter" .
p:val2 p:hasScore 0.90 .
p:val3 p:hasValue "J. K. Rowling" .
p:val3 p:hasScore 0.90 .
For now I have tried something like this:
PREFIX p: <http://localhost/rdf/>
CONSTRUCT {
p:root p:hasSameAsSet ?saSet .
?saSet ?prop ?bestVal .
?bestVal ?p ?v
}
WHERE {
?s p:hasSameAsSet ?saSet .
?saSet ?prop ?val .
?bestVal ?p ?v .
?bestVal p:hasQualityScore ?m
{
SELECT (MAX(?score) AS ?m)
WHERE {
?val p:hasQualityScore ?score
} GROUP BY ?prop
}
}
I'm discovering Sparql and I know I'm missing important things. I hope someone can help me, thank you very much ! If my question isn't clear, I can try to explain it better. Don't worry for your answers, I'm better at reading than writing ;)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…