{"record":{"id":"cbac4f04623e1bfe","repo":"hankcs/HanLP","slug":"failed-to-parse-results-from-smatch-line","errorCode":null,"errorMessage":"Failed to parse results from smatch: {line}","messagePattern":"Failed to parse results from smatch: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hanlp/metrics/amr/smatch_eval.py","lineNumber":82,"sourceCode":"    # Non_sense_frames -> P: 0.008, R: 0.008, F: 0.008\n    # Wikification -> P: 0.000, R: 0.000, F: 0.000\n    # Named Ent. -> P: 0.222, R: 0.092, F: 0.130\n    # Negations -> P: 0.000, R: 0.000, F: 0.000\n    # IgnoreVars -> P: 0.005, R: 0.003, F: 0.003\n    # Concepts -> P: 0.075, R: 0.036, F: 0.049\n    # Frames -> P: 0.007, R: 0.007, F: 0.007\n    # Reentrancies -> P: 0.113, R: 0.060, F: 0.079\n    # SRL -> P: 0.145, R: 0.104, F: 0.121\n    scores = SmatchScores()\n    for line in text.split('\\n'):\n        line = line.strip()\n        if not line:\n            continue\n        name, vs = line.split(' -> ')\n        try:\n            p, r, f = [float(x.split(': ')[-1]) for x in vs.split(', ')]\n        except ValueError:\n            warnings.warn(f'Failed to parse results from smatch: {line}')\n            p, r, f = float(\"nan\"), float(\"nan\"), float(\"nan\")\n        scores[name] = F1_(p, r, f)\n    return scores\n\n\ndef format_fast_scores(text: str):\n    # using fast smatch\n    # Precision: 0.137\n    # Recall: 0.108\n    # Document F-score: 0.121\n    scores = []\n    for line in text.split('\\n'):\n        line = line.strip()\n        if not line or ':' not in line:\n            continue\n        name, score = line.split(': ')\n        scores.append(float(score))\n    assert len(scores) == 3","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/metrics/amr/smatch_eval.py#L64-L100","documentation":"format_official_scores parses the subprocess output of the smatch AMR evaluation tool; if a line's '-> P: x, R: y, F: z' triple cannot be split/parsed as floats, it warns and records NaN scores for that metric.","triggerScenarios":"Running smatch_eval / format_official_scores where the smatch binary output format differs from expected — old/new smatch versions, localized decimal separators, or interleaved log lines breaking parsing.","commonSituations":"A different smatch version installed on PATH emitting changed output; stderr content mixed into stdout; corrupted smatch output from a failed run.","solutions":["Check the warned line to see the actual format and confirm your smatch version is the one HanLP expects (install via HanLP's smatch dependency)","Capture/inspect the raw smatch output separately to spot interleaved warnings","Treat returned NaN scores as the signal that this metric run is invalid and re-run"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import math\ndef scores_valid(scores):\n    return all(not math.isnan(s.f) for s in scores.values())","typeGuard":"def scores_valid(scores: dict) -> bool:\n    import math\n    return all(not math.isnan(getattr(s, 'f', s)) for s in scores.values())","tryCatchPattern":"scores = format_official_scores(text)\nif any(math.isnan(v.f) for v in scores.values()):\n    logging.warning('smatch output unparseable, re-running evaluation')\n    scores = format_fast_scores(text)  # alternate parser","preventionTips":["Install the smatch version HanLP depends on","Run smatch manually once to verify output format"],"tags":["amr","evaluation","smatch","parsing"],"backgroundTag":"external-tool-output-parse-failure","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}