Commit 5f9178cd by Steven Bird

Fixed issue with printing production probabilities: all were being reduced to…

Fixed issue with printing production probabilities: all were being reduced to one significant digit; documentation wrongly specified 1.0 to display as 1.
parent b4693ad2
...@@ -399,7 +399,7 @@ class ProbabilisticProduction(Production, ImmutableProbabilisticMixIn): ...@@ -399,7 +399,7 @@ class ProbabilisticProduction(Production, ImmutableProbabilisticMixIn):
def __str__(self): def __str__(self):
return Production.__unicode__(self) + \ return Production.__unicode__(self) + \
(' [1.0]' if (self.prob() == 1.0) else ' [%.g]' % self.prob()) (' [1.0]' if (self.prob() == 1.0) else ' [%g]' % self.prob())
def __eq__(self, other): def __eq__(self, other):
return (type(self) == type(other) and return (type(self) == type(other) and
......
...@@ -556,7 +556,7 @@ Create a set of PCFG productions. ...@@ -556,7 +556,7 @@ Create a set of PCFG productions.
A A
>>> grammar.productions() >>> grammar.productions()
[A -> B B [0.3], A -> C B C [0.7], B -> B D [0.5], B -> C [0.5], C -> 'a' [0.1], C -> 'b' [0.9], D -> 'b' [1]] [A -> B B [0.3], A -> C B C [0.7], B -> B D [0.5], B -> C [0.5], C -> 'a' [0.1], C -> 'b' [0.9], D -> 'b' [1.0]]
Induce some productions using parsed Treebank data. Induce some productions using parsed Treebank data.
...@@ -570,7 +570,7 @@ Induce some productions using parsed Treebank data. ...@@ -570,7 +570,7 @@ Induce some productions using parsed Treebank data.
<Grammar with 71 productions> <Grammar with 71 productions>
>>> sorted(grammar.productions(lhs=Nonterminal('PP')))[:2] >>> sorted(grammar.productions(lhs=Nonterminal('PP')))[:2]
[PP -> IN NP [1]] [PP -> IN NP [1.0]]
>>> sorted(grammar.productions(lhs=Nonterminal('NNP')))[:2] >>> sorted(grammar.productions(lhs=Nonterminal('NNP')))[:2]
[NNP -> 'Agnew' [0.0714286], NNP -> 'Consolidated' [0.0714286]] [NNP -> 'Agnew' [0.0714286], NNP -> 'Consolidated' [0.0714286]]
>>> sorted(grammar.productions(lhs=Nonterminal('JJ')))[:2] >>> sorted(grammar.productions(lhs=Nonterminal('JJ')))[:2]
...@@ -585,14 +585,14 @@ Unit tests for the Probabilistic Chart Parse classes ...@@ -585,14 +585,14 @@ Unit tests for the Probabilistic Chart Parse classes
>>> grammar = toy_pcfg2 >>> grammar = toy_pcfg2
>>> print(grammar) >>> print(grammar)
Grammar with 23 productions (start state = S) Grammar with 23 productions (start state = S)
S -> NP VP [1] S -> NP VP [1.0]
VP -> V NP [0.59] VP -> V NP [0.59]
VP -> V [0.4] VP -> V [0.4]
VP -> VP PP [0.01] VP -> VP PP [0.01]
NP -> Det N [0.41] NP -> Det N [0.41]
NP -> Name [0.28] NP -> Name [0.28]
NP -> NP PP [0.31] NP -> NP PP [0.31]
PP -> P NP [1] PP -> P NP [1.0]
V -> 'saw' [0.21] V -> 'saw' [0.21]
V -> 'ate' [0.51] V -> 'ate' [0.51]
V -> 'ran' [0.28] V -> 'ran' [0.28]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment