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);
}
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);
}
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);
}
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);
}
Aggregations