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

Feature/552 eval constant terms #564

Merged
merged 2 commits into from
Jan 7, 2025
Merged

Conversation

aannleax
Copy link
Member

@aannleax aannleax commented Dec 9, 2024

Adds the function reduce to all Terms in the rule model, which simplifies constant expressions within Operations. This is accomplished by translating the term and running a StackProgram ensuring that the result matches what would happen during rule evaluation.

Closes #552.

@mmarx mmarx added enhancement New feature or request builtins Issue related to built-in functions labels Jan 6, 2025
@mmarx mmarx added this to the Release 0.7.0 milestone Jan 6, 2025
@aannleax aannleax merged commit 4a892be into main Jan 7, 2025
8 checks passed
@aannleax aannleax deleted the feature/552-eval-constant-terms branch January 7, 2025 10:23
matzemathics added a commit that referenced this pull request Jan 8, 2025
Addresses #569. Based on #564 and #566, so should be merged after those.

With this, we can run the following program:
```prolog
@import awards :- tsv{ resource=f"https://query.wikidata.org/sparql?query={URIENCODE(?query)}",
                       format=(any, string)
                     },
               ?query = """
    SELECT ?award ?awardLabel WHERE {
      wd:Q42 wdt:P166 ?award .
      ?award rdfs:label ?awardLabel FILTER(LANG(?awardLabel) = "en")
    }
    """.

@export awards :- csv{resource=""} .
```

This currently yields the following output:
```
[2025-01-04T00:15:11Z INFO  nemo::io::formats::dsv::writer] Starting data export
?award,"""?awardLabel"""
http://www.wikidata.org/entity/Q906455,"""Ditmar Award@en"""
http://www.wikidata.org/entity/Q2687578,"""Inkpot Award@en"""
[2025-01-04T00:15:11Z INFO  nemo::io::formats::dsv::writer] Finished export: processed 3 tuples (dropped 0)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins Issue related to built-in functions enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Rule model should allow evaluating constant expressions
2 participants