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

Inverse property path with optional ? does not work in some cases #2727

Closed
damyan-ognyanov opened this issue Dec 17, 2020 · 3 comments · Fixed by #2754
Closed

Inverse property path with optional ? does not work in some cases #2727

damyan-ognyanov opened this issue Dec 17, 2020 · 3 comments · Fixed by #2754
Assignees
Labels
🐞 bug issue is a bug specification issues related to compliance to standards and external specs 🛠️ tech debt code refactoring, deprecation, and other technical debt tasks
Milestone

Comments

@damyan-ognyanov
Copy link
Contributor

There is an issue with the Inverse property paths in conjunction with ? optional modifier when grouping with brackets (forced precedense) are used.

To reproduce load following data:

insert data {
    <urn:1> <urn:prop> <urn:object> .
    <urn:2> <urn:prop> <urn:mid:1> .
    <urn:mid:1> <urn:prop> <urn:object> .
    <urn:3> <urn:prop> <urn:mid:2> .
    <urn:mid:2> <urn:prop> <urn:mid:3> .
    <urn:mid:3> <urn:prop> <urn:object> .
}

This query works as expected, returning 4 results:

select * where { 
    <urn:object> ^(<urn:prop>?) ?o .
}

This query, that uses the default operator precedense, also works correctly returning 4 results

select * where { 
    <urn:object> ^<urn:prop>? ?o .
} 

This query returns correctly 3 results:

select * where { 
    <urn:object> (^<urn:prop>) ?o .
}

but when we add ? optional modifier, it is expected to return the above 3 results plus the so called self result but instead, it only return one result (self):

select * where { 
    <urn:object> (^<urn:prop>)? ?o .
}

which is unexpected.

the produced query model in the wrong case is not inversed (urn:object is on subject position and the var on object position, e.g. these are not swapped according to the ^ inverse modifier used.

Tried to find a solution/quick fix but the code around the transaltion of property paths is a bit of a mess. For simple inverse paths like the one used in the above queries the code could be patched somehow but if the path is more complex and involves either alternatives or other segments that are also inversed the number of swaps could not be deduced after the recursive step finishes converting the nested segments so it is hard to decide wheter to swap the subj/obj positions or not.

Hope this description is clear enough ...

@github-actions github-actions bot added this to 📥 Inbox in Project Progress Dec 17, 2020
@abrokenjester
Copy link
Contributor

abrokenjester commented Dec 17, 2020

Tried to find a solution/quick fix but the code around the transaltion of property paths is a bit of a mess.

I quite agree - we keep monkey-patching the code, but it really needs a good overhaul.

For simple inverse paths like the one used in the above queries the code could be patched somehow but if the path is more complex and involves either alternatives or other segments that are also inversed the number of swaps could not be deduced after the recursive step finishes converting the nested segments so it is hard to decide wheter to swap the subj/obj positions or not.

I think we should look at writing a dedicated class for handling of path expressions. Or at the very least get rid of the awful if-else constructions in visit(PathSequence) and handle things properly.

@barthanssens barthanssens added specification issues related to compliance to standards and external specs 🐞 bug issue is a bug 🛠️ tech debt code refactoring, deprecation, and other technical debt tasks labels Dec 23, 2020
@VladimirAlexiev
Copy link

Original issue: https://ontotext.atlassian.net/browse/GDB-4650, where we have a more complex case of collecting VIAF names with a more complex path like this
(^foaf:focus?)/(schema:name|skos:prefLabel|skos:altLabel|schema:alternateName)

@abrokenjester abrokenjester moved this from 📥 Inbox to 📋 Backlog in Project Progress Jan 6, 2021
@abrokenjester
Copy link
Contributor

I'm doing a little spiking on this in my spare time, to see if I can come up with a refactor that makes sense.

@abrokenjester abrokenjester self-assigned this Jan 10, 2021
@abrokenjester abrokenjester moved this from 📋 Backlog to 🚧 In progress in Project Progress Jan 10, 2021
@abrokenjester abrokenjester added this to the 3.5.1 milestone Jan 10, 2021
abrokenjester added a commit that referenced this issue Jan 10, 2021
- drastically simplified path modifier handling, as a lot of the logic
   was legacy from the old (now unsupported) prop{min,max} syntax
abrokenjester added a commit that referenced this issue Jan 10, 2021
- drastically simplified path modifier handling, as a lot of the logic
   was legacy from the old (now unsupported) prop{min,max} syntax
abrokenjester added a commit that referenced this issue Jan 10, 2021
As far as I can see the actual output is correct
abrokenjester added a commit that referenced this issue Jan 10, 2021
As far as I can see the actual output is correct
Project Progress automation moved this from 🚧 In progress to 🥳 Done Jan 12, 2021
abrokenjester added a commit that referenced this issue Jan 12, 2021
GH-2727 simplified path expression processing and fixed nested inverse optional handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug issue is a bug specification issues related to compliance to standards and external specs 🛠️ tech debt code refactoring, deprecation, and other technical debt tasks
Projects
No open projects
4 participants