use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.
the class IdentifyEntitiesConfiguration method fromJson.
/**
* Construct an instance of {@link IdentifyEntitiesConfiguration} from
* plugin configuration JSON object.
* @param configurationJson the plugin configuration
* @return the configuration for entities detection
* @throws JSONException if identify configuration is malformed
*/
@Nullable
public static IdentifyEntitiesConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
if (!configurationJson.has(CONFIG_NAME)) {
return null;
}
// Required fields
JSONObject identifyEntitiesJson = configurationJson.getJSONObject(CONFIG_NAME);
String celebEnabledString = identifyEntitiesJson.getString("celebrityDetectionEnabled");
String networkPolicyString = identifyEntitiesJson.getString("defaultNetworkPolicy");
boolean celebEnabled = Boolean.parseBoolean(celebEnabledString);
NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
// Optional fields
int maxEntities;
boolean isGeneralEntityDetection;
String collectionId;
try {
String maxEntitiesString = identifyEntitiesJson.getString("maxEntities");
collectionId = identifyEntitiesJson.getString("collectionId");
maxEntities = Integer.parseInt(maxEntitiesString);
isGeneralEntityDetection = maxEntities < 1 || maxEntities > MAX_VALID_ENTITIES;
} catch (JSONException | IllegalArgumentException exception) {
collectionId = "";
maxEntities = 0;
isGeneralEntityDetection = true;
}
return new IdentifyEntitiesConfiguration(maxEntities, collectionId, isGeneralEntityDetection, celebEnabled, networkPolicy);
}
use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.
the class InterpretTextConfiguration method fromJson.
/**
* Construct an instance of {@link InterpretTextConfiguration} from
* plugin configuration JSON object.
* @param configurationJson the plugin configuration
* @return the configuration for text interpretation
* @throws JSONException if interpret configuration is malformed
*/
@Nullable
public static InterpretTextConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
if (!configurationJson.has(CONFIG_NAME)) {
return null;
}
JSONObject interpretTextJson = configurationJson.getJSONObject(CONFIG_NAME);
String typeString = interpretTextJson.getString("type");
String networkPolicyString = interpretTextJson.getString("defaultNetworkPolicy");
final InterpretType type = InterpretType.valueOf(typeString);
final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
return new InterpretTextConfiguration(type, networkPolicy);
}
use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.
the class TranslateTextConfiguration method fromJson.
/**
* Construct an instance of {@link TranslateTextConfiguration} from
* plugin configuration JSON object.
* @param configurationJson the plugin configuration
* @return the configuration for text translation
* @throws JSONException if translate configuration is malformed
*/
@Nullable
public static TranslateTextConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
if (!configurationJson.has(CONFIG_NAME)) {
return null;
}
JSONObject translateTextJson = configurationJson.getJSONObject(CONFIG_NAME);
String sourceLangCode = translateTextJson.getString("sourceLang");
String targetLangCode = translateTextJson.getString("targetLang");
String networkPolicyString = translateTextJson.getString("defaultNetworkPolicy");
final LanguageType sourceLanguage = LanguageType.from(sourceLangCode);
final LanguageType targetLanguage = LanguageType.from(targetLangCode);
final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
return new TranslateTextConfiguration(sourceLanguage, targetLanguage, networkPolicy);
}
use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.
the class IdentifyLabelsConfiguration method fromJson.
/**
* Construct an instance of {@link IdentifyLabelsConfiguration} from
* plugin configuration JSON object.
* @param configurationJson the plugin configuration
* @return the configuration for label identification
* @throws JSONException if identify configuration is malformed
*/
@Nullable
public static IdentifyLabelsConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
if (!configurationJson.has(CONFIG_NAME)) {
return null;
}
JSONObject identifyLabelsJson = configurationJson.getJSONObject(CONFIG_NAME);
String typeString = identifyLabelsJson.getString("type");
String networkPolicyString = identifyLabelsJson.getString("defaultNetworkPolicy");
final LabelType type = LabelType.valueOf(typeString);
final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
return new IdentifyLabelsConfiguration(type, networkPolicy);
}
use of com.amplifyframework.predictions.aws.NetworkPolicy in project amplify-android by aws-amplify.
the class IdentifyTextConfiguration method fromJson.
/**
* Construct an instance of {@link IdentifyTextConfiguration} from
* plugin configuration JSON object.
* @param configurationJson the plugin configuration
* @return the configuration for text identification
* @throws JSONException if identify configuration is malformed
*/
@Nullable
public static IdentifyTextConfiguration fromJson(@NonNull JSONObject configurationJson) throws JSONException {
if (!configurationJson.has(CONFIG_NAME)) {
return null;
}
JSONObject identifyLabelsJson = configurationJson.getJSONObject(CONFIG_NAME);
String formatString = identifyLabelsJson.getString("format");
String networkPolicyString = identifyLabelsJson.getString("defaultNetworkPolicy");
final TextFormatType format = TextFormatType.valueOf(formatString);
final NetworkPolicy networkPolicy = NetworkPolicy.fromKey(networkPolicyString);
return new IdentifyTextConfiguration(format, networkPolicy);
}
Aggregations