Geoparser#
- class Geoparser(recognizer: Recognizer | None, resolver: Resolver | None)#
Bases:
objectUser-facing interface for the geoparser functionality.
Provides a simple parse method for processing texts with configured recognizer and resolver. The Geoparser creates a new project for each parse operation, making it stateless by default.
The recognizer and resolver have to be provided explicitly, so that it is always clear which modules a pipeline is built from:
from geoparser import Geoparser from geoparser.modules import SentenceTransformerResolver, SpacyRecognizer geoparser = Geoparser( recognizer=SpacyRecognizer(), resolver=SentenceTransformerResolver(gazetteer_name="geonames"), )
- parse(texts: str, save: bool = False) Document#
- parse(texts: Sequence[str], save: bool = False) List[Document]
Parse one or more texts with the configured recognizer and resolver.
The result mirrors the input: a single text is parsed into a single document, while a sequence of texts is parsed into a list of documents in the same order as the texts that were passed in.
This method creates a new project for each parse operation, processes the texts, and returns the results. By default, the project is deleted after processing to keep the parse method stateless.
- Parameters:
texts – Either a single document text or a sequence of texts
save – If True, preserve the project after processing. If False (default), delete the project to maintain stateless behavior.
- Returns:
A single Document if a single text was passed, or a list of Documents if a sequence of texts was passed, with processed references and referents from the configured recognizer and resolver.