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

Add support for prefixes #530

Merged
merged 4 commits into from Jan 3, 2022
Merged

Conversation

RobinTF
Copy link
Collaborator

@RobinTF RobinTF commented Jan 3, 2022

Fixes a bug that was mentioned in #528 (comment)
Prefix IRIs were not parsed correctly

@hannahbast
Copy link
Member

@RobinTF Thanks, Robin, the following command, which failed so far, now works with this PR.

curl -Gs -H "Accept: text/turtle" https://qlever.informatik.uni-freiburg.de/api/olympics --data-urlencode "query=PREFIX olympics: <http://wallscope.co.uk/ontology/olympics/> CONSTRUCT { ?s olympics:medal ?o } WHERE { ?s olympics:medal ?o }"

Copy link
Member

@hannahbast hannahbast left a comment

Choose a reason for hiding this comment

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

Thanks for this PR, three questions in the code

@@ -1172,7 +1172,7 @@ class SparqlQleverVisitor : public SparqlAutomaticVisitor {
SparqlAutomaticParser::PnameLnContext* ctx) override {
string text = ctx->getText();
auto pos = text.find(':');
auto pnameNS = text.substr(0, pos + 1);
auto pnameNS = text.substr(0, pos);
Copy link
Member

Choose a reason for hiding this comment

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

Was this a bug already before or is this specific for the CONSTRUCT clause?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wouldn't consider it a bug, but rather an implementation specific oddity.
Basically the prefix map was storing the trailing colon : along with the prefix name, but the non-antlr parser already stripped those colons from the prefix.
That's why previously the hash-map mapped key: to value instead of key to value and probably also the reason why the tests are currently failing

Comment on lines +1192 to +1193
auto text = ctx->getText();
auto prefix = text.substr(0, text.length() - 1);
Copy link
Member

Choose a reason for hiding this comment

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

Same question as before.

Comment on lines +45 to +50
SparqlQleverVisitor::PrefixMap prefixes;
for (const auto& prefix : query->_prefixes) {
prefixes[prefix._prefix] = prefix._uri;
}
auto parseResult =
sparqlParserHelpers::parseConstructTemplate(str, std::move(prefixes));
Copy link
Member

Choose a reason for hiding this comment

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

Are the prefixes now parsed twice (for the CONSTRUCT clause and the WHERE clause)? I am asking because prefixes did work already for the WHERE clause.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are not, the weirdness comes from the parser-duality that currently exists within the codebase.
Basically the existing parser (the non-antlr) version currently parses all the prefixes, but the parsing of the construct clause is done using antlr (which requires the parsed prefixes being passed here), which then delegates back to the original parser to parse the where clause

@joka921 joka921 merged commit 4c16ab5 into ad-freiburg:master Jan 3, 2022
@RobinTF RobinTF deleted the support-prefix branch January 3, 2022 17:39
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

3 participants