use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.
the class NLUNuanceHelper method prepareCommand.
/**
* Coerce the parameters into a {@link CommandRequest} object
*
* @param ctx the application context
* @param commandRequest the {@link CommandRequest}
* @param sl the {@link SupportedLanguage}
* @param map the parameters unique to the NLP provider
* @return the populated {@link CommandRequest} object
*/
public CommandRequest prepareCommand(@NonNull final Context ctx, @NonNull final CommandRequest commandRequest, @NonNull final SupportedLanguage sl, @NonNull final Map<String, List<Concept>> map) {
switch(commandRequest.getCC()) {
case COMMAND_UNKNOWN:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_UNKNOWN");
}
break;
case COMMAND_CANCEL:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_CANCEL");
}
break;
case COMMAND_SPELL:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SPELL");
}
final CommandSpellValues csv = new CommandSpellValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.TEXT_TO_SPELL)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SPELL: extraction complete");
}
csv.setText(concept.getLiteral());
csv.setRanges(concept.getRanges());
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(csv);
break;
case COMMAND_TRANSLATE:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TRANSLATE");
}
final CommandTranslateValues ctv = new CommandTranslateValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.TEXT_TO_TRANSLATE)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: TEXT_TO_TRANSLATE");
MyLog.i(CLS_NAME, "prepareCommand: getLiteral: " + concept.getLiteral());
MyLog.i(CLS_NAME, "prepareCommand: getRanges: " + Arrays.deepToString(concept.getRanges()));
}
ctv.setText(concept.getLiteral());
ctv.setTextRanges(concept.getRanges());
} else if (entry.getKey().matches(NLUConstants.LANGUAGE)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: TRANSLATE_LANGUAGE");
MyLog.i(CLS_NAME, "prepareCommand: getLiteral: " + concept.getLiteral());
MyLog.i(CLS_NAME, "prepareCommand: getRanges: " + Arrays.deepToString(concept.getRanges()));
}
ctv.setLanguage(concept.getLiteral().toLowerCase(sl.getLocale()));
ctv.setLanguageRanges(concept.getRanges());
}
if (UtilsString.notNaked(ctv.getLanguage()) && UtilsString.notNaked(ctv.getText())) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TRANSLATE: extraction complete");
}
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(ctv);
break;
case COMMAND_SONG_RECOGNITION:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SONG_RECOGNITION: extraction complete");
}
commandRequest.setResolved(true);
break;
case COMMAND_PARDON:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_PARDON: extraction complete");
}
commandRequest.setResolved(true);
break;
case COMMAND_USER_NAME:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_USER_NAME");
}
final CommandUserNameValues cunv = new CommandUserNameValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.NAME_USER)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_USER_NAME: extraction complete");
}
cunv.setName(concept.getLiteral());
cunv.setRanges(concept.getRanges());
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(cunv);
break;
case COMMAND_BATTERY:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY");
}
final CommandBatteryValues cbv = new CommandBatteryValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.BATTERY_TYPE)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY: extraction complete");
}
cbv.setType(cbv.stringToType(ctx, sl, concept.getLiteral()));
cbv.setTypeString(concept.getLiteral());
cbv.setRanges(concept.getRanges());
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(cbv);
break;
case COMMAND_HOTWORD:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_HOTWORD");
}
commandRequest.setResolved(true);
break;
case COMMAND_EMOTION:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_EMOTION");
}
commandRequest.setResolved(true);
break;
case COMMAND_VOICE_IDENTIFY:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_VOICE_IDENTIFY");
}
commandRequest.setResolved(true);
break;
case COMMAND_TASKER:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TASKER");
}
final CommandTaskerValues taskerValues = new CommandTaskerValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.TASKER_TASK_NAME)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TASKER: extraction complete");
}
taskerValues.setTaskName(concept.getLiteral());
taskerValues.setRanges(concept.getRanges());
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(taskerValues);
break;
case COMMAND_WOLFRAM_ALPHA:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_WOLFRAM_ALPHA");
}
final CommandWolframAlphaValues cwav = new CommandWolframAlphaValues();
for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
final List<Concept> concepts = entry.getValue();
for (final Concept concept : concepts) {
if (entry.getKey().matches(NLUConstants.QUESTION_CONTENT)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_WOLFRAM_ALPHA: extraction complete");
}
cwav.setQuestion(concept.getLiteral());
cwav.setRanges(concept.getRanges());
commandRequest.setResolved(true);
break;
}
}
}
commandRequest.setVariableData(cwav);
break;
case COMMAND_EMPTY_ARRAY:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_EMPTY_ARRAY");
}
break;
case COMMAND_USER_CUSTOM:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_USER_CUSTOM");
}
break;
case COMMAND_SOMETHING_WEIRD:
if (DEBUG) {
MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SOMETHING_WEIRD");
}
break;
}
return commandRequest;
}
Aggregations