Source code for redshred.microservices.token_lookup

from __future__ import annotations

from typing import Union

from ..spatial import GeoJSON
from .generic import Microservice


[docs] class TokenLookup(Microservice): """ A microservice that allows you to extract text for any given RedShred segment. This microservice is specialized for extracting text based on geographic regions provided in the form of GeoJSON or a segment ID. Inherits from a more generic `Microservice` class. Args: api: The RedShredAPI object used to communicate with the RedShred API. **kwargs: Arbitrary keyword arguments passed along to the `Microservice` base class. """ def __init__(self, api, **kwargs): super().__init__(api=api, params={"token_inclusion_method": "intersects"}, endpoint="tolo-text", **kwargs)
[docs] def get_text( self, collection: Union["Collection", str], # noqa: F821 regions: Union["GeoJSON", str], **params, ): """ Retrieves the text of the provided regions/segment. This method sends a request to the associated microservice API to perform the text extraction operation and return the result. Args: collection: A `Collection` instance or a string representing the data collection to be cropped. regions: A `GeoJSON` object or a string representing the geographic regions by which to extract the text from. **params: Arbitrary keyword arguments representing additional parameters for the text extraction operation. Returns: The content of the response from the microservice API after performing the text extraction operation, which is a string representing the extracted text. """ response = self(collection=collection, regions=regions, **params) return response.json()["text"]