Search in sources :

Example 1 with Language

use of com.amplifyframework.predictions.models.Language in project amplify-android by aws-amplify.

the class AWSComprehendService method comprehend.

void comprehend(@NonNull String text, @NonNull Consumer<InterpretResult> onSuccess, @NonNull Consumer<PredictionsException> onError) {
    try {
        // First obtain the dominant language to begin analysis
        final Language dominantLanguage = fetchPredominantLanguage(text);
        final LanguageType language = dominantLanguage.getValue();
        // Actually analyze text in the context of dominant language
        final Sentiment sentiment = fetchSentiment(text, language);
        final List<KeyPhrase> keyPhrases = fetchKeyPhrases(text, language);
        final List<Entity> entities = fetchEntities(text, language);
        final List<Syntax> syntax = fetchSyntax(text, language);
        onSuccess.accept(InterpretResult.builder().language(dominantLanguage).sentiment(sentiment).keyPhrases(keyPhrases).entities(entities).syntax(syntax).build());
    } catch (PredictionsException exception) {
        onError.accept(exception);
    }
}
Also used : Entity(com.amplifyframework.predictions.models.Entity) DominantLanguage(com.amazonaws.services.comprehend.model.DominantLanguage) Language(com.amplifyframework.predictions.models.Language) PredictionsException(com.amplifyframework.predictions.PredictionsException) Syntax(com.amplifyframework.predictions.models.Syntax) LanguageType(com.amplifyframework.predictions.models.LanguageType) Sentiment(com.amplifyframework.predictions.models.Sentiment) KeyPhrase(com.amplifyframework.predictions.models.KeyPhrase)

Example 2 with Language

use of com.amplifyframework.predictions.models.Language in project amplify-android by aws-amplify.

the class AWSPredictionsInterpretTest method testEnglishLanguageDetection.

/**
 * Assert that english text is detected as English.
 * @throws Exception if prediction fails
 */
@Test
public void testEnglishLanguageDetection() throws Exception {
    // Interpret english text and assert non-null result
    final String englishText = Assets.readAsString("sample-text-en.txt");
    InterpretResult result = predictions.interpret(englishText);
    assertNotNull(result);
    // Assert detected language is English
    Language language = result.getLanguage();
    FeatureAssert.assertMatches(LanguageType.ENGLISH, language);
}
Also used : Language(com.amplifyframework.predictions.models.Language) InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Test(org.junit.Test)

Example 3 with Language

use of com.amplifyframework.predictions.models.Language in project amplify-android by aws-amplify.

the class AWSPredictionsInterpretTest method testFrenchLanguageDetection.

/**
 * Assert that english text is detected as French.
 * @throws Exception if prediction fails
 */
@Test
public void testFrenchLanguageDetection() throws Exception {
    // Interpret french text and assert non-null result
    final String frenchText = Assets.readAsString("sample-text-fr.txt");
    InterpretResult result = predictions.interpret(frenchText);
    assertNotNull(result);
    // Assert detected language is French
    Language language = result.getLanguage();
    FeatureAssert.assertMatches(LanguageType.FRENCH, language);
}
Also used : Language(com.amplifyframework.predictions.models.Language) InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Test(org.junit.Test)

Aggregations

Language (com.amplifyframework.predictions.models.Language)3 InterpretResult (com.amplifyframework.predictions.result.InterpretResult)2 Test (org.junit.Test)2 DominantLanguage (com.amazonaws.services.comprehend.model.DominantLanguage)1 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 Entity (com.amplifyframework.predictions.models.Entity)1 KeyPhrase (com.amplifyframework.predictions.models.KeyPhrase)1 LanguageType (com.amplifyframework.predictions.models.LanguageType)1 Sentiment (com.amplifyframework.predictions.models.Sentiment)1 Syntax (com.amplifyframework.predictions.models.Syntax)1