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