【AWS CLI Samples】Comprehend

Comprehend

The execution of commands is primarily verified in AWS Cloud9.
If you would like to provide command examples, please submit them through the contact form.
You may also use this form to request corrections for the listed command examples.


Determine the language of the text

text="時は金なり"
aws comprehend detect-dominant-language \
--text "$text"

output

{
    "Languages": [
        {
            "LanguageCode": "ja",
            "Score": 1.0
        }
    ]
}

by ton

Determine the language of the text and translate it to English

text="時は金なり"
lang=$(aws comprehend detect-dominant-language \
--text "$text" \
--query 'Languages[0].LanguageCode' \
--output text)
aws translate translate-text \
--source-language-code $lang \
--target-language-code "en" \
--text "$text" \
--query 'TranslatedText'

output

"Time is money"

by ton

Determine the language of the text and analyze the syntax

text="Time is money"
lang=$(aws comprehend detect-dominant-language \
--text "$text" \
--query 'Languages[0].LanguageCode' \
--output text)
aws comprehend detect-syntax \
--language-code $lang \
--text "$text"

output

{
    "SyntaxTokens": [
        {
            "TokenId": 1,
            "Text": "Time",
            "BeginOffset": 0,
            "EndOffset": 4,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 1.0
            }
        },
        {
            "TokenId": 2,
            "Text": "is",
            "BeginOffset": 5,
            "EndOffset": 7,
            "PartOfSpeech": {
                "Tag": "VERB",
                "Score": 1.0
            }
        },
        {
            "TokenId": 3,
            "Text": "money",
            "BeginOffset": 8,
            "EndOffset": 13,
            "PartOfSpeech": {
                "Tag": "NOUN",
                "Score": 1.0
            }
        }
    ]
}

by anonymous

タイトルとURLをコピーしました