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

Fix PCSG handling #104

Merged
merged 9 commits into from
Feb 26, 2025
14 changes: 14 additions & 0 deletions src/grammar_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@
return grammar.log_probabilities[index]
end


"""
make_probabilistic!(grammar::AbstractGrammar)

If the grammar is not probabilistic yet, initializes the grammar with uniform probabilities per type. If the grammar is alread probabilistic, no changed are made.
"""
function make_probabilistic!(grammar::AbstractGrammar)
if isprobabilistic(grammar)
@warn "Grammar is already probabilistic. The grammar will not be changed."

Check warning on line 151 in src/grammar_base.jl

View check run for this annotation

Codecov / codecov/patch

src/grammar_base.jl#L149-L151

Added lines #L149 - L151 were not covered by tests
else
grammar.log_probabilities = [log(1 / length(grammar.bytype[grammar.types[index]])) for index in 1:length(grammar.rules)]

Check warning on line 153 in src/grammar_base.jl

View check run for this annotation

Codecov / codecov/patch

src/grammar_base.jl#L153

Added line #L153 was not covered by tests
end
end

"""
probability(grammar::AbstractGrammar, index::Int)::Real

Expand Down