Skip to content

Commit

Permalink
feat: allow creating graphs from plain texts
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Feb 7, 2023
1 parent 2b1ce7d commit 309e959
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions arguebuf/load/_load_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)

Expand All @@ -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":
Expand Down
27 changes: 27 additions & 0 deletions arguebuf/load/_load_text.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 309e959

Please sign in to comment.