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

[BUGFIX] Fixing DAS vars resolution #729

Merged
merged 2 commits into from
Jul 5, 2024
Merged

[BUGFIX] Fixing DAS vars resolution #729

merged 2 commits into from
Jul 5, 2024

Conversation

angeloprobst
Copy link
Contributor

Rationale

While working with MeTTa and DAS Gate, I faced the following situation: the same query that works perfectly with the built-in atom space, when executed using DAS, does not resolve some variables if a function is defined and called to match some condition.
For example:

[(parent of Paul = $y#40)]
[(parent of Paul = John)]

The first line is the output of a query on DAS. And the second one comes from the same query but using the built-in space.

The issue does not happen on DAS if the match is made without calling a function.
For example, this query fails (output shows a non-resolved variable):

(= (get_parent_from_das $x) (match &das (Parent $y $x) $y))
!(parent of Paul = (get_parent_from_das Paul))

However, this match works perfectly (it shows the value):

!(match &das (Parent $y Paul) (parent of Paul = $y))

And both queries are equivalent.

Sample Script

(two first queries do not have variables properly resolved)

!(import! &self das_gate)

!(bind! &das (new-das))
!(bind! &local (new-space))

!(add-atom &das (Parent John Paul))  ; Paul is child of John
!(add-atom &das (Person Paul))

!(add-atom &local (Parent John Paul))  ; Paul is child of John
!(add-atom &local (Person Paul))

; getting parent from das using a function
(= (get_parent_from_das $x)
    (match &das (Parent $y $x) $y))
!(parent of Paul = (get_parent_from_das Paul))  ; person as a constant
!(match &das (Person $x)  ; person as a wildcard
    (parent of $x = (get_parent_from_das $x)))

; getting parent from das, inline, no function
!(match &das (Parent $y Paul) (parent of Paul = $y))  ; person as a constant
!(match &das (Person $x)  ; person as a wildcard
    (parent of $x = (match &das (Parent $y $x) $y)))

; getting parent from local using a function
(= (get_parent_from_local $x)
    (match &local (Parent $y $x) $y))
!(parent of Paul = (get_parent_from_local Paul))  ; person as a constant
!(match &local (Person $x)  ; person as a wildcard
    (parent of $x = (get_parent_from_local $x)))

; getting parent from local, inline, no function
!(match &local (Parent $y Paul) (parent of Paul = $y))  ; person as a constant
!(match &local (Person $x)  ; person as a wildcard
    (parent of $x = (match &local (Parent $y $x) $y)))

Output is:
(two first lines should show John instead of $y#40 and $y#55)

[(Parent of Paul = $y#40)]
[(Parent of Paul = $y#55)]
[(Parent of Paul = John)]
[(Parent of Paul = John)]
[(Parent of Paul = John)]
[(Parent of Paul = John)]
[(Parent of Paul = John)]
[(Parent of Paul = John)]

Vitaly's feedback on Mattermost

Issue is on the DAS gate side. Variable's identity in hyperon-experimental consists of two parts: variable name and unique id. When DAS Gate converts variables to the DAS variables it merges these two parts into the the name like y#39. But when value is returned and should be applied to the template variable in template is not converted and has name y with 39 as unique id. Thus these two variables are not matched and value is not substituted. It is not a case for the simple query where variables doesn't have unique identifier.

Copy link
Collaborator

@vsbogd vsbogd left a comment

Choose a reason for hiding this comment

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

Hi @angeloprobst, thank you for the PR. It is indeed a step in a right direction. I was thinking about similar change but in a Rust core library. Also I need to finish C API rework and remove using strings as the keys in variable bindings.

I am merging it and going to raise PR with the follow up changes soon.

@vsbogd vsbogd merged commit 4b05f05 into trueagi-io:main Jul 5, 2024
2 checks passed
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.

2 participants