How to use the pyknp.evaluate.scorer.Scorer function in pyknp

To help you get started, we’ve selected a few pyknp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ku-nlp / pyknp / pyknp / evaluate / dep.py View on Github external
assert isinstance(ignoreStart, bool)
    if level != 1 and level != 2:
        raise KeyError

    spans = set([])
    g_spans = [g.get_tag_span(t.tag_id) for t in g.tag_list()]
    s_spans = [s.get_tag_span(t.tag_id) for t in s.tag_list()]
    if ignoreStart:
        for i, g_span in enumerate(g_spans):
            g_spans[i] = g_span[1]
        for i, s_span in enumerate(s_spans):
            s_spans[i] = s_span[1]
    spans = spans.union(set(g_spans))
    spans = spans.union(set(s_spans))

    scorer = Scorer()
    for span in spans:
        g_to_span = None
        s_to_span = None
        g_dpndtype = None
        s_dpndtype = None
        try:
            gold_pid = g_spans.index(span)
            if (level == 2) and (gold_pid == len(g_spans) - 2):
                continue
            g_to = g.tag_list()[gold_pid].parent_id
            if g_to == -1:
                continue
            g_dpndtype = g.tag_list()[gold_pid].dpndtype
            g_to_span = g_spans[g_to]
        except ValueError:
            pass
github ku-nlp / pyknp / pyknp / evaluate / phrase.py View on Github external
def phrase(g, s, level=0):
    assert isinstance(g, BList)
    assert isinstance(s, BList)
    assert isinstance(level, int)
    if level != 0:
        raise KeyError

    spans = set([])
    g_spans = [g.get_tag_span(t.tag_id) for t in g.tag_list()]
    s_spans = [s.get_tag_span(t.tag_id) for t in s.tag_list()]
    spans = spans.union(set(g_spans))
    spans = spans.union(set(s_spans))

    scorer = Scorer()
    for span in spans:
        try:
            gold_pid = g_spans.index(span)
        except ValueError:
            scorer.fp += 1
            continue

        try:
            sys_pid = s_spans.index(span)
        except ValueError:
            scorer.fn += 1
            continue

        scorer.tp += 1

    return scorer

pyknp

Python module for JUMAN/KNP

See COPYING
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages