nltk.grammar.ProbabilisticProduction¶
- class nltk.grammar.ProbabilisticProduction[source]¶
Bases:
Production
,ImmutableProbabilisticMixIn
A probabilistic context free grammar production. A PCFG
ProbabilisticProduction
is essentially just aProduction
that has an associated probability, which represents how likely it is that this production will be used. In particular, the probability of aProbabilisticProduction
records the likelihood that its right-hand side is the correct instantiation for any given occurrence of its left-hand side.- See
Production
- __init__(lhs, rhs, **prob)[source]¶
Construct a new
ProbabilisticProduction
.- Parameters
lhs (Nonterminal) – The left-hand side of the new
ProbabilisticProduction
.rhs (sequence(Nonterminal and terminal)) – The right-hand side of the new
ProbabilisticProduction
.prob – Probability parameters of the new
ProbabilisticProduction
.
- is_lexical()¶
Return True if the right-hand contain at least one terminal token.
- Return type
bool
- is_nonlexical()¶
Return True if the right-hand side only contains
Nonterminals
- Return type
bool
- lhs()¶
Return the left-hand side of this
Production
.- Return type
- logprob()¶
Return
log(p)
, wherep
is the probability associated with this object.- Return type
float
- prob()¶
Return the probability associated with this object.
- Return type
float
- rhs()¶
Return the right-hand side of this
Production
.- Return type
sequence(Nonterminal and terminal)
- set_logprob(prob)¶
Set the log probability associated with this object to
logprob
. I.e., set the probability associated with this object to2**(logprob)
.- Parameters
logprob (float) – The new log probability
- set_prob(prob)¶
Set the probability associated with this object to
prob
.- Parameters
prob (float) – The new probability