Skip to content

Commit

Permalink
Added Symbol support
Browse files Browse the repository at this point in the history
  • Loading branch information
LoLo5689 authored Nov 25, 2024
1 parent 4c13d57 commit 0c76903
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/rulenode_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,29 @@ function expr2rulenode(expr::Expr, grammar::AbstractGrammar)
return rn
end

function expr2rulenode(expr::Symbol, grammar::AbstractGrammar, startSymbol::Symbol)
tags = get_tags(grammar)
(s, rn) = expr2rulenode(expr, grammar, tags)
while s != startSymbol

Check warning on line 347 in src/rulenode_operators.jl

View check run for this annotation

Codecov / codecov/patch

src/rulenode_operators.jl#L344-L347

Added lines #L344 - L347 were not covered by tests

updatedrule = findfirst(==(s), grammar.rules)

Check warning on line 349 in src/rulenode_operators.jl

View check run for this annotation

Codecov / codecov/patch

src/rulenode_operators.jl#L349

Added line #L349 was not covered by tests

if isnothing(updatedrule)
error("INVALID STARTING SYMBOL")

Check warning on line 352 in src/rulenode_operators.jl

View check run for this annotation

Codecov / codecov/patch

src/rulenode_operators.jl#L351-L352

Added lines #L351 - L352 were not covered by tests
end

s = tags[s]
rn = RuleNode(updatedrule, [rn])
end
return rn

Check warning on line 358 in src/rulenode_operators.jl

View check run for this annotation

Codecov / codecov/patch

src/rulenode_operators.jl#L355-L358

Added lines #L355 - L358 were not covered by tests
end

function expr2rulenode(expr::Symbol, grammar::AbstractGrammar)
tags = get_tags(grammar)
(s, rn) = expr2rulenode(expr, grammar, tags)
return rn

Check warning on line 364 in src/rulenode_operators.jl

View check run for this annotation

Codecov / codecov/patch

src/rulenode_operators.jl#L361-L364

Added lines #L361 - L364 were not covered by tests
end

"""
Calculates the log probability associated with a rulenode in a probabilistic grammar.
"""
Expand Down

0 comments on commit 0c76903

Please sign in to comment.