in aws-predictions/src/main/java/com/amplifyframework/predictions/aws/AWSPredictionsPluginConfiguration.java [74:138]
static AWSPredictionsPluginConfiguration fromJson(JSONObject configurationJson) throws PredictionsException {
if (configurationJson == null) {
throw new PredictionsException(
"Could not locate predictions configuration for AWS Predictions Plugin.",
"Verify that amplifyconfiguration.json contains a section for \"awsPredictionsPlugin\"."
);
}
final Region defaultRegion;
final SpeechGeneratorConfiguration speechGeneratorConfiguration;
final TranslateTextConfiguration translateTextConfiguration;
final IdentifyLabelsConfiguration identifyLabelsConfiguration;
final IdentifyEntitiesConfiguration identifyEntitiesConfiguration;
final IdentifyTextConfiguration identifyTextConfiguration;
final InterpretTextConfiguration interpretConfiguration;
try {
// Get default region
String regionString = configurationJson.getString(ConfigKey.DEFAULT_REGION.key());
defaultRegion = Region.getRegion(regionString);
if (configurationJson.has(ConfigKey.CONVERT.key())) {
JSONObject convertJson = configurationJson.getJSONObject(ConfigKey.CONVERT.key());
speechGeneratorConfiguration = SpeechGeneratorConfiguration.fromJson(convertJson);
translateTextConfiguration = TranslateTextConfiguration.fromJson(convertJson);
} else {
speechGeneratorConfiguration = null;
translateTextConfiguration = null;
}
if (configurationJson.has(ConfigKey.IDENTIFY.key())) {
JSONObject identifyJson = configurationJson.getJSONObject(ConfigKey.IDENTIFY.key());
identifyLabelsConfiguration = IdentifyLabelsConfiguration.fromJson(identifyJson);
identifyEntitiesConfiguration = IdentifyEntitiesConfiguration.fromJson(identifyJson);
identifyTextConfiguration = IdentifyTextConfiguration.fromJson(identifyJson);
} else {
identifyLabelsConfiguration = null;
identifyEntitiesConfiguration = null;
identifyTextConfiguration = null;
}
if (configurationJson.has(ConfigKey.INTERPRET.key())) {
JSONObject interpretJson = configurationJson.getJSONObject(ConfigKey.INTERPRET.key());
interpretConfiguration = InterpretTextConfiguration.fromJson(interpretJson);
} else {
interpretConfiguration = null;
}
} catch (JSONException | IllegalArgumentException exception) {
throw new PredictionsException(
"Issue encountered while parsing configuration JSON",
exception,
"Check the attached exception for more details."
);
}
return new AWSPredictionsPluginConfiguration(
defaultRegion,
speechGeneratorConfiguration,
translateTextConfiguration,
identifyLabelsConfiguration,
identifyEntitiesConfiguration,
identifyTextConfiguration,
interpretConfiguration
);
}