diff --git a/scripts/conll18_ud_eval.py b/scripts/conll18_ud_eval.py index ee553acdac36d0a1f68b700764a6b5d0ae3b09ed..371cbc1f2a2e0b8947edc645909e4c2aa134c275 100755 --- a/scripts/conll18_ud_eval.py +++ b/scripts/conll18_ud_eval.py @@ -146,10 +146,10 @@ UNIVERSAL_FEATURES = { def is_float(value) : if not isinstance(value, str) : return False - try: + try : float(value) - return '.' in value - except ValueError: + return True + except ValueError : return False ################################################################################ @@ -165,14 +165,12 @@ def filter_columns(columns) : return res ################################################################################ - ################################################################################ # UD Error is used when raising exceptions in this module class UDError(Exception) : pass ################################################################################ - ################################################################################ # Conversion methods handling `str` <-> `unicode` conversions in Python2 def _decode(text) : @@ -435,8 +433,9 @@ def evaluate(gold_ud, system_ud, extraColumns) : if filter_fn is None or filter_fn(words.gold_word) : goldItem = key_fn(words.gold_word, gold_aligned_gold) systemItem = key_fn(words.system_word, gold_aligned_system) - if (not isinstance(systemItem, str) or '.' not in systemItem or not is_float(systemItem)) or (not isinstance(goldItem, str) or '.' not in goldItem or not is_float(goldItem)) : + if (not is_float(systemItem)) or (not is_float(goldItem)) : isNumericOnly = False + break correct = [0,0] errors = [] @@ -451,8 +450,7 @@ def evaluate(gold_ud, system_ud, extraColumns) : correct[0] += 1 else : errors.append(words) - # WARNING: this script ignore examples where gold value == 0.0 - elif float(goldItem) != 0.0 : + else : correct[0] -= abs(float(goldItem) - float(systemItem))**1 correct[1] -= abs(float(goldItem) - float(systemItem))**2 goldValues.append(float(goldItem))