dsp-api
dsp-api copied to clipboard
Gravsearch: unify user provided value literal variables with generated statement
The input query
PREFIX anything: <http://0.0.0.0:3333/ontology/0001/anything/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
CONSTRUCT {
?thing knora-api:isMainResource true .
?thing anything:hasDecimal ?decimal .
} WHERE {
?thing a anything:Thing .
?thing a knora-api:Resource .
OPTIONAL {
?thing anything:hasDecimal ?decimal .
?decimal knora-api:decimalValueAsDecimal ?decimalVal .
FILTER(?decimalVal > "2"^^xsd:decimal)
}
} ORDER BY ASC(?decimal)
gets converted to the prequery
SELECT DISTINCT ?thing (GROUP_CONCAT(DISTINCT(?decimal); SEPARATOR='') AS ?decimal__Concat)
WHERE {
?thing <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/knora-base#Resource> .
GRAPH <http://www.knora.org/explicit> {
?thing <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
}
?thing <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.knora.org/ontology/0001/anything#Thing> .
OPTIONAL {
?thing <http://www.knora.org/ontology/0001/anything#hasDecimal> ?decimal .
GRAPH <http://www.knora.org/explicit> {
?decimal <http://www.knora.org/ontology/knora-base#isDeleted> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
}
GRAPH <http://www.knora.org/explicit> {
?decimal <http://www.knora.org/ontology/knora-base#valueHasDecimal> ?decimal__valueHasDecimal .
}
?decimal <http://www.knora.org/ontology/knora-base#valueHasDecimal> ?decimalVal .
FILTER((?decimalVal > "2"^^<http://www.w3.org/2001/XMLSchema#decimal>))
}
}
GROUP BY ?thing ?decimal__valueHasDecimal
ORDER BY ASC(?decimal__valueHasDecimal) ASC(?thing)
LIMIT 25
Unify ?decimal <http://www.knora.org/ontology/knora-base#valueHasDecimal> ?decimalVal . and ?decimal <http://www.knora.org/ontology/knora-base#valueHasDecimal> ?decimal__valueHasDecimal
I think this is not a bug but redundancy.
I don't think it's possible to for us to use the variable in the input query, because it could exist only in one block (an OPTIONAL). What if the user writes this?
PREFIX anything: <http://0.0.0.0:3333/ontology/0001/anything/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
CONSTRUCT {
?thing knora-api:isMainResource true .
?thing anything:hasDecimal ?decimal .
} WHERE {
?thing a anything:Thing .
?thing a knora-api:Resource .
?thing anything:hasDecimal ?decimal .
OPTIONAL {
?decimal knora-api:decimalValueAsDecimal ?decimalVal1 .
FILTER(?decimalVal1 < "3"^^xsd:decimal)
}
OPTIONAL {
?decimal knora-api:decimalValueAsDecimal ?decimalVal2 .
FILTER(?decimalVal2 > "5"^^xsd:decimal)
}
} ORDER BY ASC(?decimal)
Here we would have to generate our own variable anyway.
I don't think having redundant variables is a problem for the triplestore. The query works, right?
Yes, the query works. See: https://github.com/dhlab-basel/Knora/pull/1178/commits/e84f4a2ce9b71abece68040c989f8a4cb8da67dd
OK, so I think this isn't a bug.
I still think we should have a look at this. Maybe we should disallow property values as sort criteria that have a cardinality other than 1 or max 1.