From d37c8814aa7e2269fd09c92581255eb7b6d1ce2b Mon Sep 17 00:00:00 2001 From: Mirko Lenz Date: Fri, 18 Oct 2024 12:54:05 +0200 Subject: [PATCH] chore: reformat all python files --- arguebuf/cli/graph.py | 26 +++---- arguebuf/cli/model.py | 4 +- arguebuf/cli/text.py | 3 +- arguebuf/cli/translator.py | 4 +- arguebuf/dt.py | 10 +-- arguebuf/dump/_dump_d2.py | 12 ++-- arguebuf/dump/_dump_graphviz.py | 32 ++++----- arguebuf/dump/_dump_networkx.py | 14 ++-- arguebuf/dump/_dump_path.py | 5 +- arguebuf/load/_config.py | 2 +- arguebuf/load/_load_aif.py | 10 +-- arguebuf/load/_load_aml.py | 2 +- arguebuf/load/_load_argdown.py | 6 +- arguebuf/load/_load_brat.py | 2 +- arguebuf/load/_load_casebase.py | 12 ++-- arguebuf/load/_load_dict.py | 2 +- arguebuf/load/_load_io.py | 2 +- arguebuf/load/_load_json.py | 2 +- arguebuf/load/_load_kialo.py | 6 +- arguebuf/load/_load_microtexts.py | 2 +- arguebuf/load/_load_ova.py | 6 +- arguebuf/load/_load_path.py | 9 ++- arguebuf/load/_load_protobuf.py | 6 +- arguebuf/load/_load_sadface.py | 4 +- arguebuf/load/_load_text.py | 2 +- arguebuf/load/_load_xaif.py | 6 +- arguebuf/model/analyst.py | 14 ++-- arguebuf/model/edge.py | 8 +-- arguebuf/model/graph.py | 48 +++++-------- arguebuf/model/metadata.py | 6 +- arguebuf/model/node.py | 42 +++++------ arguebuf/model/participant.py | 32 ++++----- arguebuf/model/reference.py | 12 ++-- arguebuf/model/resource.py | 6 +- arguebuf/model/scheme.py | 12 ++-- arguebuf/model/utils.py | 10 +-- arguebuf/render/__init__.py | 2 +- arguebuf/render/_render_d2.py | 6 +- arguebuf/render/_render_graphviz.py | 3 +- arguebuf/schemas/aif.py | 12 ++-- arguebuf/schemas/argdown.py | 4 +- arguebuf/schemas/d2.py | 5 +- arguebuf/schemas/ova.py | 107 ++++++++++++---------------- arguebuf/schemas/sadface.py | 8 +-- arguebuf/schemas/xaif.py | 16 ++--- arguebuf/traverse.py | 14 ++-- 46 files changed, 257 insertions(+), 301 deletions(-) diff --git a/arguebuf/cli/graph.py b/arguebuf/cli/graph.py index 5845004..d26c3c1 100644 --- a/arguebuf/cli/graph.py +++ b/arguebuf/cli/graph.py @@ -19,7 +19,7 @@ def translate( target_lang: str, auth_key: str, input_glob: str, - output_folder: t.Optional[Path] = None, + output_folder: Path | None = None, output_format: ag.dump.Format = ag.dump.Format.ARGUEBUF, clean: bool = False, overwrite: bool = False, @@ -51,7 +51,7 @@ def translate( def node_label_formatter( - strip_labels: bool, strip_labels_char: t.Optional[str] + strip_labels: bool, strip_labels_char: str | None ) -> t.Callable[[ag.AbstractNode], str] | None: _replace_char = "–" if strip_labels_char is None else strip_labels_char @@ -68,22 +68,22 @@ def _node_label(node: ag.AbstractNode) -> str: def render( input_folder: Path, input_glob: str, - output_folder: t.Optional[Path] = None, + output_folder: Path | None = None, output_format: str = ".pdf", strip_scheme_nodes: bool = False, strip_node_labels: bool = False, - strip_node_labels_char: t.Optional[str] = None, - edge_style: t.Optional[ag.schemas.graphviz.EdgeStyle] = None, - nodesep: t.Optional[float] = None, - ranksep: t.Optional[float] = None, - node_wrap_col: t.Optional[int] = None, + strip_node_labels_char: str | None = None, + edge_style: ag.schemas.graphviz.EdgeStyle | None = None, + nodesep: float | None = None, + ranksep: float | None = None, + node_wrap_col: int | None = None, node_margin: tuple[float, float] = (0, 0), - font_name: t.Optional[str] = None, - font_size: t.Optional[float] = None, + font_name: str | None = None, + font_size: float | None = None, clean: bool = False, overwrite: bool = False, start: int = 1, - max_nodes: t.Optional[int] = None, + max_nodes: int | None = None, prog: str = "dot", dpi: int = 300, monochrome: bool = False, @@ -141,12 +141,12 @@ def render( def convert( input_folder: Path, input_glob: str, - output_folder: t.Optional[Path] = None, + output_folder: Path | None = None, output_format: ag.dump.Format = ag.dump.Format.ARGUEBUF, clean: bool = False, overwrite: bool = False, start: int = 1, - text_folder: t.Optional[Path] = None, + text_folder: Path | None = None, text_suffix: str = ".txt", ) -> None: if not output_folder: diff --git a/arguebuf/cli/model.py b/arguebuf/cli/model.py index 06f066e..22a69ad 100644 --- a/arguebuf/cli/model.py +++ b/arguebuf/cli/model.py @@ -15,8 +15,8 @@ def create( cls, path_in: Path, path_out: Path, - input_glob: t.Optional[str], - output_suffix: t.Optional[str], + input_glob: str | None, + output_suffix: str | None, ) -> list["PathPair"]: pairs: list[PathPair] = [] diff --git a/arguebuf/cli/text.py b/arguebuf/cli/text.py index 0506dd0..0c96f8b 100644 --- a/arguebuf/cli/text.py +++ b/arguebuf/cli/text.py @@ -3,6 +3,7 @@ from pathlib import Path import typer + from arguebuf.cli.translator import Translator from . import model @@ -18,7 +19,7 @@ def translate( auth_key: str, input_glob: str, output_suffix: str, - output_folder: t.Optional[Path] = None, + output_folder: Path | None = None, clean: bool = False, overwrite: bool = False, start: int = 1, diff --git a/arguebuf/cli/translator.py b/arguebuf/cli/translator.py index 020c67d..c3e356e 100644 --- a/arguebuf/cli/translator.py +++ b/arguebuf/cli/translator.py @@ -19,9 +19,7 @@ def __init__(self, auth_key: str, source_lang: str, target_lang: str): self.target_lang = target_lang self.translator = DeepLTranslator(auth_key) - def _deepl_translate( - self, text: t.Union[str, t.Iterable[str]] - ) -> t.Union[str, list[str]]: + def _deepl_translate(self, text: str | t.Iterable[str]) -> str | list[str]: result = self.translator.translate_text( text, source_lang=self.source_lang, diff --git a/arguebuf/dt.py b/arguebuf/dt.py index 4f6ea82..a0fa642 100644 --- a/arguebuf/dt.py +++ b/arguebuf/dt.py @@ -1,14 +1,12 @@ -import typing as t - import pendulum from google.protobuf import timestamp_pb2 -def from_format(text: t.Optional[str], format: str) -> t.Optional[pendulum.DateTime]: +def from_format(text: str | None, format: str) -> pendulum.DateTime | None: return pendulum.from_format(text, format) if text else None -def to_format(dt: t.Optional[pendulum.DateTime], format: str) -> str: +def to_format(dt: pendulum.DateTime | None, format: str) -> str: return dt.format(format) if dt else "" @@ -16,8 +14,6 @@ def from_protobuf(dt: timestamp_pb2.Timestamp) -> pendulum.DateTime: return pendulum.instance(dt.ToDatetime()) if dt else pendulum.now() -def to_protobuf( - dt: t.Optional[pendulum.DateTime], obj: timestamp_pb2.Timestamp -) -> None: +def to_protobuf(dt: pendulum.DateTime | None, obj: timestamp_pb2.Timestamp) -> None: if dt: obj.FromDatetime(dt) diff --git a/arguebuf/dump/_dump_d2.py b/arguebuf/dump/_dump_d2.py index b24ae1c..4d3d6a4 100644 --- a/arguebuf/dump/_dump_d2.py +++ b/arguebuf/dump/_dump_d2.py @@ -8,11 +8,11 @@ def dump_d2( graph: Graph, - atom_label: t.Optional[t.Callable[[AtomNode], str]] = None, - scheme_label: t.Optional[t.Callable[[SchemeNode], str]] = None, - max_nodes: t.Optional[int] = None, + atom_label: t.Callable[[AtomNode], str] | None = None, + scheme_label: t.Callable[[SchemeNode], str] | None = None, + max_nodes: int | None = None, monochrome: bool = False, -) -> t.Optional[D2Graph]: +) -> D2Graph | None: if len(graph.nodes) > (max_nodes or 1000): return None @@ -50,7 +50,7 @@ def _dump_atom( g: D2Graph, major_claim: bool, monochrome: bool, - label_func: t.Optional[t.Callable[[AtomNode], str]] = None, + label_func: t.Callable[[AtomNode], str] | None = None, ) -> None: label: str = label_func(node) if label_func else node.label color = node.color(major_claim, monochrome) @@ -78,7 +78,7 @@ def _dump_scheme( g: D2Graph, major_claim: bool, monochrome: bool, - label_func: t.Optional[t.Callable[[SchemeNode], str]] = None, + label_func: t.Callable[[SchemeNode], str] | None = None, ) -> None: label: str = label_func(node) if label_func else node.label color = node.color(False, monochrome) diff --git a/arguebuf/dump/_dump_graphviz.py b/arguebuf/dump/_dump_graphviz.py index ad8ad8f..409df31 100644 --- a/arguebuf/dump/_dump_graphviz.py +++ b/arguebuf/dump/_dump_graphviz.py @@ -37,21 +37,21 @@ def add_gv_edge(graph, *args, **kwargs): # type: ignore def dump_graphviz( graph: Graph, - nodesep: t.Optional[float] = None, - ranksep: t.Optional[float] = None, - wrap_col: t.Optional[int] = None, - margin: t.Optional[t.Tuple[float, float]] = None, - font_name: t.Optional[str] = None, - font_size: t.Optional[float] = None, - atom_label: t.Optional[t.Callable[[AtomNode], str]] = None, - scheme_label: t.Optional[t.Callable[[SchemeNode], str]] = None, - graph_attr: t.Optional[t.Mapping[str, str]] = None, - node_attr: t.Optional[t.Mapping[str, str]] = None, - edge_attr: t.Optional[t.Mapping[str, str]] = None, - edge_style: t.Optional[EdgeStyle] = None, - max_nodes: t.Optional[int] = None, + nodesep: float | None = None, + ranksep: float | None = None, + wrap_col: int | None = None, + margin: tuple[float, float] | None = None, + font_name: str | None = None, + font_size: float | None = None, + atom_label: t.Callable[[AtomNode], str] | None = None, + scheme_label: t.Callable[[SchemeNode], str] | None = None, + graph_attr: t.Mapping[str, str] | None = None, + node_attr: t.Mapping[str, str] | None = None, + edge_attr: t.Mapping[str, str] | None = None, + edge_style: EdgeStyle | None = None, + max_nodes: int | None = None, monochrome: bool = False, -) -> t.Optional[GraphvizGraph]: +) -> GraphvizGraph | None: """Transform a Graph instance into an instance of GraphViz directed graph. Make sure that a GraphViz Executable path is set on your machine for visualization. Refer to the GraphViz library for additional information.""" if len(graph.nodes) > (max_nodes or 1000): @@ -127,7 +127,7 @@ def _dump_atom( major_claim: bool, wrap_col: int, monochrome: bool, - label_func: t.Optional[t.Callable[[AtomNode], str]] = None, + label_func: t.Callable[[AtomNode], str] | None = None, ) -> None: """Submethod used to export Graph object g into GV Graph format.""" color = node.color(major_claim, monochrome) @@ -150,7 +150,7 @@ def _dump_scheme( node: SchemeNode, g: GraphvizGraph, monochrome: bool, - label_func: t.Optional[t.Callable[[SchemeNode], str]] = None, + label_func: t.Callable[[SchemeNode], str] | None = None, ) -> None: """Submethod used to export Graph object g into GV Graph format.""" diff --git a/arguebuf/dump/_dump_networkx.py b/arguebuf/dump/_dump_networkx.py index 1db511d..482678a 100644 --- a/arguebuf/dump/_dump_networkx.py +++ b/arguebuf/dump/_dump_networkx.py @@ -11,12 +11,10 @@ def dump_networkx( graph: Graph, - graph_attrs: t.Optional[t.MutableMapping[str, t.Callable[[Graph], t.Any]]] = None, - atom_attrs: t.Optional[t.MutableMapping[str, t.Callable[[AtomNode], t.Any]]] = None, - scheme_attrs: t.Optional[ - t.MutableMapping[str, t.Callable[[SchemeNode], t.Any]] - ] = None, - edge_attrs: t.Optional[t.MutableMapping[str, t.Callable[[Edge], t.Any]]] = None, + graph_attrs: t.MutableMapping[str, t.Callable[[Graph], t.Any]] | None = None, + atom_attrs: t.MutableMapping[str, t.Callable[[AtomNode], t.Any]] | None = None, + scheme_attrs: t.MutableMapping[str, t.Callable[[SchemeNode], t.Any]] | None = None, + edge_attrs: t.MutableMapping[str, t.Callable[[Edge], t.Any]] | None = None, ) -> nx.DiGraph: """Transform the argument graph for use with the library `NetworkX` @@ -69,7 +67,7 @@ def dump_networkx( def edge_to_nx( edge: Edge, g: nx.DiGraph, - attrs: t.Optional[t.MutableMapping[str, t.Callable[[Edge], t.Any]]] = None, + attrs: t.MutableMapping[str, t.Callable[[Edge], t.Any]] | None = None, ) -> None: """Submethod used to export Graph object g into NX Graph format.""" @@ -86,7 +84,7 @@ def edge_to_nx( def node_to_nx( node: AbstractNode, g: nx.DiGraph, - attrs: t.Optional[t.MutableMapping[str, t.Callable[[AbstractNode], t.Any]]] = None, + attrs: t.MutableMapping[str, t.Callable[[AbstractNode], t.Any]] | None = None, ) -> None: """Submethod used to export Graph object g into NX Graph format.""" if attrs is None: diff --git a/arguebuf/dump/_dump_path.py b/arguebuf/dump/_dump_path.py index 1850b44..1ab0599 100644 --- a/arguebuf/dump/_dump_path.py +++ b/arguebuf/dump/_dump_path.py @@ -1,4 +1,3 @@ -import typing as t from pathlib import Path from arguebuf.model import Graph @@ -9,9 +8,7 @@ __all__ = ("dump_file",) -def dump_file( - graph: Graph, path: t.Union[Path, str], config: Config = DefaultConfig -) -> None: +def dump_file(graph: Graph, path: Path | str, config: Config = DefaultConfig) -> None: """Export structure of Graph instance into structure of File/Folder format.""" if isinstance(path, str): path = Path(path) diff --git a/arguebuf/load/_config.py b/arguebuf/load/_config.py index 386350b..ed17dbb 100644 --- a/arguebuf/load/_config.py +++ b/arguebuf/load/_config.py @@ -16,7 +16,7 @@ @dataclass class Config(t.Generic[TextType]): - nlp: t.Optional[t.Callable[[str], TextType]] = None + nlp: t.Callable[[str], TextType] | None = None GraphClass: type[Graph] = Graph AtomNodeClass: type[AtomNode] = AtomNode SchemeNodeClass: type[SchemeNode] = SchemeNode diff --git a/arguebuf/load/_load_aif.py b/arguebuf/load/_load_aif.py index e0e4e77..5f7bddc 100644 --- a/arguebuf/load/_load_aif.py +++ b/arguebuf/load/_load_aif.py @@ -1,7 +1,9 @@ import typing as t -from arguebuf.load._preprocess_aif import process_hanging_nodes + import pendulum + from arguebuf import dt +from arguebuf.load._preprocess_aif import process_hanging_nodes from arguebuf.model import Graph, utils from arguebuf.model.edge import Edge, warn_missing_nodes from arguebuf.model.node import AbstractNode, AtomNode, SchemeNode @@ -15,7 +17,7 @@ def load_aif( obj: aif.Graph, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, reconstruct_dialog: bool = False, ) -> Graph: @@ -57,7 +59,7 @@ def atom_from_aif(obj: aif.Node, config: Config) -> AtomNode: ) -def scheme_from_aif(obj: aif.Node, config: Config) -> t.Optional[SchemeNode]: +def scheme_from_aif(obj: aif.Node, config: Config) -> SchemeNode | None: """Generate SchemeNode object from AIF Node object.""" aif_type = obj["type"] @@ -87,7 +89,7 @@ def scheme_from_aif(obj: aif.Node, config: Config) -> t.Optional[SchemeNode]: def edge_from_aif( obj: aif.Edge, nodes: t.Mapping[str, AbstractNode], config: Config -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from AIF Edge format.""" source_id = obj.get("fromID") target_id = obj.get("toID") diff --git a/arguebuf/load/_load_aml.py b/arguebuf/load/_load_aml.py index 73799f6..5e52221 100644 --- a/arguebuf/load/_load_aml.py +++ b/arguebuf/load/_load_aml.py @@ -14,7 +14,7 @@ def load_aml( - obj: t.IO, name: t.Optional[str] = None, config: Config = DefaultConfig + obj: t.IO, name: str | None = None, config: Config = DefaultConfig ) -> Graph: """ Generate Graph structure from AML argument graph file diff --git a/arguebuf/load/_load_argdown.py b/arguebuf/load/_load_argdown.py index 2164689..029a9cd 100644 --- a/arguebuf/load/_load_argdown.py +++ b/arguebuf/load/_load_argdown.py @@ -15,7 +15,7 @@ def load_argdown( obj: argdown.Graph, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from JSON Argdown argument graph file @@ -60,7 +60,7 @@ def edge_from_argdown( obj: argdown.Edge, nodes: t.Mapping[str, AbstractNode], edge_class: type[Edge] = Edge, -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from Argdown JSON Edge format.""" source_id = obj.get("from", obj.get("source")) @@ -81,7 +81,7 @@ def edge_from_argdown( def atom_from_argdown( obj: argdown.Node, - nlp: t.Optional[t.Callable[[str], t.Any]] = None, + nlp: t.Callable[[str], t.Any] | None = None, node_class: type[AtomNode] = AtomNode, ) -> AtomNode: """Generate AtomNode object from Argdown JSON Node object.""" diff --git a/arguebuf/load/_load_brat.py b/arguebuf/load/_load_brat.py index c7655dd..11d26a3 100644 --- a/arguebuf/load/_load_brat.py +++ b/arguebuf/load/_load_brat.py @@ -11,7 +11,7 @@ def load_brat( obj: t.TextIO, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from BRAT argument graph file (reference: https://brat.nlplab.org/)""" diff --git a/arguebuf/load/_load_casebase.py b/arguebuf/load/_load_casebase.py index 52e51ee..748fb5b 100644 --- a/arguebuf/load/_load_casebase.py +++ b/arguebuf/load/_load_casebase.py @@ -58,10 +58,10 @@ def from_path(cls, path: Path) -> "FilesystemFilter": class CasebaseFilter: name: re.Pattern - cases: t.Optional[re.Pattern] + cases: re.Pattern | None kwargs: dict[str, re.Pattern] - def __init__(self, name: str, cases: t.Optional[str] = None, **kwargs: str): + def __init__(self, name: str, cases: str | None = None, **kwargs: str): self.name = re.compile(name) self.cases = re.compile(cases) if cases is not None else None self.kwargs = {} @@ -87,7 +87,7 @@ def from_protobuf(cls, filter: CasebaseFilterProto) -> "CasebaseFilter": def convert_filters( - filters: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType], None], + filters: CasebaseFilterType | t.Iterable[CasebaseFilterType] | None, ) -> list[CasebaseFilter]: if filters is None: return [] @@ -106,9 +106,9 @@ def convert_filters( def load_casebase( - include: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType]], - exclude: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType], None] = None, - basepath: t.Union[Path, str] = ".", + include: CasebaseFilterType | t.Iterable[CasebaseFilterType], + exclude: CasebaseFilterType | t.Iterable[CasebaseFilterType] | None = None, + basepath: Path | str = ".", glob: str = "*/*", config: Config = DefaultConfig, strict_equal: bool = False, diff --git a/arguebuf/load/_load_dict.py b/arguebuf/load/_load_dict.py index 844a68a..e242279 100644 --- a/arguebuf/load/_load_dict.py +++ b/arguebuf/load/_load_dict.py @@ -16,7 +16,7 @@ def load_dict( obj: t.Mapping[str, t.Any], - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from DICT argument graph file(Link?).""" diff --git a/arguebuf/load/_load_io.py b/arguebuf/load/_load_io.py index 7d62372..be44c25 100644 --- a/arguebuf/load/_load_io.py +++ b/arguebuf/load/_load_io.py @@ -15,7 +15,7 @@ def load_io( obj: t.TextIO, suffix: str, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from IO argument graph file(Link?).""" diff --git a/arguebuf/load/_load_json.py b/arguebuf/load/_load_json.py index 982a761..ffe126e 100644 --- a/arguebuf/load/_load_json.py +++ b/arguebuf/load/_load_json.py @@ -11,7 +11,7 @@ def load_json( obj: t.TextIO, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from JSON argument graph file(Link?).""" diff --git a/arguebuf/load/_load_kialo.py b/arguebuf/load/_load_kialo.py index 9711ef8..f104026 100644 --- a/arguebuf/load/_load_kialo.py +++ b/arguebuf/load/_load_kialo.py @@ -11,7 +11,7 @@ def load_kialo( obj: t.TextIO, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: if name_match := re.search(r"Discussion Title: (.*)", obj.readline()): @@ -103,8 +103,8 @@ def load_kialo( def _kialo_atom_node( id: str, text: str, - nlp: t.Optional[t.Callable[[str], t.Any]], - atom_class: t.Type[AtomNode], + nlp: t.Callable[[str], t.Any] | None, + atom_class: type[AtomNode], ) -> AtomNode: # Remove backslashes before parentheses/brackets text = re.sub(r"\\([\[\]\(\)])", r"\1", text) diff --git a/arguebuf/load/_load_microtexts.py b/arguebuf/load/_load_microtexts.py index acc90b1..82199ed 100644 --- a/arguebuf/load/_load_microtexts.py +++ b/arguebuf/load/_load_microtexts.py @@ -32,7 +32,7 @@ def transform_edges(elems: t.Iterable[t.Any]) -> dict[str, _Edge]: def load_microtexts( - obj: t.IO, name: t.Optional[str] = None, config: Config = DefaultConfig + obj: t.IO, name: str | None = None, config: Config = DefaultConfig ) -> Graph: """ Generate Graph structure from AML argument graph file diff --git a/arguebuf/load/_load_ova.py b/arguebuf/load/_load_ova.py index 81a2dee..6a3f000 100644 --- a/arguebuf/load/_load_ova.py +++ b/arguebuf/load/_load_ova.py @@ -19,7 +19,7 @@ def load_ova( obj: ova.Graph, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from OVA argument graph file (reference: http://ova.uni-trier.de/).""" @@ -105,7 +105,7 @@ def _inject_original_text( def edge_from_ova( obj: ova.Edge, nodes: t.Mapping[str, AbstractNode], config: Config -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from OVA Edge format.""" source_id = str(obj["from"]["id"]) target_id = str(obj["to"]["id"]) @@ -124,7 +124,7 @@ def edge_from_ova( return None -def scheme_from_ova(obj: ova.Node, config: Config) -> t.Optional[SchemeNode]: +def scheme_from_ova(obj: ova.Node, config: Config) -> SchemeNode | None: """Generate SchemeNode object from OVA Node object.""" ova_type = obj["type"] diff --git a/arguebuf/load/_load_path.py b/arguebuf/load/_load_path.py index 4f831ba..aaab255 100644 --- a/arguebuf/load/_load_path.py +++ b/arguebuf/load/_load_path.py @@ -1,4 +1,3 @@ -import typing as t from pathlib import Path from arguebuf.model import Graph @@ -11,8 +10,8 @@ def load_file( - file: t.Union[Path, str], - text_file: t.Optional[t.Union[Path, str]] = None, + file: Path | str, + text_file: Path | str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from a File.""" @@ -35,9 +34,9 @@ def load_file( def load_folder( - folder: t.Union[Path, str], + folder: Path | str, pattern: str, - text_folder: t.Optional[t.Union[Path, str]] = None, + text_folder: Path | str | None = None, text_suffix: str = ".txt", config: Config = DefaultConfig, ) -> dict[Path, Graph]: diff --git a/arguebuf/load/_load_protobuf.py b/arguebuf/load/_load_protobuf.py index c9d4632..1c3d932 100644 --- a/arguebuf/load/_load_protobuf.py +++ b/arguebuf/load/_load_protobuf.py @@ -25,7 +25,7 @@ def load_protobuf( obj: graph_pb2.Graph, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from PROTOBUF argument graph file.(Link?)""" @@ -144,7 +144,7 @@ def edge_from_protobuf( obj: graph_pb2.Edge, nodes: t.Mapping[str, AbstractNode], config: Config, -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from PROTOBUF Edge format.""" if obj.source in nodes and obj.target in nodes: return config.EdgeClass( @@ -172,7 +172,7 @@ def reference_from_protobuf( obj: graph_pb2.Reference, resources: t.Mapping[str, Resource], config: Config, -) -> t.Optional[Reference]: +) -> Reference | None: """Generate Resource object from PROTOBUF format Graph's Resource object.""" if obj.text: if obj.resource: diff --git a/arguebuf/load/_load_sadface.py b/arguebuf/load/_load_sadface.py index 45c9a9d..44defe7 100644 --- a/arguebuf/load/_load_sadface.py +++ b/arguebuf/load/_load_sadface.py @@ -23,7 +23,7 @@ def load_sadface( obj: sadface.Graph, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: """Generate Graph structure from SADFace argument graph file @@ -106,7 +106,7 @@ def scheme_from_sadface(obj: sadface.Node, config: Config) -> SchemeNode: def edge_from_sadface( obj: sadface.Edge, nodes: t.Mapping[str, AbstractNode], config: Config -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from SADFace Edge format.""" source_id = obj.get("source_id") target_id = obj.get("target_id") diff --git a/arguebuf/load/_load_text.py b/arguebuf/load/_load_text.py index c5f6592..c4aa1e3 100644 --- a/arguebuf/load/_load_text.py +++ b/arguebuf/load/_load_text.py @@ -11,7 +11,7 @@ def load_text( obj: t.TextIO, - name: t.Optional[str] = None, + name: str | None = None, config: Config = DefaultConfig, ) -> Graph: first_line = obj.readline() diff --git a/arguebuf/load/_load_xaif.py b/arguebuf/load/_load_xaif.py index 2b515e5..a4990a0 100644 --- a/arguebuf/load/_load_xaif.py +++ b/arguebuf/load/_load_xaif.py @@ -15,7 +15,7 @@ def load_xaif( - obj: xaif.Graph, name: t.Optional[str] = None, config: Config = DefaultConfig + obj: xaif.Graph, name: str | None = None, config: Config = DefaultConfig ) -> Graph: """ Generate Graph structure from xAif argument graph file @@ -40,7 +40,7 @@ def load_xaif( return g -def scheme_from_xaif(obj: xaif.AifNode, config: Config) -> t.Optional[SchemeNode]: +def scheme_from_xaif(obj: xaif.AifNode, config: Config) -> SchemeNode | None: """Generate SchemeNode object from xAif Node object.""" aif_type = obj["type"] @@ -79,7 +79,7 @@ def atom_from_xaif(obj: xaif.AifNode, config: Config) -> AtomNode: def edge_from_xaif( obj: xaif.AifEdge, nodes: t.Mapping[str, AbstractNode], config: Config -) -> t.Optional[Edge]: +) -> Edge | None: """Generate Edge object from xAif Edge format.""" source_id = obj.get("fromID") target_id = obj.get("toID") diff --git a/arguebuf/model/analyst.py b/arguebuf/model/analyst.py index bacc28c..f427cae 100644 --- a/arguebuf/model/analyst.py +++ b/arguebuf/model/analyst.py @@ -1,5 +1,3 @@ -import typing as t - from arguebuf.model import utils from arguebuf.model.userdata import Userdata @@ -7,17 +5,17 @@ class Analyst: - name: t.Optional[str] - email: t.Optional[str] + name: str | None + email: str | None userdata: Userdata _id: str def __init__( self, - name: t.Optional[str] = None, - email: t.Optional[str] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + name: str | None = None, + email: str | None = None, + userdata: Userdata | None = None, + id: str | None = None, ) -> None: self.name = name self.email = email diff --git a/arguebuf/model/edge.py b/arguebuf/model/edge.py index 858b19e..94e4c54 100644 --- a/arguebuf/model/edge.py +++ b/arguebuf/model/edge.py @@ -12,7 +12,7 @@ def warn_missing_nodes( - edge_id: t.Optional[str], source_id: t.Optional[str], target_id: t.Optional[str] + edge_id: str | None, source_id: str | None, target_id: str | None ) -> None: log.warning( f"Skipping edge '{edge_id}': Source '{source_id}' or target '{target_id}' not" @@ -41,9 +41,9 @@ def __init__( self, source: AbstractNode, target: AbstractNode, - metadata: t.Optional[Metadata] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + metadata: Metadata | None = None, + userdata: Userdata | None = None, + id: str | None = None, ): # if isinstance(source, AtomNode) and isinstance(target, AtomNode): # raise ValueError("Cannot create an edge between two atom nodes.") diff --git a/arguebuf/model/graph.py b/arguebuf/model/graph.py index dcebecd..45351c6 100644 --- a/arguebuf/model/graph.py +++ b/arguebuf/model/graph.py @@ -57,10 +57,10 @@ class Graph(t.Generic[TextType]): _outgoing_edges: ImmutableDict[AbstractNode, ImmutableSet[Edge]] _resources: ImmutableDict[str, Resource] _participants: ImmutableDict[str, Participant] - _major_claim: t.Optional[AtomNode] + _major_claim: AtomNode | None _analysts: ImmutableDict[str, Analyst] - library_version: t.Optional[str] - schema_version: t.Optional[int] + library_version: str | None + schema_version: int | None metadata: Metadata userdata: Userdata @@ -80,17 +80,13 @@ def atom_nodes(self) -> t.Mapping[str, AtomNode]: def scheme_nodes(self) -> t.Mapping[str, SchemeNode]: return self._scheme_nodes - def incoming_nodes( - self, node: t.Union[str, AbstractNode] - ) -> t.AbstractSet[AbstractNode]: + def incoming_nodes(self, node: str | AbstractNode) -> t.AbstractSet[AbstractNode]: if isinstance(node, str): node = self._nodes[node] return self._incoming_nodes[node] - def incoming_atom_nodes( - self, node: t.Union[str, AbstractNode] - ) -> t.AbstractSet[AtomNode]: + def incoming_atom_nodes(self, node: str | AbstractNode) -> t.AbstractSet[AtomNode]: if isinstance(node, str): node = self._nodes[node] @@ -107,17 +103,13 @@ def incoming_atom_nodes( return incoming_atom_nodes - def outgoing_nodes( - self, node: t.Union[str, AbstractNode] - ) -> t.AbstractSet[AbstractNode]: + def outgoing_nodes(self, node: str | AbstractNode) -> t.AbstractSet[AbstractNode]: if isinstance(node, str): node = self._nodes[node] return self._outgoing_nodes[node] - def outgoing_atom_nodes( - self, node: t.Union[str, AbstractNode] - ) -> t.AbstractSet[AtomNode]: + def outgoing_atom_nodes(self, node: str | AbstractNode) -> t.AbstractSet[AtomNode]: if isinstance(node, str): node = self._nodes[node] @@ -141,8 +133,8 @@ def outgoing_atom_nodes( def sibling_node_distances( self, - node: t.Union[str, AbstractNode], - max_levels: t.Optional[int] = None, + node: str | AbstractNode, + max_levels: int | None = None, node_type: type[AbstractNode] = AbstractNode, ) -> dict[AbstractNode, int]: """Find all sibling nodes of a node and their distance in the graph""" @@ -192,27 +184,25 @@ def sibling_node_distances( def sibling_nodes( self, - node: t.Union[str, AbstractNode], - max_levels: t.Optional[int] = 1, + node: str | AbstractNode, + max_levels: int | None = 1, node_type: type[AbstractNode] = AbstractNode, ) -> t.AbstractSet[AbstractNode]: return self.sibling_node_distances(node, max_levels, node_type).keys() - def incoming_edges(self, node: t.Union[str, AbstractNode]) -> t.AbstractSet[Edge]: + def incoming_edges(self, node: str | AbstractNode) -> t.AbstractSet[Edge]: if isinstance(node, str): node = self._nodes[node] return self._incoming_edges[node] - def outgoing_edges(self, node: t.Union[str, AbstractNode]) -> t.AbstractSet[Edge]: + def outgoing_edges(self, node: str | AbstractNode) -> t.AbstractSet[Edge]: if isinstance(node, str): node = self._nodes[node] return self._outgoing_edges[node] - def scheme_between( - self, premise: AtomNode, claim: AtomNode - ) -> t.Optional[SchemeNode]: + def scheme_between(self, premise: AtomNode, claim: AtomNode) -> SchemeNode | None: candidates = set(self._outgoing_nodes[premise]).intersection( self._incoming_nodes[claim] ) @@ -230,12 +220,12 @@ def resources(self) -> t.Mapping[str, Resource]: return self._resources @property - def major_claim(self) -> t.Optional[AtomNode]: + def major_claim(self) -> AtomNode | None: if self._major_claim: return self._major_claim @major_claim.setter - def major_claim(self, value: t.Union[str, AtomNode, None]) -> None: + def major_claim(self, value: str | AtomNode | None) -> None: if isinstance(value, str): value = self._atom_nodes[value] elif not (value is None or isinstance(value, AtomNode)): @@ -245,7 +235,7 @@ def major_claim(self, value: t.Union[str, AtomNode, None]) -> None: # self._metadata.update() @property - def root_node(self) -> t.Optional[AtomNode]: + def root_node(self) -> AtomNode | None: """If there is a single node with no outgoing edges, return it, otherwise None""" candidates = self.root_nodes @@ -280,7 +270,7 @@ def participants(self) -> t.Mapping[str, Participant]: def analysts(self) -> t.Mapping[str, Analyst]: return self._analysts - def __init__(self, name: t.Optional[str] = None): + def __init__(self, name: str | None = None): """Create a graph from scratch.""" self.name = name or utils.uuid() @@ -689,7 +679,7 @@ def remove_empty_scheme_branches(self) -> None: if scheme_node.id in self.scheme_nodes: self.remove_branch(scheme_node) - def remove_branch(self, element: t.Union[AbstractNode, Edge, str]) -> None: + def remove_branch(self, element: AbstractNode | Edge | str) -> None: """Remove an element and all its descendants from the graph. If the element is a string, it is interpreted as the id of a node. diff --git a/arguebuf/model/metadata.py b/arguebuf/model/metadata.py index 6dcf394..7d38f05 100644 --- a/arguebuf/model/metadata.py +++ b/arguebuf/model/metadata.py @@ -1,5 +1,3 @@ -import typing as t - import pendulum __all__ = ("Metadata",) @@ -12,8 +10,8 @@ class Metadata: def __init__( self, - created: t.Optional[pendulum.DateTime] = None, - updated: t.Optional[pendulum.DateTime] = None, + created: pendulum.DateTime | None = None, + updated: pendulum.DateTime | None = None, ) -> None: now = pendulum.now() diff --git a/arguebuf/model/node.py b/arguebuf/model/node.py index da4a34d..acdc08a 100644 --- a/arguebuf/model/node.py +++ b/arguebuf/model/node.py @@ -30,9 +30,9 @@ class Color: def __init__( self, - bg: t.Optional[str] = None, - fg: t.Optional[str] = None, - border: t.Optional[str] = None, + bg: str | None = None, + fg: str | None = None, + border: str | None = None, ) -> None: self.bg = bg or "#000000" self.fg = fg or "#ffffff" @@ -60,9 +60,9 @@ class AbstractNode(ABC): def __init__( self, - metadata: t.Optional[Metadata] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + metadata: Metadata | None = None, + userdata: Userdata | None = None, + id: str | None = None, ): self._id = id or utils.uuid() self.metadata = metadata or Metadata() @@ -113,17 +113,17 @@ class AtomNode(AbstractNode, t.Generic[TextType]): ) text: TextType - _reference: t.Optional[Reference] - _participant: t.Optional[Participant] + _reference: Reference | None + _participant: Participant | None def __init__( self, text: TextType, - reference: t.Optional[Reference] = None, - participant: t.Optional[Participant] = None, - metadata: t.Optional[Metadata] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + reference: Reference | None = None, + participant: Participant | None = None, + metadata: Metadata | None = None, + userdata: Userdata | None = None, + id: str | None = None, ): super().__init__(metadata, userdata, id) self.text = text @@ -141,11 +141,11 @@ def label(self) -> str: return self.plain_text @property - def reference(self) -> t.Optional[Reference]: + def reference(self) -> Reference | None: return self._reference @property - def participant(self) -> t.Optional[Participant]: + def participant(self) -> Participant | None: return self._participant def __repr__(self): @@ -169,16 +169,16 @@ class SchemeNode(AbstractNode): "premise_descriptors", ) - scheme: t.Optional[Scheme] + scheme: Scheme | None premise_descriptors: list[str] def __init__( self, - scheme: t.Optional[Scheme] = None, - premise_descriptors: t.Optional[list[str]] = None, - metadata: t.Optional[Metadata] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + scheme: Scheme | None = None, + premise_descriptors: list[str] | None = None, + metadata: Metadata | None = None, + userdata: Userdata | None = None, + id: str | None = None, ): super().__init__(metadata, userdata, id) self.scheme = scheme diff --git a/arguebuf/model/participant.py b/arguebuf/model/participant.py index 9a2a738..6913547 100644 --- a/arguebuf/model/participant.py +++ b/arguebuf/model/participant.py @@ -1,5 +1,3 @@ -import typing as t - from arguebuf.model import utils from arguebuf.model.metadata import Metadata from arguebuf.model.userdata import Userdata @@ -8,27 +6,27 @@ class Participant: - name: t.Optional[str] - username: t.Optional[str] - email: t.Optional[str] - url: t.Optional[str] - location: t.Optional[str] - description: t.Optional[str] + name: str | None + username: str | None + email: str | None + url: str | None + location: str | None + description: str | None metadata: Metadata userdata: Userdata _id: str def __init__( self, - name: t.Optional[str] = None, - username: t.Optional[str] = None, - email: t.Optional[str] = None, - url: t.Optional[str] = None, - location: t.Optional[str] = None, - description: t.Optional[str] = None, - metadata: t.Optional[Metadata] = None, - userdata: t.Optional[Userdata] = None, - id: t.Optional[str] = None, + name: str | None = None, + username: str | None = None, + email: str | None = None, + url: str | None = None, + location: str | None = None, + description: str | None = None, + metadata: Metadata | None = None, + userdata: Userdata | None = None, + id: str | None = None, ) -> None: self.name = name self.username = username diff --git a/arguebuf/model/reference.py b/arguebuf/model/reference.py index 8fe9527..e2209db 100644 --- a/arguebuf/model/reference.py +++ b/arguebuf/model/reference.py @@ -7,15 +7,15 @@ class Reference: - _resource: t.Optional[Resource] - offset: t.Optional[int] + _resource: Resource | None + offset: int | None text: t.Any def __init__( self, - resource: t.Optional[Resource] = None, - offset: t.Optional[int] = None, - text: t.Optional[t.Any] = None, + resource: Resource | None = None, + offset: int | None = None, + text: t.Any | None = None, ) -> None: self._resource = resource self.offset = offset @@ -27,5 +27,5 @@ def plain_text(self) -> str: return utils.xstr(self.text) @property - def resource(self) -> t.Optional[Resource]: + def resource(self) -> Resource | None: return self._resource diff --git a/arguebuf/model/resource.py b/arguebuf/model/resource.py index 5c4da29..6751d9d 100644 --- a/arguebuf/model/resource.py +++ b/arguebuf/model/resource.py @@ -13,9 +13,9 @@ @dataclass() class Resource: text: t.Any - title: t.Optional[str] = None - source: t.Optional[str] = None - timestamp: t.Optional[pendulum.DateTime] = None + title: str | None = None + source: str | None = None + timestamp: pendulum.DateTime | None = None metadata: Metadata = field(default_factory=Metadata) userdata: Userdata = field(default_factory=dict) _id: str = field(default_factory=utils.uuid) diff --git a/arguebuf/model/scheme.py b/arguebuf/model/scheme.py index 09e6d7e..3e87986 100644 --- a/arguebuf/model/scheme.py +++ b/arguebuf/model/scheme.py @@ -144,7 +144,7 @@ class Rephrase(str, Enum): Rephrase: "MA", Preference: "PA", } -aif2scheme: dict[aif.SchemeType, t.Optional[Scheme]] = { +aif2scheme: dict[aif.SchemeType, Scheme | None] = { "RA": Support.DEFAULT, "CA": Attack.DEFAULT, "MA": Rephrase.DEFAULT, @@ -252,12 +252,10 @@ class Rephrase(str, Enum): text2scheme: dict[ type[Scheme], - t.Union[ - dict[str, Support], - dict[str, Attack], - dict[str, Rephrase], - dict[str, Preference], - ], + dict[str, Support] + | dict[str, Attack] + | dict[str, Rephrase] + | dict[str, Preference], ] = { Support: text2support, Attack: {}, diff --git a/arguebuf/model/utils.py b/arguebuf/model/utils.py index 8f6c89f..855ad11 100644 --- a/arguebuf/model/utils.py +++ b/arguebuf/model/utils.py @@ -19,7 +19,7 @@ def xstr(data: t.Any) -> str: return "" if data is None else str(data) -def parse(text: t.Optional[str], nlp: t.Optional[t.Callable[[str], t.Any]]) -> t.Any: +def parse(text: str | None, nlp: t.Callable[[str], t.Any] | None) -> t.Any: if nlp: if text is None: return nlp("") @@ -66,7 +66,7 @@ class ImmutableList(abc.Sequence[_T]): _store: t.MutableSequence[_T] - def __init__(self, items: t.Optional[t.MutableSequence[_T]] = None): + def __init__(self, items: t.MutableSequence[_T] | None = None): self._store = items or [] def __len__(self) -> int: @@ -80,7 +80,7 @@ def __getitem__(self, key: int) -> _T: def __getitem__(self, key: slice) -> t.Sequence[_T]: pass # Don't put code here - def __getitem__(self, key: t.Union[int, slice]) -> t.Union[_T, t.Sequence[_T]]: + def __getitem__(self, key: int | slice) -> _T | t.Sequence[_T]: return self._store.__getitem__(key) def __repr__(self) -> str: @@ -97,7 +97,7 @@ class ImmutableSet(abc.Set[_T]): _store: t.MutableSet[_T] - def __init__(self, items: t.Optional[t.MutableSet[_T]] = None): + def __init__(self, items: t.MutableSet[_T] | None = None): self._store = items or set() def __len__(self) -> int: @@ -123,7 +123,7 @@ class ImmutableDict(t.Mapping[_T, _U]): _store: t.MutableMapping[_T, _U] - def __init__(self, items: t.Optional[t.MutableMapping[_T, _U]] = None): + def __init__(self, items: t.MutableMapping[_T, _U] | None = None): self._store = items or {} def __len__(self) -> int: diff --git a/arguebuf/render/__init__.py b/arguebuf/render/__init__.py index 5a24e2a..2533358 100644 --- a/arguebuf/render/__init__.py +++ b/arguebuf/render/__init__.py @@ -1,4 +1,4 @@ -from ._render_graphviz import graphviz from ._render_d2 import d2 +from ._render_graphviz import graphviz __all__ = ("graphviz", "d2") diff --git a/arguebuf/render/_render_d2.py b/arguebuf/render/_render_d2.py index 3bcf36d..652eaa0 100644 --- a/arguebuf/render/_render_d2.py +++ b/arguebuf/render/_render_d2.py @@ -1,8 +1,8 @@ import os -from tempfile import NamedTemporaryFile -import typing as t from pathlib import Path from subprocess import run +from tempfile import NamedTemporaryFile + from arguebuf.schemas.d2 import D2Graph __all__ = ("d2",) @@ -11,7 +11,7 @@ def d2( graph: D2Graph, - path: t.Union[Path, str], + path: Path | str, ) -> None: """Visualize a Graph instance using a D2 backend. Make sure that a D2 Executable path is set on your machine for visualization.""" diff --git a/arguebuf/render/_render_graphviz.py b/arguebuf/render/_render_graphviz.py index d6b3b75..5e97b4c 100644 --- a/arguebuf/render/_render_graphviz.py +++ b/arguebuf/render/_render_graphviz.py @@ -1,4 +1,3 @@ -import typing as t from pathlib import Path from graphviz import ENGINES, FORMATS, Digraph @@ -11,7 +10,7 @@ def graphviz( graph: GraphvizGraph, - path: t.Union[Path, str], + path: Path | str, prog: str = "dot", dpi: int = 300, ) -> None: diff --git a/arguebuf/schemas/aif.py b/arguebuf/schemas/aif.py index ccc54c5..64ae323 100644 --- a/arguebuf/schemas/aif.py +++ b/arguebuf/schemas/aif.py @@ -23,12 +23,12 @@ class Locution(t.TypedDict): nodeID: str personID: str timestamp: str - start: t.Optional[str] - end: t.Optional[str] - source: t.Optional[str] + start: str | None + end: str | None + source: str | None class Graph(t.TypedDict): - nodes: t.List[Node] - edges: t.List[Edge] - locutions: t.List[Locution] + nodes: list[Node] + edges: list[Edge] + locutions: list[Locution] diff --git a/arguebuf/schemas/argdown.py b/arguebuf/schemas/argdown.py index 6ea9f0d..3d66410 100644 --- a/arguebuf/schemas/argdown.py +++ b/arguebuf/schemas/argdown.py @@ -18,8 +18,8 @@ class Edge(t.TypedDict): class Map(t.TypedDict): - nodes: t.List[Node] - edges: t.List[Edge] + nodes: list[Node] + edges: list[Edge] class Graph(t.TypedDict): diff --git a/arguebuf/schemas/d2.py b/arguebuf/schemas/d2.py index 0516231..00e669d 100644 --- a/arguebuf/schemas/d2.py +++ b/arguebuf/schemas/d2.py @@ -1,6 +1,3 @@ -import typing as t - - class D2Style: def __init__( self, font_color: str, bold: bool, stroke: str, stroke_width: int, fill: str @@ -27,7 +24,7 @@ def __init__(self, from_id: str, to_id: str): class D2Graph: - def __init__(self, nodes: t.List[D2Node], edges: t.List[D2Edge]): + def __init__(self, nodes: list[D2Node], edges: list[D2Edge]): self.nodes = nodes self.edges = edges diff --git a/arguebuf/schemas/ova.py b/arguebuf/schemas/ova.py index 4d70511..9ecdeaf 100644 --- a/arguebuf/schemas/ova.py +++ b/arguebuf/schemas/ova.py @@ -5,40 +5,32 @@ DATE_FORMAT = "DD/MM/YYYY - HH:mm:ss" DATE_FORMAT_ANALYSIS = "DD/MM/YYYY" -Node = t.TypedDict( - "Node", - { - "id": int, - "x": float, - "y": float, - "color": str, - "text": str, - "type": NodeType, - "scheme": str, - "descriptors": t.Dict[str, int], - "cqdesc": t.Dict[str, t.Any], - "visible": bool, - "participantID": str, - "w": float, - "h": float, - # - # Specific to original OVA - # - "imgurl": t.Optional[str], - # - # Specific to ReCAP OVA - # - "majorClaim": t.Optional[bool], - "is_check_worthy": t.Optional[str], - "source": t.Optional[str], - "text_begin": t.Optional[t.List[int]], - "text_end": t.Optional[t.List[int]], - "text_length": t.Optional[t.List[int]], - "comment": t.Optional[str], - "annotator": t.Optional[str], - "date": t.Optional[str], - }, -) + +class Node(t.TypedDict): + id: int + x: float + y: float + color: str + text: str + type: NodeType + scheme: str + descriptors: dict[str, int] + cqdesc: dict[str, t.Any] + visible: bool + participantID: str + w: float + h: float + imgurl: str | None + majorClaim: bool | None + is_check_worthy: str | None + source: str | None + text_begin: list[int] | None + text_end: list[int] | None + text_length: list[int] | None + comment: str | None + annotator: str | None + date: str | None + Edge = t.TypedDict( "Edge", @@ -49,34 +41,29 @@ # # Specific to ReCAP OVA # - "annotator": t.Optional[str], - "date": t.Optional[str], + "annotator": str | None, + "date": str | None, }, ) -Participant = t.TypedDict("Participant", {"id": int, "firstname": str, "surname": str}) -Analysis = t.TypedDict( - "Analysis", - { - "txt": str, - # - # Specific to ReCAP OVA - # - "plain_txt": t.Optional[str], - "annotatorName": t.Optional[str], - "documentSource": t.Optional[str], - "documentTitle": t.Optional[str], - "ovaVersion": t.Optional[str], - }, -) +class Participant(t.TypedDict): + id: int + firstname: str + surname: str -Graph = t.TypedDict( - "Graph", - { - "nodes": t.List[Node], - "edges": t.List[Edge], - "participants": t.List[Participant], - "analysis": Analysis, - }, -) + +class Analysis(t.TypedDict): + txt: str + plain_txt: str | None + annotatorName: str | None + documentSource: str | None + documentTitle: str | None + ovaVersion: str | None + + +class Graph(t.TypedDict): + nodes: list[Node] + edges: list[Edge] + participants: list[Participant] + analysis: Analysis diff --git a/arguebuf/schemas/sadface.py b/arguebuf/schemas/sadface.py index f8d183f..0f9d9b7 100644 --- a/arguebuf/schemas/sadface.py +++ b/arguebuf/schemas/sadface.py @@ -9,8 +9,8 @@ class Node(t.TypedDict): text: str type: NodeType name: str - sources: t.List[str] - metadata: t.Dict[str, t.Any] + sources: list[str] + metadata: dict[str, t.Any] class Edge(t.TypedDict): @@ -36,6 +36,6 @@ class Metadata(t.TypedDict): class Graph(t.TypedDict): - nodes: t.List[Node] - edges: t.List[Edge] + nodes: list[Node] + edges: list[Edge] metadata: Metadata diff --git a/arguebuf/schemas/xaif.py b/arguebuf/schemas/xaif.py index 4d097f4..bc536ad 100644 --- a/arguebuf/schemas/xaif.py +++ b/arguebuf/schemas/xaif.py @@ -10,7 +10,7 @@ class AifNode(t.TypedDict): class AifEdge(t.TypedDict): - edgeID: t.Union[str, int] + edgeID: str | int fromID: str toID: str @@ -32,11 +32,11 @@ class AifParticipant(t.TypedDict): class Aif(t.TypedDict): - nodes: t.List[AifNode] - edges: t.List[AifEdge] - schemefulfillments: t.List[AifSchemeFulfillment] - locutions: t.List[AifLocution] - participants: t.List[AifParticipant] + nodes: list[AifNode] + edges: list[AifEdge] + schemefulfillments: list[AifSchemeFulfillment] + locutions: list[AifLocution] + participants: list[AifParticipant] class OvaNode(t.TypedDict): @@ -57,8 +57,8 @@ class Ova(t.TypedDict): firstname: str surname: str url: str - nodes: t.List[OvaNode] - edges: t.List[OvaEdge] + nodes: list[OvaNode] + edges: list[OvaEdge] class Graph(t.TypedDict): diff --git a/arguebuf/traverse.py b/arguebuf/traverse.py index 15ac3e4..18a1610 100644 --- a/arguebuf/traverse.py +++ b/arguebuf/traverse.py @@ -10,7 +10,7 @@ def dfs( start: NodeType, connections: t.Callable[[AbstractNode], t.AbstractSet[NodeType]], include_start: bool = True, -) -> t.List[NodeType]: +) -> list[NodeType]: # Need to use a dict since a set does not preserve order visited: dict[NodeType, None] = {} stack: list[NodeType] = [start] @@ -32,7 +32,7 @@ def bfs( start: NodeType, connections: t.Callable[[AbstractNode], t.AbstractSet[NodeType]], include_start: bool = True, -) -> t.List[NodeType]: +) -> list[NodeType]: # Need to use a dict since a set does not preserve order visited: dict[NodeType, None] = {} queue: list[NodeType] = [start] @@ -54,9 +54,9 @@ def node_distance( start_node: AbstractNode, end_node: AbstractNode, connections: t.Callable[[AbstractNode], t.Iterable[AbstractNode]], - max_distance: t.Optional[int] = None, + max_distance: int | None = None, directed: bool = True, -) -> t.Optional[int]: +) -> int | None: """Get the distance between `start_node` and `end_node` in the graph. Args: @@ -107,9 +107,9 @@ def _directed_node_distance( start_node: AbstractNode, end_node: AbstractNode, connections: t.Callable[[AbstractNode], t.Iterable[AbstractNode]], - max_distance: t.Optional[int] = None, -) -> t.Optional[int]: - expansion: t.List[t.Tuple[AbstractNode, int]] = [ + max_distance: int | None = None, +) -> int | None: + expansion: list[tuple[AbstractNode, int]] = [ (n, 1) for n in connections(start_node) ]