How to use the underthesea.util.file_io.read function in underthesea

To help you get started, we’ve selected a few underthesea 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 undertheseanlp / underthesea / tests / ner / test_ner.py View on Github external
def load_input(input_file):
    lines = read(input_file).strip().split("\n")
    content = [line.split("\t")[0] for line in lines]
    content = u" ".join(content)
    return content
github undertheseanlp / underthesea / tests / ner / test_ner.py View on Github external
def load_output(input_file):
    lines = [text.split("\t") for text in read(input_file).strip().split("\n")]
    output = [tuple(item) for item in lines]
    return output
github undertheseanlp / ner / util / evaluation.py View on Github external
def load_input(input_file):
    lines = read(input_file).strip().split("\n")
    if lines[0][0] == "#":
        lines = lines[1:]
    content = [line.split("\t")[0] for line in lines]
    content = u" ".join(content)
    return content
github undertheseanlp / ner / util / evaluation.py View on Github external
def load_output(input_file):
    lines = read(input_file).strip().split("\n")
    if lines[0][0] == "#":
        lines = lines[1:]
    text = "\n".join(lines)
    return text
github undertheseanlp / ner / util / error_analysis.py View on Github external
def convert_cm_to_log(cm, labels, line=5):
    cm = cm.tolist()
    # cm = [" ".join([("%-" + str(line) + "s") % labels[index]] + map(lambda i: ("%" + str(line) + "d") % i, row)) for index, row in enumerate(cm)]
    cm_ = []
    for index, row in enumerate(cm):
        content = " ".join([("%-" + str(line) + "s") % labels[index]] + map(lambda i: ("%" + str(line) + "d") % i, row))
        cm_.append(content)
    title = " " * (line + 1) + " ".join(map(lambda i: ("%" + str(line) + "s") % i, labels))
    cm.insert(0, title)
    return cm


# results = json.loads(read(join("logs", "20171006_153955", "result.json")))
results = json.loads(read(join("logs", "20171006_161437", "result.json")))
print(0)
actual = results["actual"]
expected = results["expected"]
labels = list(set(expected).union(set(actual)))
cm = confusion_matrix(expected, actual, labels)
cm = convert_cm_to_log(cm, labels)
pprint(cm, indent=2)