Coverage for geoparser/modules/resolvers/base.py: 100%
7 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-20 18:08 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-20 18:08 +0000
1import typing as t
2from abc import abstractmethod
4from geoparser.modules.module import Module
7class Resolver(Module):
8 """
9 Abstract class for modules that perform reference resolution.
11 These modules link recognized references to specific referents in a gazetteer.
12 They are completely database-agnostic and operate only on raw text data.
13 """
15 # This base class should have NAME set to None since it should not be instantiated directly
16 NAME = None
18 def __init__(self, **kwargs):
19 """
20 Initialize a resolution module.
22 Args:
23 **kwargs: Configuration parameters for this module
24 """
25 super().__init__(**kwargs)
27 @abstractmethod
28 def predict(
29 self, texts: t.List[str], references: t.List[t.List[t.Tuple[int, int]]]
30 ) -> t.List[t.List[t.Union[t.Tuple[str, str], None]]]:
31 """
32 Predict referents for multiple references across multiple documents.
34 This abstract method must be implemented by child classes.
36 Args:
37 texts: List of document text strings
38 references: List of lists of tuples containing (start, end) positions of references.
39 Each inner list corresponds to references in one document at the same index in texts.
41 Returns:
42 A list of lists where each inner list corresponds to referents for references in one
43 document. Each element at position [i][j] is the referent (or None) for the reference
44 at position [i][j] in the input. Each element is either a tuple (gazetteer_name,
45 identifier) for a successfully resolved reference, or None to indicate that prediction
46 is not available for that specific reference (e.g., missing data, unsupported format,
47 etc.). The gazetteer_name identifies which gazetteer the identifier refers to, and the
48 identifier is the value used to identify the referent in that gazetteer.
49 """