Search in sources :

Example 1 with InterpretResult

use of com.amplifyframework.predictions.result.InterpretResult in project amplify-android by aws-amplify.

the class AWSPredictionsInterpretTest method testSyntaxDetection.

/**
 * Assert that interpret correctly labels syntax.
 * @throws Exception if prediction fails
 */
@Test
public void testSyntaxDetection() throws Exception {
    final String sampleText = "I am inevitable.";
    // Interpret sample text and assert non-null result
    InterpretResult result = predictions.interpret(sampleText);
    assertNotNull(result);
    // Assert syntax detection
    List<Syntax> actual = result.getSyntax();
    List<SpeechType> expected = Arrays.asList(// I
    SpeechType.PRONOUN, // am
    SpeechType.VERB, // inevitable
    SpeechType.ADJECTIVE, // .
    SpeechType.PUNCTUATION);
    FeatureAssert.assertMatches(expected, actual);
}
Also used : SpeechType(com.amplifyframework.predictions.models.SpeechType) InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Syntax(com.amplifyframework.predictions.models.Syntax) Test(org.junit.Test)

Example 2 with InterpretResult

use of com.amplifyframework.predictions.result.InterpretResult in project amplify-android by aws-amplify.

the class AWSPredictionsInterpretTest method testNegativeSentimentDetection.

/**
 * Assert that unhappy review is detected as negative.
 * @throws Exception if prediction fails
 */
@Test
public void testNegativeSentimentDetection() throws Exception {
    // Interpret negative text and assert non-null result
    final String negativeReview = Assets.readAsString("negative-review.txt");
    InterpretResult result = predictions.interpret(negativeReview);
    assertNotNull(result);
    // Assert detected sentiment is negative
    Sentiment sentiment = result.getSentiment();
    FeatureAssert.assertMatches(SentimentType.NEGATIVE, sentiment);
}
Also used : InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Sentiment(com.amplifyframework.predictions.models.Sentiment) Test(org.junit.Test)

Example 3 with InterpretResult

use of com.amplifyframework.predictions.result.InterpretResult in project amplify-android by aws-amplify.

the class RxPredictionsBindingTest method testFailedTextInterpretation.

/**
 * When the delegate of {@link RxPredictionsBinding#interpret(String)} emits a failure,
 * it should be propagated via the returned {@link Single}.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void testFailedTextInterpretation() throws InterruptedException {
    String text = RandomString.string();
    PredictionsException predictionsException = new PredictionsException("Uh", "Oh");
    doAnswer(invocation -> {
        // 0 = text, 1 = result, 2 = error
        final int indexOfFailureConsumer = 2;
        Consumer<PredictionsException> onFailure = invocation.getArgument(indexOfFailureConsumer);
        onFailure.accept(predictionsException);
        return mock(InterpretOperation.class);
    }).when(delegate).interpret(eq(text), anyConsumer(), anyConsumer());
    TestObserver<InterpretResult> observer = rxPredictions.interpret(text).test();
    observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
    observer.assertError(predictionsException);
}
Also used : PredictionsException(com.amplifyframework.predictions.PredictionsException) RandomString(com.amplifyframework.testutils.random.RandomString) InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Test(org.junit.Test)

Example 4 with InterpretResult

use of com.amplifyframework.predictions.result.InterpretResult 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 5 with InterpretResult

use of com.amplifyframework.predictions.result.InterpretResult 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

InterpretResult (com.amplifyframework.predictions.result.InterpretResult)9 Test (org.junit.Test)9 Language (com.amplifyframework.predictions.models.Language)2 Sentiment (com.amplifyframework.predictions.models.Sentiment)2 RandomString (com.amplifyframework.testutils.random.RandomString)2 PredictionsException (com.amplifyframework.predictions.PredictionsException)1 Entity (com.amplifyframework.predictions.models.Entity)1 EntityType (com.amplifyframework.predictions.models.EntityType)1 KeyPhrase (com.amplifyframework.predictions.models.KeyPhrase)1 SpeechType (com.amplifyframework.predictions.models.SpeechType)1 Syntax (com.amplifyframework.predictions.models.Syntax)1