Source code for stringcompare.preprocessing.tagger

from abc import ABC, abstractmethod
from typing import Dict, List


[docs]class Tagger(ABC): @property @classmethod @abstractmethod def LABELS(cls): pass def __call__(self, obj): return self.tag(obj)
[docs] @abstractmethod def tag(self, obj) -> Dict: pass
[docs] def batch_tag(self, objs: List) -> List[Dict]: return [self.tag(obj) for obj in objs]
[docs]class DeepparseAddressTagger(Tagger): LABELS = [ "StreetNumber", "StreetName", "Unit", "Municipality", "Province", "PostalCode", "Orientation", "GeneralDelivery", ] def __init__(self, deepparse_handle): assert ( deepparse_handle.__class__.__name__ == "AddressParser" ), "deepparse_handle should be an AddressParser instance." self.deepparse_handle = deepparse_handle
[docs] def tag(self, obj) -> Dict: return self.deepparse_handle(obj).to_dict()
[docs] def batch_tag(self, objs: List) -> List[Dict]: return [r.to_dict() for r in self.deepparse_handle(objs)]