Page MenuHomePhabricator

SMW 1.6.1 with SMWSparqlStore: Erroneous SPARQL for property value comparison queries
Closed, ResolvedPublic

Description

Author: matt.voysey

Description:
Using SMW 1.6.1 and SMWSparqlStore to use external triple store (TDB via Fuseki). A semantic query of the form:

{{#ask: [[Age::<75]] }}

Generates the following SPARQL query (namespace prefixes omitted):

SELECT DISTINCT ?result WHERE {
?result swivt:wikiPageSortKey ?resultsk .
?result property:Age ?v1 .
{ FILTER ( ?v1 <= "75"^^xsd:double )
}
}
ORDER BY ASC(?resultsk)
OFFSET 0
LIMIT 51

The above returns no results, because the FILTER is placed in a different group to the query - see the SPARQL Query Spec section "5.2.2 Scope of Filters" (http://www.w3.org/TR/rdf-sparql-query/#scopeFilters). Indeed, testing the same form of query using dbpedia's Virtuoso SPARQL server yields the error "Virtuoso 37000 Error SP031: SPARQL compiler: Variable 'v1' is used in subexpressions of the query but not assigned". I'm not sure it's valid SPARQL to filter within a graph with no variables.

The same problem also causes Special:SearchByProperty to not return any "nearby values" results for numeric properties.

I traced the source of this rogue nested group to SMW_SparqlStoreQueryEngine buildPropertyCondition method, around line 713:

$innerConditionString = $innerCondition->getCondition() . $innerCondition->getWeakConditionString();

if ( $innerConditionString != '' ) {
  $condition .= "{ $innerConditionString}\n" ;
}

Removing the '{' and '}' characters from the above fixes the problems and the queries then work OK, but I'm not sure whether it will break anything else.


Version: unspecified
Severity: normal

Details

Reference
bz30993
ReferenceSource BranchDest BranchAuthorTitle
repos/releng/gitlab-settings!17gitlab-switchovermainjeltoupdate settings files for 2023 switchover eqiad -> codfw
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 21 2014, 11:51 PM
bzimport set Reference to bz30993.
bzimport added a subscriber: Unknown Object (MLST).

Fixed in r111235. The braces are now only placed if not a filter.