diff --git a/src/annotations/annotations.py b/src/annotations/annotations.py index c72270ccc24fc3fd8ad81130d9a81a4ff37b12ed..4ba6feb7e5b9c50452679f7d91745ea53c6a2c98 100644 --- a/src/annotations/annotations.py +++ b/src/annotations/annotations.py @@ -1,7 +1,3 @@ -from dataclasses import dataclass - - -@dataclass class Annotation: def __hash__(self) -> int: return (type(self), *(self.__dict__.values())).__hash__() diff --git a/src/detections/detection.py b/src/detections/detection.py index 149eaf87296928e4d5d7f4c9b5392367170b3886..fad8a6db4fc91a0b02ad553bbfc023be3fba69cf 100644 --- a/src/detections/detection.py +++ b/src/detections/detection.py @@ -1,8 +1,6 @@ -from dataclasses import dataclass from typing import Optional -@dataclass class Detection: TYPE_NAME = "detection" diff --git a/src/detectors/interface.py b/src/detectors/interface.py index 325d6d6a813409b3794f3c74f66b54a4276ff409..fe8981eb98bf3215e84a3d51c0e81ab2fdcd9420 100644 --- a/src/detectors/interface.py +++ b/src/detectors/interface.py @@ -1,9 +1,19 @@ from typing import List, Dict, Any, Tuple from src.detections import Detection +from abc import ABC, abstractmethod - -class Detector: +class Detector(ABC): + @abstractmethod def detect( self, text: str, annotations: Dict[str, List[Tuple[int, int, Any]]] ) -> List[Tuple[int, int, Detection]]: - raise NotImplementedError + """Detects entities in text + + Args: + text (str): Text to be processed. + annotations (Dict[str, List[Tuple[int, int, Any]]]): Annotations. + + Returns: + List[Tuple[int, int, Detection]]: List of detections. + """ + pass \ No newline at end of file diff --git a/src/dictionaries/morphosyntactic/interface.py b/src/dictionaries/morphosyntactic/interface.py index 2718189b72baec04831eeded2b4564d681c0046e..13d36e95ba7675d2b9162b4dc83509f770055ba4 100644 --- a/src/dictionaries/morphosyntactic/interface.py +++ b/src/dictionaries/morphosyntactic/interface.py @@ -1,16 +1,17 @@ from src.detections import Detection from typing import Optional, List, Type +from abc import ABC, abstractmethod - -class MorphosyntacticDictionary: +class MorphosyntacticDictionary(ABC): + @abstractmethod def get_supported_detection_classes(self) -> List[Type[Detection]]: """ - Returns a list of supported detection classes + Returns a list of supported detection classess """ - raise NotImplementedError() + pass def get_random_replacement(self, original_entry: Detection) -> Optional[str]: """ Returns a random replacement for the original entry """ - raise NotImplementedError() + pass diff --git a/src/input_parsers/interface.py b/src/input_parsers/interface.py index 192fa2f80709997e5a6029a218192f2fc1567a04..6309f918b7b5a1ecc7f2ab1a85852eb8b2a61e83 100644 --- a/src/input_parsers/interface.py +++ b/src/input_parsers/interface.py @@ -1,7 +1,9 @@ from typing import Dict, List, Tuple, Any +from abc import ABC, abstractmethod -class InputParser: +class InputParser(ABC): + @abstractmethod def parse(self, content: str) -> Tuple[str, List[Tuple[int, int, Any]]]: """Parse input string into text and annotations. diff --git a/src/pipeline/default.py b/src/pipeline/default.py index 8850a28ce928c5b44d95d3248605cc7ab3da48c5..cdf2db3463a4db3c319e238cde32835485b48c3b 100644 --- a/src/pipeline/default.py +++ b/src/pipeline/default.py @@ -19,8 +19,8 @@ class DefaultPipeline(Pipeline): self._suppressor = suppressor self._replacers = replacers - def run(self, input) -> str: - with open(input, "r") as f: + def run(self, input_path) -> str: + with open(input_path, "r") as f: content = f.read() parsed_input = self._input_parser.parse(content) diff --git a/src/pipeline/interface.py b/src/pipeline/interface.py index ed87fd653c7b721f5a960b2da8bdd459ba212bb0..3574d841324abf8b3c828cd82b217b47c29f2fd4 100644 --- a/src/pipeline/interface.py +++ b/src/pipeline/interface.py @@ -1,3 +1,14 @@ -class Pipeline: - def run(self, input) -> str: - raise NotImplementedError +from abc import ABC, abstractmethod + +class Pipeline(ABC): + @abstractmethod + def run(self, input_path) -> str: + """Run the whole anonymization pipeline on the input file and output the result. + + Args: + input_path (_type_): Path to the input file. + + Returns: + str: Anonymized text. + """ + pass diff --git a/src/pipeline/sequential_jsonl.py b/src/pipeline/sequential_jsonl.py index 2bc796a706ce52de25cae2f72dc8988c20e14e0b..5f922ec900bbe7b8050acc221a1e9e8aac346b22 100644 --- a/src/pipeline/sequential_jsonl.py +++ b/src/pipeline/sequential_jsonl.py @@ -20,9 +20,9 @@ class SequentialJSONLPipeline(Pipeline): self._suppressor = suppressor self._replacers = replacers - def run(self, input) -> str: + def run(self, input_path) -> str: result = [] - with open(input, "r") as f: + with open(input_path, "r") as f: for line in f.readlines(): if line.strip() == "": continue diff --git a/src/suppressors/interface.py b/src/suppressors/interface.py index 565c6ac3a3ec8cd68045497158fa4ac052f46361..f6a3420f4f3b2df7eef15bada11c3e2fea905277 100644 --- a/src/suppressors/interface.py +++ b/src/suppressors/interface.py @@ -1,7 +1,9 @@ from typing import List, Tuple, Any +from abc import ABC, abstractmethod -class Suppressor: +class Suppressor(ABC): + @abstractmethod def suppress( self, annotations: List[Tuple[int, int, Any]] ) -> List[Tuple[int, int, Any]]: