Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FILTER (lang(…) = …) for predicate paths #276 #277

Merged
merged 2 commits into from Nov 12, 2019
Merged

Fix FILTER (lang(…) = …) for predicate paths #276 #277

merged 2 commits into from Nov 12, 2019

Conversation

niklas88
Copy link
Member

@niklas88 niklas88 commented Aug 21, 2019

Improve FILTER (lang(… for predicate paths #276

We were trying to use language tagged predicates on predicate paths.
Instead if the predicate path isn't simple we have to fallback on using
language predicates on the literal variable.

This change also means that if a predicate path mixes predicates with
literal subjects and non-literal subjects we only get the literals when
FILTER (lang(?var) = "…") is used.

The spec at https://www.w3.org/TR/sparql11-query/#func-lang

doesn't make it clear what should happen when applied to a non-literal.
Our behaviour matches the Wikidata Query Service though.

We were trying to use language tagged predicates on predicate paths.
Instead if the predicate path isn't simple we have to fallback on using
language predicates on the literal variable.

This change also means that if a predicate path mixes predicates with
literal subjects and non-literal subjects we only get the literals when
FILTER (lang(?var) = "…") is used.

The spec at

https://www.w3.org/TR/sparql11-query/#func-lang

doesn't make it clear what should happen when applied to a non-literal.
Our behaviour matches the Wikidata Query Service though.
@niklas88
Copy link
Member Author

The following is an example query for the behavior with mixed literal and non-literal subjects:

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?alias WHERE {
  wd:Q567 skos:altLabel|rdfs:label|wdt:P106 ?alias .
  FILTER (lang(?alias) = "en")
} 

removing the language FILTER mixes them while using the FILTER restricts to literal results. The same happens for the Wikidata Query Service.

@niklas88
Copy link
Member Author

@floriankramer can you take a look, otherwise I'll just merge as trivial change

Copy link
Member

@lehmann-4178656ch lehmann-4178656ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor wording stuff, can't say much about the code itself.

it = std::find_if(it + 1, pattern->_whereClauseTriples.end(),
[&lhs](const auto& tr) { return tr._o == lhs; });
}
// First find a suitabke triple for the given variable. It
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo suitabke -> suitable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find

src/parser/SparqlParser.cpp Show resolved Hide resolved
@niklas88 niklas88 closed this Oct 1, 2019
@niklas88 niklas88 deleted the fix_prop_path_langfilter branch October 1, 2019 15:52
@niklas88 niklas88 restored the fix_prop_path_langfilter branch October 1, 2019 15:53
@niklas88 niklas88 reopened this Oct 1, 2019
@niklas88
Copy link
Member Author

@lehmann-4178656ch can you give this an ACK, I'd like to merge it and it seems neither @floriankramer nor @joka921 are coming around to a proper review.

Copy link
Member

@lehmann-4178656ch lehmann-4178656ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM without running extensive tests.

@niklas88 niklas88 merged commit 51501b5 into ad-freiburg:master Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants