Skip to content

Commit

Permalink
Issue nltk#1859: Add method definition for abstract method max in Ran…
Browse files Browse the repository at this point in the history
…domProbDist and MutableProbDist
  • Loading branch information
PavanGJ committed Oct 25, 2017
1 parent 0c7e43f commit 318b94c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions AUTHORS.md
@@ -1,4 +1,4 @@
# Natural Language Toolkit (NLTK) Authors
# Natural Language Toolkit (NLTK) Authors

## Original Authors

Expand Down Expand Up @@ -223,6 +223,7 @@
- Stoytcho Stoytchev
- Lakhdar Benzahia
- Oleg Chislov
- Pavan Gururaj Joshi <https://github.com/PavanGJ>

## Others whose work we've taken and included in NLTK, but who didn't directly contribute it:
### Contributors to the Porter Stemmer
Expand All @@ -239,4 +240,4 @@
### Authors of snowball arabic stemmer algorithm
- Assem Chelli
- Abdelkrim Aries
- Lakhdar Benzahia
- Lakhdar Benzahia
9 changes: 9 additions & 0 deletions nltk/probability.py
Expand Up @@ -603,6 +603,11 @@ def unirand(cls, samples):

return dict((s, randrow[i]) for i, s in enumerate(samples))

def max(self):
if not hasattr(self, '_max'):
self._max = max((p,v) for (v,p) in self._probs.items())[1]
return self._max

def prob(self, sample):
return self._probs.get(sample, 0)

Expand Down Expand Up @@ -1522,6 +1527,10 @@ def __init__(self, prob_dist, samples, store_logs=True):
self._data[i] = prob_dist.prob(samples[i])
self._logs = store_logs

def max(self):
# inherit documentation
return max((p,v) for (v,p) in self._sample_dict.items())[1]

def samples(self):
# inherit documentation
return self._samples
Expand Down

0 comments on commit 318b94c

Please sign in to comment.