Skip to content

detect_entities async

detect_entities(
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
    text: Optional[CustomerInputString] = None,
    language_code: Optional[LanguageCode] = None,
    endpoint_arn: Optional[EntityRecognizerEndpointArn] = None,
    bytes: Optional[SemiStructuredDocumentBlob] = None,
    document_reader_config: Optional[DocumentReaderConfig] = None,
) -> DetectEntitiesResponse

Detects named entities in input text when you use the pre-trained model. Detects custom entities if you have a custom entity recognition model.

When detecting named entities using the pre-trained model, use plain text as the input. For more information about named entities, see Entities in the Comprehend Developer Guide.

When you use a custom entity recognition model, you can input plain text or you can upload a single-page input document (text, PDF, Word, or image).

If the system detects errors while processing a page in the input document, the API response includes an entry in Errors for each error.

If the system detects a document-level error in your input document, the API returns an InvalidRequestException error response. For details about this exception, see Errors in semi-structured documents in the Comprehend Developer Guide.

Parameters:

  • text (Optional[CustomerInputString], default: None ) –

    A UTF-8 text string. The maximum string size is 100 KB. If you enter text using this parameter, do not use the Bytes parameter.

  • language_code (Optional[LanguageCode], default: None ) –

    The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. If your request includes the endpoint for a custom entity recognition model, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you specify here.

    All input documents must be in the same language.

  • endpoint_arn (Optional[EntityRecognizerEndpointArn], default: None ) –

    The Amazon Resource Name of an endpoint that is associated with a custom entity recognition model. Provide an endpoint if you want to detect entities by using your own custom model instead of the default model that is used by Amazon Comprehend.

    If you specify an endpoint, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you provide in your request.

    For information about endpoints, see Managing endpoints.

  • bytes (Optional[SemiStructuredDocumentBlob], default: None ) –

    This field applies only when you use a custom entity recognition model that was trained with PDF annotations. For other cases, enter your text input in the Text field.

    Use the Bytes parameter to input a text, PDF, Word or image file. Using a plain-text file in the Bytes parameter is equivelent to using the Text parameter (the Entities field in the response is identical).

    You can also use the Bytes parameter to input an Amazon Textract DetectDocumentText or AnalyzeDocument output file.

    Provide the input document as a sequence of base64-encoded bytes. If your code uses an Amazon Web Services SDK to detect entities, the SDK may encode the document file bytes for you.

    The maximum length of this field depends on the input document type. For details, see Inputs for real-time custom analysis in the Comprehend Developer Guide.

    If you use the Bytes parameter, do not use the Text parameter.

  • document_reader_config (Optional[DocumentReaderConfig], default: None ) –

    Provides configuration parameters to override the default actions for extracting text from PDF documents and image files.

Raises:

