From 309e959fa2d934faef198183f0aff18a1eee80b2 Mon Sep 17 00:00:00 2001 From: Mirko Lenz Date: Tue, 7 Feb 2023 17:17:37 +0100 Subject: [PATCH] feat: allow creating graphs from plain texts --- arguebuf/load/_load_io.py | 4 ++-- arguebuf/load/_load_text.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 arguebuf/load/_load_text.py diff --git a/arguebuf/load/_load_io.py b/arguebuf/load/_load_io.py index 37c0b96..cea94ee 100644 --- a/arguebuf/load/_load_io.py +++ b/arguebuf/load/_load_io.py @@ -8,8 +8,8 @@ from ._load_aml import load_aml from ._load_brat import load_brat from ._load_json import load_json -from ._load_kialo import load_kialo from ._load_microtexts import load_microtexts +from ._load_text import load_text __all__ = ("load_io",) @@ -25,7 +25,7 @@ def load_io( if suffix == ".ann": return load_brat(obj, name, config) if suffix == ".txt": - return load_kialo(obj, name, config) + return load_text(obj, name, config) if suffix == ".aml": return load_aml(obj, name, config) if suffix == ".xml": diff --git a/arguebuf/load/_load_text.py b/arguebuf/load/_load_text.py new file mode 100644 index 0000000..d6caddf --- /dev/null +++ b/arguebuf/load/_load_text.py @@ -0,0 +1,27 @@ +import re +import typing as t + +from arguebuf.model import Graph, utils +from arguebuf.model.node import AtomNode, Attack, Rephrase, Support + +from ._config import Config, DefaultConfig +from ._load_kialo import load_kialo + +__all__ = ("load_text",) + + +def load_text( + obj: t.TextIO, + name: t.Optional[str] = None, + config: Config = DefaultConfig, +) -> Graph: + if "Discussion Title: " in obj.readline(): + obj.seek(0) + return load_kialo(obj, name, config) + + text = obj.read() + + g = config.GraphClass(name) + g.add_node(AtomNode(utils.parse(text, config.nlp))) + + return g