Skip to content

Commit

Permalink
Merge pull request #18 from Herb-AI/dev
Browse files Browse the repository at this point in the history
Grammar -> AbstractGrammar according to HerbCore 0.2, HerbGrammar -> 0.2
  • Loading branch information
THinnerichs authored Feb 29, 2024
2 parents 1db3fe5 + 2ef2421 commit 15b6a8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name = "HerbInterpret"
uuid = "5bbddadd-02c5-4713-84b8-97364418cca7"
authors = ["Tilman Hinnerichs <[email protected]>", "Jaap de Jong <[email protected]>", "Sebastijan Dumancic <[email protected]>", "Reuben Gardos Reid <[email protected]>"]
version = "0.1.1"
version = "0.1.2"

[deps]
HerbCore = "2b23ba43-8213-43cb-b5ea-38c12b45bd45"
HerbGrammar = "4ef9e186-2fe5-4b24-8de7-9f7291f24af7"
HerbSpecification = "6d54aada-062f-46d8-85cf-a1ceaf058a06"

[compat]
HerbCore = "0.1.1"
HerbGrammar = "0.1.0"
HerbSpecification = "0.1.0"
julia = "1.8"
HerbCore = "^0.2.0"
HerbGrammar = "^0.2.0"
HerbSpecification = "^0.1.0"
julia = "^1.8"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
16 changes: 8 additions & 8 deletions src/interpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,50 +89,50 @@ function execute_on_input(tab::SymbolTable, expr::Any, input::Vector{T})::Vector
end

"""
execute_on_input(grammar::Grammar, program::RuleNode, input::Dict{Symbol, T})::Any where T
execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Dict{Symbol, T})::Any where T
Converts a `RuleNode` program into an expression using a given `grammar`, then evaluates this expression with a single input dictionary `input` and a symbol table derived from the `grammar` using [`execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T})`](@ref).
# Arguments
- `grammar::Grammar`: A grammar object used to convert the `RuleNode` into an executable expression.
- `grammar::AbstractGrammar`: A grammar object used to convert the `RuleNode` into an executable expression.
- `program::RuleNode`: The program, represented as a `RuleNode`, to be converted and evaluated.
- `input::Dict{Symbol, T}`: A dictionary providing input values for symbols used in the generated expression.
# Returns
- `Any`: The result of evaluating the generated expression with the given input dictionary.
"""
function execute_on_input(grammar::Grammar, program::RuleNode, input::Dict{Symbol, T})::Any where T
function execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Dict{Symbol, T})::Any where T
expression = rulenode2expr(program, grammar)
symboltable = SymbolTable(grammar)
return execute_on_input(symboltable, expression, input)
end

"""
execute_on_input(grammar::Grammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any}
execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any}
Converts a `RuleNode` program into an expression using a given `grammar`, then evaluates this expression for each input dictionary in a vector `input` and a symbol table derived from the `grammar` using [`execute_on_input(tab::SymbolTable, expr::Any, input::Dict{Symbol, T})`](@ref).
# Arguments
- `grammar::Grammar`: A grammar object used to convert the `RuleNode` into an executable expression.
- `grammar::AbstractGrammar`: A grammar object used to convert the `RuleNode` into an executable expression.
- `program::RuleNode`: The program, represented as a `RuleNode`, to be converted and evaluated.
- `input::Vector{T}`: A vector of dictionaries, each providing input values for symbols used in the generated expression.
# Returns
- `Vector{Any}`: A vector containing the results of evaluating the generated expression for each input dictionary.
"""
function execute_on_input(grammar::Grammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any}
function execute_on_input(grammar::AbstractGrammar, program::RuleNode, input::Vector{T})::Vector{Any} where T <: Dict{Symbol, <:Any}
expression = rulenode2expr(program, grammar)
symboltable = SymbolTable(grammar)
return execute_on_input(symboltable, expression, input)
end


"""
evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::Grammar, evaluation_function::Function)
evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::AbstractGrammar, evaluation_function::Function)
Runs a program on the examples and returns tuples of actual desired output and the program's output
"""
function evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::Grammar, evaluation_function::Function)
function evaluate_program(program::RuleNode, examples::Vector{<:IOExample}, grammar::AbstractGrammar, evaluation_function::Function)
depwarn("`evaluate_program` is deprecated and should no longer be used. Please use HerbSearch.evaluate instead.", :evaluate_program)

results = Tuple{<:Number,<:Number}[]
Expand Down
2 changes: 1 addition & 1 deletion test/test_execute_on_input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ end
end
end

@testset "With Grammar and RuleNode" begin
@testset "With grammar and RuleNode" begin
grammar = create_dummy_grammar() # integer arithmetic
program = create_dummy_rulenode() # :(1+x)

Expand Down

2 comments on commit 15b6a8e

@THinnerichs
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

Release notes:

This path includes

  • update of dependencies
  • Grammar -> AbstractGrammar

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/101989

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.2 -m "<description of version>" 15b6a8e4f86fe876f277f6475944a0f1d3e72e04
git push origin v0.1.2

Please sign in to comment.