From 0c76903069bdf5fa53419ef2e52cd6458d4c6d45 Mon Sep 17 00:00:00 2001 From: Lorenzo <19820958+LoLo5689@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:25:31 +0100 Subject: [PATCH] Added Symbol support --- src/rulenode_operators.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/rulenode_operators.jl b/src/rulenode_operators.jl index 06bee99..d4fc378 100644 --- a/src/rulenode_operators.jl +++ b/src/rulenode_operators.jl @@ -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 + + updatedrule = findfirst(==(s), grammar.rules) + + if isnothing(updatedrule) + error("INVALID STARTING SYMBOL") + end + + s = tags[s] + rn = RuleNode(updatedrule, [rn]) + end + return rn +end + +function expr2rulenode(expr::Symbol, grammar::AbstractGrammar) + tags = get_tags(grammar) + (s, rn) = expr2rulenode(expr, grammar, tags) + return rn +end + """ Calculates the log probability associated with a rulenode in a probabilistic grammar. """