Skip to content

[#212] Integration of new CHAIN operator in tokens-based query#1055

Merged
andre-senna merged 10 commits intomasterfrom
senna-212-2
Apr 9, 2026
Merged

[#212] Integration of new CHAIN operator in tokens-based query#1055
andre-senna merged 10 commits intomasterfrom
senna-212-2

Conversation

@andre-senna
Copy link
Copy Markdown
Contributor

@andre-senna andre-senna commented Mar 10, 2026

WIP towards #212 Still missing integration with MeTTa queries

After this PR, it's possible to include CHAIN operators in token based queries like these:

        "CHAIN", "0", "1", "2",
            "NODE", "Symbol", "\"chimp\"",
            "NODE", "Symbol", "\"ent\"",
            "LINK_TEMPLATE", "Expression", "3",
                "NODE", "Symbol", "Similarity",
                "VARIABLE", "v1",
                "VARIABLE", "v2",
        "CHAIN", "0", "1", "2",
            "NODE", "Symbol", "\"ent\"",
            "NODE", "Symbol", "\"animal\"",
            "OR", "2",
                "LINK_TEMPLATE", "Expression", "3",
                    "NODE", "Symbol", "Similarity",
                    "VARIABLE", "v1",
                    "VARIABLE", "v2",
                "LINK_TEMPLATE", "Expression", "3",
                    "NODE", "Symbol", "Inheritance",
                    "VARIABLE", "v1",
                    "VARIABLE", "v2",

The syntax of the tokens is like this:

        "CHAIN", <handle>, <tail>, <head>,
            <source>,
            <target>,
            <query>

Where <handle>, <tail> and <head> specify which link from <query>'s query answers should be considered to build the paths and which target indexes should be considered as tail and head of the link in the path.

<handle> can be an uint, meaning one of the handles in query_answer.handles or a string meaning the name of a variable in query_answer.mapping. <tail> and <head> are uints indexing the given link targets.

So, for instance, "CHAIN", "0", "1", "2", is saying that for each query answer of <query> the operator will consider the 0'th handle in query_answer.handle (i.e. the first handle) as the link which will build the paths and the targets 1 and 2 will be used as tail and head respectively.

In the first example, the operator will take links like (Similarity h1 h2), (Similarity h2 h3), (Similarity h3 h4) to build paths like: h1 -> h2 -> h3 -> h4 (i.e. (h1, h2), (h2, h3), (h3, h4)).

@andre-senna andre-senna changed the title [#212] Integration of new CHAIN operator in tokens-bases query [#212] Integration of new CHAIN operator in tokens-based query Apr 8, 2026
@andre-senna andre-senna merged commit 3c55bc8 into master Apr 9, 2026
2 checks passed
@andre-senna andre-senna deleted the senna-212-2 branch April 9, 2026 20:02
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