|
32 | 32 | from collections import namedtuple |
33 | 33 |
|
34 | 34 |
|
35 | | -class ScoredAnalysis(namedtuple('ScoredAnalysis', ['score', 'analysis'])): |
| 35 | +class ScoredAnalysis(namedtuple('ScoredAnalysis', |
| 36 | + [ |
| 37 | + 'score', |
| 38 | + 'analysis', |
| 39 | + 'diac', |
| 40 | + 'pos_lex_logprob', |
| 41 | + 'lex_logprob' |
| 42 | + ])): |
36 | 43 | """A named tuple containing an analysis and its score. |
37 | 44 |
|
38 | 45 | Attributes: |
39 | | - score (:obj:`float`): The score of a given analysis. |
| 46 | + score (:obj:`float`): The overall score of the analysis. |
40 | 47 |
|
41 | 48 | analysis (:obj:`dict`): The analysis dictionary. |
42 | | - See :doc:`/reference/camel_morphology_features` for more information on |
43 | | - features and their values. |
| 49 | + See :doc:`/reference/camel_morphology_features` for more |
| 50 | + information on features and their values. |
| 51 | +
|
| 52 | + diac (:obj:`str`): The diactrized form of the associated analysis. |
| 53 | + Used for tie-breaking equally scored analyses. |
| 54 | +
|
| 55 | + pos_lex_log_prob (:obj:`float`): The log (base 10) of the probability |
| 56 | + of the associated pos-lex pair values. |
| 57 | + Used for tie-breaking equally scored analyses. |
| 58 | +
|
| 59 | + lex_log_prob (:obj:`float`): The log (base 10) of the probability of |
| 60 | + the associated lex value. |
| 61 | + Used for tie-breaking equally scored analyses. |
44 | 62 | """ |
45 | 63 |
|
| 64 | + def __lt__(self, other): |
| 65 | + if self.score > other.score: |
| 66 | + return True |
| 67 | + elif self.score == other.score: |
| 68 | + if self.pos_lex_logprob > other.pos_lex_logprob: |
| 69 | + return True |
| 70 | + elif self.pos_lex_logprob == other.pos_lex_logprob: |
| 71 | + if self.lex_logprob > other.lex_logprob: |
| 72 | + return True |
| 73 | + elif self.lex_logprob == other.lex_logprob: |
| 74 | + return self.diac < other.diac |
| 75 | + |
| 76 | + return False |
| 77 | + |
46 | 78 |
|
47 | 79 | class DisambiguatedWord(namedtuple('DisambiguatedWord', ['word', 'analyses'])): |
48 | 80 | """A named tuple containing a word and a sorted list (from high to low |
|
0 commit comments