Search in sources :

Example 6 with InterpretResult

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

the class AWSPredictionsInterpretTest method testEntityDetection.

/**
 * Assert that entities are detected.
 * @throws Exception if prediction fails
 */
@Test
public void testEntityDetection() throws Exception {
    final String sampleText = "Toto, I've a feeling we're not in Kansas anymore.";
    // Interpret sample text and assert non-null result
    InterpretResult result = predictions.interpret(sampleText);
    assertNotNull(result);
    // Assert entities detection
    List<Entity> actual = result.getEntities();
    List<EntityType> expected = Arrays.asList(// Toto (it's a dog, but close enough)
    EntityType.PERSON, // Kansas
    EntityType.LOCATION);
    FeatureAssert.assertMatches(expected, actual);
}
Also used : EntityType(com.amplifyframework.predictions.models.EntityType) Entity(com.amplifyframework.predictions.models.Entity) InterpretResult(com.amplifyframework.predictions.result.InterpretResult) Test(org.junit.Test)

Example 7 with InterpretResult

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

the class AWSPredictionsInterpretTest method testPositiveSentimentDetection.

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

Example 8 with InterpretResult

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

the class AWSPredictionsInterpretTest method testKeyPhraseDetection.

/**
 * Assert that key phrases are detected.
 * @throws Exception if prediction fails
 */
@Test
public void testKeyPhraseDetection() throws Exception {
    final String sampleText = "My mama always said life was like a box of chocolates.";
    // Interpret sample text and assert non-null result
    InterpretResult result = predictions.interpret(sampleText);
    assertNotNull(result);
    // Assert key phrase detection
    List<KeyPhrase> actual = result.getKeyPhrases();
    List<String> expected = Arrays.asList("My mama", "life", "a box", "chocolates");
    FeatureAssert.assertMatches(expected, actual);
}
Also used : InterpretResult(com.amplifyframework.predictions.result.InterpretResult) KeyPhrase(com.amplifyframework.predictions.models.KeyPhrase) Test(org.junit.Test)

Example 9 with InterpretResult

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

the class RxPredictionsBindingTest method testSuccessfulTextInterpretation.

/**
 * When the delegate of {@link RxPredictionsBinding#interpret(String)} emits a result,
 * it should be propagated via the returned {@link Single}.
 * @throws InterruptedException If interrupted while test observer is awaiting terminal event
 */
@Test
public void testSuccessfulTextInterpretation() throws InterruptedException {
    String text = RandomString.string();
    InterpretResult result = InterpretResult.builder().build();
    doAnswer(invocation -> {
        // 0 = text, 1 = result, 2 = error
        final int indexOfResultConsumer = 1;
        Consumer<InterpretResult> onResult = invocation.getArgument(indexOfResultConsumer);
        onResult.accept(result);
        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.assertValue(result);
}
Also used : RandomString(com.amplifyframework.testutils.random.RandomString) 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