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