Source code in docs_src/capo_comprehend/_services/async_comprehend.py
async def detect_entities(
    self,
    *,
    config_overrides: Optional[AsyncComprehendClientConfig] = None,
    text: Optional[
        "capo_comprehend.types.customer_input_string.CustomerInputString"
    ] = None,
    language_code: Optional[
        "capo_comprehend.types.language_code.LanguageCode"
    ] = None,
    endpoint_arn: Optional[
        "capo_comprehend.types.entity_recognizer_endpoint_arn.EntityRecognizerEndpointArn"
    ] = None,
    bytes: Optional[
        "capo_comprehend.types.semi_structured_document_blob.SemiStructuredDocumentBlob"
    ] = None,
    document_reader_config: Optional[
        "capo_comprehend.types.document_reader_config.DocumentReaderConfig"
    ] = None,
) -> "capo_comprehend.types.detect_entities_response.DetectEntitiesResponse":
    """<p>Detects named entities in input text when you use the pre-trained model. Detects custom entities if you have a custom entity recognition model. </p> <p> When detecting named entities using the pre-trained model, use plain text as the input. For more information about named entities, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/how-entities.html">Entities</a> in the Comprehend Developer Guide.</p> <p>When you use a custom entity recognition model, you can input plain text or you can upload a single-page input document (text, PDF, Word, or image). </p> <p>If the system detects errors while processing a page in the input document, the API response includes an entry in <code>Errors</code> for each error. </p> <p>If the system detects a document-level error in your input document, the API returns an <code>InvalidRequestException</code> error response. For details about this exception, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/idp-inputs-sync-err.html"> Errors in semi-structured documents</a> in the Comprehend Developer Guide. </p>

    Args:
        text: <p>A UTF-8 text string. The maximum string size is 100 KB. If you enter text using this parameter, do not use the <code>Bytes</code> parameter.</p>
        language_code: <p>The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. If your request includes the endpoint for a custom entity recognition model, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you specify here.</p> <p>All input documents must be in the same language.</p>
        endpoint_arn: <p>The Amazon Resource Name of an endpoint that is associated with a custom entity recognition model. Provide an endpoint if you want to detect entities by using your own custom model instead of the default model that is used by Amazon Comprehend.</p> <p>If you specify an endpoint, Amazon Comprehend uses the language of your custom model, and it ignores any language code that you provide in your request.</p> <p>For information about endpoints, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/manage-endpoints.html">Managing endpoints</a>.</p>
        bytes: <p>This field applies only when you use a custom entity recognition model that was trained with PDF annotations. For other cases, enter your text input in the <code>Text</code> field.</p> <p> Use the <code>Bytes</code> parameter to input a text, PDF, Word or image file. Using a plain-text file in the <code>Bytes</code> parameter is equivelent to using the <code>Text</code> parameter (the <code>Entities</code> field in the response is identical).</p> <p>You can also use the <code>Bytes</code> parameter to input an Amazon Textract <code>DetectDocumentText</code> or <code>AnalyzeDocument</code> output file.</p> <p>Provide the input document as a sequence of base64-encoded bytes. If your code uses an Amazon Web Services SDK to detect entities, the SDK may encode the document file bytes for you. </p> <p>The maximum length of this field depends on the input document type. For details, see <a href="https://docs.aws.amazon.com/comprehend/latest/dg/idp-inputs-sync.html"> Inputs for real-time custom analysis</a> in the Comprehend Developer Guide. </p> <p>If you use the <code>Bytes</code> parameter, do not use the <code>Text</code> parameter.</p>
        document_reader_config: <p>Provides configuration parameters to override the default actions for extracting text from PDF documents and image files.</p>

    Raises:
        capo_comprehend.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry your request.</p>
        capo_comprehend.errors.invalid_request_exception.InvalidRequestException: <p>The request is invalid.</p>
        capo_comprehend.errors.resource_unavailable_exception.ResourceUnavailableException: <p>The specified resource is not available. Check the resource and try your request again.</p>
        capo_comprehend.errors.text_size_limit_exceeded_exception.TextSizeLimitExceededException: <p>The size of the input text exceeds the limit. Use a smaller document.</p>
        capo_comprehend.errors.unsupported_language_exception.UnsupportedLanguageException: <p>Amazon Comprehend can't process the language of the input text. For a list of supported languages, <a href="https://docs.aws.amazon.com/comprehend/latest/dg/supported-languages.html">Supported languages</a> in the Comprehend Developer Guide. </p>
        capo_comprehend.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_comprehend.types.detect_entities_request.DetectEntitiesRequest]",
    ) -> AsyncOperationResponse[
        "capo_comprehend.types.detect_entities_response.DetectEntitiesResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.detect_entities

        (
            output,
            http_response,
        ) = await capo_comprehend._operations.comprehend_20171127.detect_entities.async_detect_entities(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_comprehend.types.detect_entities_request.DetectEntitiesRequest",
    ) -> dict[str, Any]:
        import capo_comprehend.types.detect_entities_request

        return capo_comprehend.types.detect_entities_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("DetectEntities", redact_input=_redact_input),
    )
    input_: capo_comprehend.types.detect_entities_request.DetectEntitiesRequest = {}
    if text is not None:
        input_["text"] = text
    if language_code is not None:
        input_["language_code"] = language_code
    if endpoint_arn is not None:
        input_["endpoint_arn"] = endpoint_arn
    if bytes is not None:
        input_["bytes"] = bytes
    if document_reader_config is not None:
        input_["document_reader_config"] = document_reader_config

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output