Skip to content

Commit

Permalink
fixed #25, preserve dict order in evaluation output
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmaat committed Mar 7, 2018
1 parent 7f018b5 commit 8560395
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions wordseg/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import codecs
import collections

from wordseg import utils
from wordseg.separator import Separator
Expand Down Expand Up @@ -206,17 +207,19 @@ def evaluate(text, gold, separator=_DEFAULT_SEPARATOR):
_stringpos_boundarypos(text_stringpos),
_stringpos_boundarypos(gold_stringpos))

return {
'token_precision': token_eval.precision(),
'token_recall': token_eval.recall(),
'token_fscore': token_eval.fscore(),
'type_precision': type_eval.precision(),
'type_recall': type_eval.recall(),
'type_fscore': type_eval.fscore(),
'boundary_precision': boundary_eval.precision(),
'boundary_recall': boundary_eval.recall(),
'boundary_fscore': boundary_eval.fscore()
}
# return the scores in a fixed order (the default dict does not
# repect insertion order). This is needed for python<3.6, see
# https://docs.python.org/3.6/whatsnew/3.6.html#new-dict-implementation
return collections.OrderedDict((k, v) for k, v in (
('token_precision', token_eval.precision()),
('token_recall', token_eval.recall()),
('token_fscore', token_eval.fscore()),
('type_precision', type_eval.precision()),
('type_recall', type_eval.recall()),
('type_fscore', type_eval.fscore()),
('boundary_precision', boundary_eval.precision()),
('boundary_recall', boundary_eval.recall()),
('boundary_fscore', boundary_eval.fscore())))


def _load_text(text):
Expand Down

0 comments on commit 8560395

Please sign in to comment.