Search in sources :

Example 1 with CommandTranslateValues

use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.

the class BingTranslate method getResponse.

/**
 * Resolve the translation request and return the {@link Outcome}
 *
 * @return the created {@link Outcome}
 */
public Outcome getResponse() {
    final CommandTranslateValues ctv = (CommandTranslateValues) cr.getVariableData();
    final TranslationLanguageBing language = resolveLanguage(ctv.getLanguage());
    if (language != TranslationLanguageBing.AUTO_DETECT) {
        String translationRequest = ctv.getText();
        if (DEBUG) {
            MyLog.d(CLS_NAME, "language: " + language.name());
            MyLog.d(CLS_NAME, "request: " + translationRequest);
        }
        if (ClipboardHelper.isClipboard(mContext, translationRequest)) {
            try {
                Thread.sleep(CLIPBOARD_DELAY);
            } catch (final InterruptedException e) {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "InterruptedException");
                    e.printStackTrace();
                }
            }
            final Pair<Boolean, String> clipboardPair = ClipboardHelper.getClipboardContentPair(mContext, sl);
            if (clipboardPair.first) {
                translationRequest = clipboardPair.second;
            } else {
                outcome.setUtterance(clipboardPair.second);
                outcome.setOutcome(Outcome.FAILURE);
                return outcome;
            }
        }
        if (!tooLong(translationRequest)) {
            final Pair<Boolean, String> translationResult = execute(mContext, language, translationRequest);
            if (translationResult.first) {
                outcome.setUtterance(translationResult.second);
                outcome.setOutcome(Outcome.SUCCESS);
                final EntangledPair entangledPair = new EntangledPair(Position.TOAST_LONG, CC.COMMAND_TRANSLATE);
                entangledPair.setToastContent(translationResult.second);
                outcome.setEntangledPair(entangledPair);
                final Qubit qubit = new Qubit();
                qubit.setTranslatedText(translationResult.second);
                outcome.setQubit(qubit);
                outcome.setTTSLocale(language.getLocale());
            } else {
                outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate, PersonalityHelper.getUserNameOrNot(mContext)));
                outcome.setOutcome(Outcome.FAILURE);
                return outcome;
            }
        } else {
            outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate_length, PersonalityHelper.getUserNameOrNot(mContext)));
            outcome.setOutcome(Outcome.FAILURE);
            return outcome;
        }
    } else {
        outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate_unsupported, PersonalityHelper.getUserNameOrNot(mContext)));
        outcome.setOutcome(Outcome.FAILURE);
        return outcome;
    }
    return outcome;
}
Also used : CommandTranslateValues(ai.saiy.android.command.translate.CommandTranslateValues) Qubit(ai.saiy.android.processing.Qubit) EntangledPair(ai.saiy.android.processing.EntangledPair) UtilsString(ai.saiy.android.utils.UtilsString)

Example 2 with CommandTranslateValues

use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.

