Skip to content

Commit 8821db8

Browse files
Refactors method signatures across UDS modules for improved readability and consistency. Updates from_conll_and_annotations, from_json, add_annotation, and various other methods in corpus.py, document.py, and graph.py to use a more structured format. This change enhances code clarity and maintains uniformity in method definitions throughout the codebase.
1 parent c3e52e2 commit 8821db8

File tree

3 files changed

+160
-84
lines changed

3 files changed

+160
-84
lines changed

decomp/semantics/uds/corpus.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,15 @@ def _process_conll(self, split: str | None, udewt: bytes) -> None:
356356
spl.to_json(sentences_json_path, documents_json_path)
357357

358358
@classmethod
359-
def from_conll_and_annotations(cls,
360-
corpus: Location,
361-
sentence_annotations: Sequence[Location] = [],
362-
document_annotations: Sequence[Location] = [],
363-
annotation_format: str = 'normalized',
364-
version: str = '2.0',
365-
name: str = 'ewt') -> 'UDSCorpus':
359+
def from_conll_and_annotations(
360+
cls,
361+
corpus: Location,
362+
sentence_annotations: Sequence[Location] = [],
363+
document_annotations: Sequence[Location] = [],
364+
annotation_format: str = 'normalized',
365+
version: str = '2.0',
366+
name: str = 'ewt'
367+
) -> 'UDSCorpus':
366368
"""Load UDS graph corpus from CoNLL (dependencies) and JSON (annotations).
367369
368370
This method should only be used if the UDS corpus is being
@@ -463,8 +465,11 @@ def _load_ud_ids(
463465
return ud_ids
464466

465467
@classmethod
466-
def from_json(cls, sentences_jsonfile: Location,
467-
documents_jsonfile: Location) -> 'UDSCorpus':
468+
def from_json(
469+
cls,
470+
sentences_jsonfile: Location,
471+
documents_jsonfile: Location
472+
) -> 'UDSCorpus':
468473
"""Load annotated UDS graph corpus (including annotations) from JSON.
469474
470475
This is the suggested method for loading the UDS corpus.
@@ -541,8 +546,11 @@ def add_corpus_metadata(self, metadata: UDSCorpusMetadata) -> None:
541546
"""
542547
self._metadata += metadata
543548

544-
def add_annotation(self, sentence_annotation: list[UDSAnnotation] | None = None,
545-
document_annotation: list[UDSAnnotation] | None = None) -> None:
549+
def add_annotation(
550+
self,
551+
sentence_annotation: list[UDSAnnotation] | None = None,
552+
document_annotation: list[UDSAnnotation] | None = None
553+
) -> None:
546554
"""Add annotations to UDS sentence and document graphs.
547555
548556
Parameters
@@ -873,8 +881,11 @@ def sentence_properties(self, subspace: str | None = None) -> set[str]:
873881
"""
874882
raise NotImplementedError
875883

876-
def sentence_property_metadata(self, subspace: str,
877-
prop: str) -> UDSPropertyMetadata:
884+
def sentence_property_metadata(
885+
self,
886+
subspace: str,
887+
prop: str
888+
) -> UDSPropertyMetadata:
878889
"""Return the metadata for a property in a sentence subspace.
879890
880891
Parameters
@@ -906,8 +917,11 @@ def document_properties(self, subspace: str | None = None) -> set[str]:
906917
"""
907918
raise NotImplementedError
908919

909-
def document_property_metadata(self, subspace: str,
910-
prop: str) -> UDSPropertyMetadata:
920+
def document_property_metadata(
921+
self,
922+
subspace: str,
923+
prop: str
924+
) -> UDSPropertyMetadata:
911925
"""Return the metadata for a property in a document subspace.
912926
913927
Parameters

decomp/semantics/uds/document.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ class UDSDocument:
5050
initialized without edges from sentence_graphs
5151
"""
5252

53-
def __init__(self, sentence_graphs: SentenceGraphDict,
54-
sentence_ids: SentenceIDDict, name: str, genre: str,
55-
timestamp: str | None = None, doc_graph: UDSDocumentGraph | None = None):
53+
def __init__(
54+
self,
55+
sentence_graphs: SentenceGraphDict,
56+
sentence_ids: SentenceIDDict,
57+
name: str,
58+
genre: str,
59+
timestamp: str | None = None,
60+
doc_graph: UDSDocumentGraph | None = None
61+
):
5662
self.sentence_graphs: SentenceGraphDict = {}
5763
self.sentence_ids: SentenceIDDict = {}
5864
self.name = name
@@ -79,8 +85,13 @@ def to_dict(self) -> NetworkXGraphData:
7985
return self.document_graph.to_dict()
8086

8187
@classmethod
82-
def from_dict(cls, document: dict[str, dict], sentence_graphs: dict[str, UDSSentenceGraph],
83-
sentence_ids: dict[str, str], name: str = 'UDS') -> 'UDSDocument':
88+
def from_dict(
89+
cls,
90+
document: dict[str, dict],
91+
sentence_graphs: dict[str, UDSSentenceGraph],
92+
sentence_ids: dict[str, str],
93+
name: str = 'UDS'
94+
) -> 'UDSDocument':
8495
"""Construct a UDSDocument from a dictionary.
8596
8697
Since only the document graphs are serialized, the sentence

0 commit comments

Comments
 (0)