Skip to content

detect_key_phrases

detect_key_phrases(
    text: CustomerInputString,
    language_code: LanguageCode,
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
) -> DetectKeyPhrasesResponse

Detects the key noun phrases found in the text.

Parameters:

  • text (CustomerInputString) –

    A UTF-8 text string. The string must contain less than 100 KB of UTF-8 encoded characters.

  • language_code (LanguageCode) –

    The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. All documents must be in the same language.

Raises:

Source code in docs_src/capo_comprehend/_services/comprehend.py
def detect_key_phrases(
    self,
    text: "capo_comprehend.types.customer_input_string.CustomerInputString",
    language_code: "capo_comprehend.types.language_code.LanguageCode",
    *,
    config_overrides: Optional[ComprehendClientConfig] = None,
) -> "capo_comprehend.types.detect_key_phrases_response.DetectKeyPhrasesResponse":
    """<p>Detects the key noun phrases found in the text. </p>

    Args:
        text: <p>A UTF-8 text string. The string must contain less than 100 KB of UTF-8 encoded characters.</p>
        language_code: <p>The language of the input documents. You can specify any of the primary languages supported by Amazon Comprehend. All documents must be in the same language.</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.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.
    """

    def _handler(
        req: "OperationRequest[capo_comprehend.types.detect_key_phrases_request.DetectKeyPhrasesRequest]",
    ) -> OperationResponse[
        "capo_comprehend.types.detect_key_phrases_response.DetectKeyPhrasesResponse"
    ]:
        import capo_comprehend._operations.comprehend_20171127.detect_key_phrases

        output, http_response = (
            capo_comprehend._operations.comprehend_20171127.detect_key_phrases.detect_key_phrases(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

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

        return capo_comprehend.types.detect_key_phrases_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("DetectKeyPhrases", redact_input=_redact_input),
    )
    input_: capo_comprehend.types.detect_key_phrases_request.DetectKeyPhrasesRequest = {
        "text": text,
        "language_code": language_code,
    }

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output