the class NLUAPIAIHelper 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 parameters     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 HashMap<String, JsonElement> parameters) {
    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();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.TEXT_TO_SPELL)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SPELL: extraction complete");
                    }
                    csv.setText(parameters.get(NLUConstants.TEXT_TO_SPELL).getAsString());
                    commandRequest.setResolved(true);
                }
            }
            commandRequest.setVariableData(csv);
            break;
        case COMMAND_TRANSLATE:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TRANSLATE");
            }
            final CommandTranslateValues ctv = new CommandTranslateValues();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.LANGUAGE) && parameters.containsKey(NLUConstants.TEXT_TO_TRANSLATE)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TRANSLATE: extraction complete");
                    }
                    ctv.setText(parameters.get(NLUConstants.TEXT_TO_TRANSLATE).getAsString());
                    ctv.setLanguage(parameters.get(NLUConstants.LANGUAGE).getAsString());
                    commandRequest.setResolved(true);
                }
            }
            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();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.NAME_USER)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_USER_NAME: extraction complete");
                    }
                    cunv.setName(parameters.get(NLUConstants.NAME_USER).getAsString());
                    commandRequest.setResolved(true);
                }
            }
            commandRequest.setVariableData(cunv);
            break;
        case COMMAND_BATTERY:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY");
            }
            final CommandBatteryValues cbv = new CommandBatteryValues();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.BATTERY_TYPE)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY: extraction complete");
                    }
                    cbv.setTypeString(parameters.get(NLUConstants.BATTERY_TYPE).getAsString());
                    cbv.setType(cbv.stringToType(ctx, sl, parameters.get(NLUConstants.BATTERY_TYPE).getAsString()));
                    commandRequest.setResolved(true);
                }
            }
            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();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.TASKER_TASK_NAME)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TASKER: extraction complete");
                    }
                    taskerValues.setTaskName(parameters.get(NLUConstants.TASKER_TASK_NAME).getAsString());
                    commandRequest.setResolved(true);
                }
            }
            commandRequest.setVariableData(taskerValues);
            break;
        case COMMAND_WOLFRAM_ALPHA:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_WOLFRAM_ALPHA");
            }
            final CommandWolframAlphaValues cwav = new CommandWolframAlphaValues();
            if (UtilsMap.notNaked(parameters)) {
                if (parameters.containsKey(NLUConstants.QUESTION_CONTENT)) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_WOLFRAM_ALPHA: extraction complete");
                    }
                    cwav.setQuestion(parameters.get(NLUConstants.QUESTION_CONTENT).getAsString());
                    commandRequest.setResolved(true);
                }
            }
            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;
}
Also used : CommandTranslateValues(ai.saiy.android.command.translate.CommandTranslateValues) CommandSpellValues(ai.saiy.android.command.spell.CommandSpellValues) CommandWolframAlphaValues(ai.saiy.android.command.wolframalpha.CommandWolframAlphaValues) CommandTaskerValues(ai.saiy.android.command.tasker.CommandTaskerValues) CommandBatteryValues(ai.saiy.android.command.battery.CommandBatteryValues) CommandUserNameValues(ai.saiy.android.command.username.CommandUserNameValues)

Example 3 with CommandTranslateValues

use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.

the class NLUMicrosoftHelper 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 entities       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 List<Entity> entities) {
    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_SONG_RECOGNITION:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SONG_RECOGNITION: extraction complete");
            }
            commandRequest.setResolved(true);
            break;
        case COMMAND_SPELL:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SPELL");
            }
            final CommandSpellValues csv = new CommandSpellValues();
            for (final Entity e : entities) {
                if (e.getType().matches(NLUConstants.TEXT_TO_SPELL)) {
                    csv.setText(e.getEntity());
                    csv.setStartIndex(e.getStartIndex());
                    csv.setEndIndex(e.getEndIndex());
                    commandRequest.setResolved(true);
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_SPELL: extraction complete");
                    }
                    break;
                }
            }
            commandRequest.setVariableData(csv);
            break;
        case COMMAND_TRANSLATE:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TRANSLATE");
            }
            final CommandTranslateValues ctv = new CommandTranslateValues();
            for (final Entity e : entities) {
                if (e.getType().matches(NLUConstants.TRANSLATE_LANGUAGE)) {
                    ctv.setLanguage(e.getEntity());
                    ctv.setLanguageStartIndex(e.getStartIndex());
                    ctv.setLanguageEndIndex(e.getEndIndex());
                } else if (e.getType().matches(NLUConstants.TEXT_TO_TRANSLATE)) {
                    ctv.setText(e.getEntity());
                    ctv.setTextStartIndex(e.getStartIndex());
                    ctv.setTextEndIndex(e.getEndIndex());
                }
                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_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 Entity e : entities) {
                if (e.getType().matches(NLUConstants.NAME_USER)) {
                    cunv.setName(e.getEntity());
                    cunv.setStartIndex(e.getStartIndex());
                    cunv.setEndIndex(e.getEndIndex());
                    commandRequest.setResolved(true);
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_USER_NAME: extraction complete");
                    }
                    break;
                }
            }
            commandRequest.setVariableData(cunv);
            break;
        case COMMAND_BATTERY:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY");
            }
            final CommandBatteryValues cbv = new CommandBatteryValues();
            for (final Entity e : entities) {
                if (e.getType().matches(NLUConstants.BATTERY_TYPE)) {
                    cbv.setType(cbv.stringToType(ctx, sl, e.getEntity()));
                    cbv.setTypeString(e.getEntity());
                    cbv.setStartIndex(e.getStartIndex());
                    cbv.setEndIndex(e.getEndIndex());
                    commandRequest.setResolved(true);
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_BATTERY: extraction complete");
                    }
                    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 Entity e : entities) {
                if (e.getType().matches(NLUConstants.TASKER_TASK_NAME)) {
                    taskerValues.setTaskName(e.getEntity());
                    taskerValues.setStartIndex(e.getStartIndex());
                    taskerValues.setEndIndex(e.getEndIndex());
                    commandRequest.setResolved(true);
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_TASKER: extraction complete");
                    }
                    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 Entity e : entities) {
                if (e.getType().matches(NLUConstants.QUESTION_CONTENT)) {
                    cwav.setQuestion(e.getEntity());
                    cwav.setStartIndex(e.getStartIndex());
                    cwav.setEndIndex(e.getEndIndex());
                    commandRequest.setResolved(true);
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "prepareCommand: COMMAND_WOLFRAM_ALPHA: extraction complete");
                    }
                    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;
}
Also used : CommandTranslateValues(ai.saiy.android.command.translate.CommandTranslateValues) CommandSpellValues(ai.saiy.android.command.spell.CommandSpellValues) CommandWolframAlphaValues(ai.saiy.android.command.wolframalpha.CommandWolframAlphaValues) CommandTaskerValues(ai.saiy.android.command.tasker.CommandTaskerValues) CommandBatteryValues(ai.saiy.android.command.battery.CommandBatteryValues) CommandUserNameValues(ai.saiy.android.command.username.CommandUserNameValues)

Example 4 with CommandTranslateValues

use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.

the class NLUSaiyHelper 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 entities       the parameters unique to the NLP provider
 * @return the populated {@link CommandRequest} object
 */
public CommandRequest prepareCommand(@NonNull final android.content.Context ctx, @NonNull final CommandRequest commandRequest, @NonNull final SupportedLanguage sl, @NonNull final List<Entity> entities) {
    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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.NAME_USER)) {
                    csv.setText(e.getValue());
                    csv.setStartIndex(e.getIndex()[0]);
                    csv.setEndIndex(e.getIndex()[1]);
                    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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.TRANSLATE_LANGUAGE)) {
                    ctv.setLanguage(e.getValue());
                    ctv.setLanguageStartIndex(e.getIndex()[0]);
                    ctv.setLanguageEndIndex(e.getIndex()[1]);
                } else if (e.getName().matches(NLUConstants.TEXT_TO_TRANSLATE)) {
                    ctv.setText(e.getValue());
                    ctv.setTextStartIndex(e.getIndex()[0]);
                    ctv.setTextEndIndex(e.getIndex()[1]);
                }
                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");
            }
            commandRequest.setResolved(true);
            break;
        case COMMAND_PARDON:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "prepareCommand: COMMAND_PARDON");
            }
            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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.NAME_USER)) {
                    cunv.setName(e.getValue());
                    cunv.setStartIndex(e.getIndex()[0]);
                    cunv.setEndIndex(e.getIndex()[1]);
                    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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.BATTERY_TYPE)) {
                    cbv.setTypeString(e.getValue());
                    cbv.setType(cbv.stringToType(ctx, sl, e.getValue()));
                    cbv.setStartIndex(e.getIndex()[0]);
                    cbv.setEndIndex(e.getIndex()[1]);
                    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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.TASKER_TASK_NAME)) {
                    taskerValues.setTaskName(e.getValue());
                    taskerValues.setStartIndex(e.getIndex()[0]);
                    taskerValues.setEndIndex(e.getIndex()[1]);
                    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 Entity e : entities) {
                if (e.getName().matches(NLUConstants.QUESTION_CONTENT)) {
                    cwav.setQuestion(e.getValue());
                    cwav.setStartIndex(e.getIndex()[0]);
                    cwav.setEndIndex(e.getIndex()[1]);
                    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;
}
Also used : CommandTranslateValues(ai.saiy.android.command.translate.CommandTranslateValues) CommandSpellValues(ai.saiy.android.command.spell.CommandSpellValues) CommandWolframAlphaValues(ai.saiy.android.command.wolframalpha.CommandWolframAlphaValues) CommandTaskerValues(ai.saiy.android.command.tasker.CommandTaskerValues) CommandBatteryValues(ai.saiy.android.command.battery.CommandBatteryValues) CommandUserNameValues(ai.saiy.android.command.username.CommandUserNameValues)

Example 5 with CommandTranslateValues

use of ai.saiy.android.command.translate.CommandTranslateValues in project Saiy-PS by brandall76.

the class GoogleTranslate method getResponse.

/**
 * Resolve the translation request and return the {@link Outcome}
 *
 * @return the created {@link Outcome}
 */
public Outcome getResponse() {
    final CommandTranslateValues ctv = (CommandTranslateValues) cr.getVariableData();
    final TranslationLanguageGoogle language = resolveLanguage(ctv.getLanguage());
    if (language != TranslationLanguageGoogle.AUTO_DETECT) {
        String translationRequest = ctv.getText();
        if (DEBUG) {
            MyLog.d(CLS_NAME, "language: " + language.name());
            MyLog.d(CLS_NAME, "request: " + translationRequest);
        }
        if (ClipboardHelper.isClipboard(mContext, translationRequest)) {
            try {
                Thread.sleep(CLIPBOARD_DELAY);
            } catch (final InterruptedException e) {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "InterruptedException");
                    e.printStackTrace();
                }
            }
            final Pair<Boolean, String> clipboardPair = ClipboardHelper.getClipboardContentPair(mContext, sl);
            if (clipboardPair.first) {
                translationRequest = clipboardPair.second;
            } else {
                outcome.setUtterance(clipboardPair.second);
                outcome.setOutcome(Outcome.FAILURE);
                return outcome;
            }
        }
        if (!tooLong(translationRequest)) {
            final Pair<Boolean, String> translationResult = execute(mContext, language, translationRequest);
            if (translationResult.first) {
                outcome.setUtterance(translationResult.second);
                outcome.setOutcome(Outcome.SUCCESS);
                final EntangledPair entangledPair = new EntangledPair(Position.TOAST_LONG, CC.COMMAND_TRANSLATE);
                entangledPair.setToastContent(translationResult.second);
                outcome.setEntangledPair(entangledPair);
                final Qubit qubit = new Qubit();
                qubit.setTranslatedText(translationResult.second);
                outcome.setQubit(qubit);
                outcome.setTTSLocale(UtilsLocale.stringToLocale(language.getLanguage()));
            } else {
                outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate, PersonalityHelper.getUserNameOrNot(mContext)));
                outcome.setOutcome(Outcome.FAILURE);
                return outcome;
            }
        } else {
            outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate_length, PersonalityHelper.getUserNameOrNot(mContext)));
            outcome.setOutcome(Outcome.FAILURE);
            return outcome;
        }
    } else {
        outcome.setUtterance(mContext.getString(ai.saiy.android.R.string.error_translate_unsupported, PersonalityHelper.getUserNameOrNot(mContext)));
        outcome.setOutcome(Outcome.FAILURE);
        return outcome;
    }
    return outcome;
}
Also used : CommandTranslateValues(ai.saiy.android.command.translate.CommandTranslateValues) Qubit(ai.saiy.android.processing.Qubit) EntangledPair(ai.saiy.android.processing.EntangledPair) UtilsString(ai.saiy.android.utils.UtilsString)

Aggregations

CommandTranslateValues (ai.saiy.android.command.translate.CommandTranslateValues)6 CommandBatteryValues (ai.saiy.android.command.battery.CommandBatteryValues)4 CommandSpellValues (ai.saiy.android.command.spell.CommandSpellValues)4 CommandTaskerValues (ai.saiy.android.command.tasker.CommandTaskerValues)4 CommandUserNameValues (ai.saiy.android.command.username.CommandUserNameValues)4 CommandWolframAlphaValues (ai.saiy.android.command.wolframalpha.CommandWolframAlphaValues)4 UtilsString (ai.saiy.android.utils.UtilsString)3 EntangledPair (ai.saiy.android.processing.EntangledPair)2 Qubit (ai.saiy.android.processing.Qubit)2 List (java.util.List)1 Map (java.util.Map)1