use of ai.saiy.android.custom.CustomResolver in project Saiy-PS by brandall76.
the class Quantum method doTunnelling.
@Override
protected Qubit doTunnelling(final CommandRequest cr) {
if (DEBUG) {
MyLog.i(CLS_NAME, "doTunnelling");
}
Qubit qubit = null;
if (DEBUG) {
MyLog.i(CLS_NAME, "voiceData before: " + cr.getResultsArray().toString());
}
final CustomResolver customResolver = new QuantumHelper().resolve(mContext, sl, cr);
final ArrayList<String> toResolve = customResolver.getVoiceData();
if (customResolver.isCustom()) {
cch = customResolver.getCustomCommandHelper();
COMMAND = cch.getCommandConstant();
} else if (UtilsList.notNaked(toResolve)) {
final float[] confidence = cr.getConfidenceArray();
final SaiyDefaults.LanguageModel languageModel = SPH.getDefaultLanguageModel(mContext);
switch(languageModel) {
case LOCAL:
if (DEBUG) {
MyLog.i(CLS_NAME, "LanguageModel LOCAL");
}
COMMAND = new FrequencyAnalysis(new Resolve(mContext, toResolve, confidence, sl).resolve()).analyse();
break;
default:
if (DEBUG) {
MyLog.i(CLS_NAME, "LanguageModel EXTERNAL");
}
COMMAND = cr.getCC();
if (CommandRequest.inError(COMMAND)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "LanguageModelDefault.EXTERNAL inError: reverting to LOCAL");
}
COMMAND = new FrequencyAnalysis(new Resolve(mContext, toResolve, confidence, sl).resolve()).analyse();
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "LanguageModelDefault.EXTERNAL: populated");
}
}
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "toResolve naked");
}
COMMAND = CC.COMMAND_EMPTY_ARRAY;
}
final Outcome outcome;
request.setCommand(COMMAND);
if (Network.networkProceed(mContext, COMMAND)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "DT networkProceed passed");
MyLog.i(CLS_NAME, "DT command secure: " + COMMAND.isSecure());
MyLog.i(CLS_NAME, "DT command requested securely: " + cr.wasSecure());
MyLog.i(CLS_NAME, "DT device secure: " + UtilsDevice.isDeviceLocked(this.mContext));
}
secure = COMMAND.isSecure() && cr.wasSecure() && UtilsDevice.isDeviceLocked(this.mContext);
switch(COMMAND) {
case COMMAND_CANCEL:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_CANCEL.name());
}
request.setUtterance(PersonalityResponse.getCancelled(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
break;
case COMMAND_SPELL:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_SPELL.name());
}
outcome = new CommandSpell().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
qubit = outcome.getQubit();
publishProgress(outcome.getEntangledPair());
break;
case COMMAND_TRANSLATE:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_TRANSLATE.name());
}
outcome = new CommandTranslate().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setTTSLocale(outcome.getTTSLocale());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
if (result == Outcome.SUCCESS) {
request.setCondition(Condition.CONDITION_TRANSLATION);
publishProgress(outcome.getEntangledPair());
qubit = outcome.getQubit();
}
break;
case COMMAND_PARDON:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_PARDON.name());
}
final Memory memory = MemoryHelper.getMemory(mContext);
if (!secure) {
request.setUtterance(memory.getUtterance());
request.setTTSLocale(UtilsLocale.stringToLocale(memory.getTTSLanguage()));
request.setVRLocale(UtilsLocale.stringToLocale(memory.getVRLanguage()));
request.setAction(memory.getAction());
request.setUtteranceArray(memory.getUtteranceArray());
result = Outcome.SUCCESS;
switch(memory.getCondition()) {
case Condition.CONDITION_TRANSLATION:
request.setCondition(Condition.CONDITION_TRANSLATION);
break;
case Condition.CONDITION_NONE:
case Condition.CONDITION_CONVERSATION:
case Condition.CONDITION_ROOT:
case Condition.CONDITION_USER_CUSTOM:
case Condition.CONDITION_EMOTION:
case Condition.CONDITION_IDENTITY:
case Condition.CONDITION_GOOGLE_NOW:
case Condition.CONDITION_IGNORE:
default:
request.setCondition(Condition.CONDITION_IGNORE);
break;
}
} else {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(PersonalityResponse.getSecureErrorResponse(mContext, sl));
result = Outcome.SUCCESS;
}
break;
case COMMAND_USER_NAME:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_USER_NAME.name());
}
outcome = new CommandUserName().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
break;
case COMMAND_BATTERY:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_BATTERY.name());
}
outcome = new CommandBattery().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
break;
case COMMAND_SONG_RECOGNITION:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_SONG_RECOGNITION.name());
}
outcome = new CommandSongRecognition().getResponse(mContext, toResolve, sl);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
qubit = outcome.getQubit();
break;
case COMMAND_WOLFRAM_ALPHA:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_WOLFRAM_ALPHA.name());
}
outcome = new CommandWolframAlpha().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
break;
case COMMAND_TASKER:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_TASKER.name());
}
if (!secure) {
outcome = new CommandTasker().getResponse(mContext, toResolve, sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
result = outcome.getOutcome();
} else {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(PersonalityResponse.getSecureErrorResponse(mContext, sl));
result = Outcome.SUCCESS;
}
break;
case COMMAND_EMOTION:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_EMOTION.name());
}
if (!secure) {
outcome = new CommandEmotion().getResponse(mContext, sl);
request.setUtterance(outcome.getUtterance());
request.setAction(LocalRequest.ACTION_SPEAK_LISTEN);
request.setCondition(Condition.CONDITION_EMOTION);
result = outcome.getOutcome();
} else {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(PersonalityResponse.getSecureErrorResponse(mContext, sl));
result = Outcome.SUCCESS;
}
break;
case COMMAND_HOTWORD:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_HOTWORD.name());
}
// noinspection NewApi
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !PermissionHelper.checkUsageStatsPermission(mContext)) {
if (ExecuteIntent.settingsIntent(mContext, IntentConstants.SETTINGS_USAGE_STATS)) {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(SaiyResourcesHelper.getStringResource(mContext, sl, R.string.app_speech_usage_stats));
} else {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(SaiyResourcesHelper.getStringResource(mContext, sl, R.string.issue_usage_stats_bug));
}
} else {
request.setAction(LocalRequest.ACTION_TOGGLE_HOTWORD);
}
result = Outcome.SUCCESS;
break;
case COMMAND_VOICE_IDENTIFY:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_VOICE_IDENTIFY.name());
}
outcome = new CommandVocalRecognition().getResponse(mContext, sl);
result = outcome.getOutcome();
request.setUtterance(outcome.getUtterance());
if (result == Outcome.SUCCESS) {
request.setAction(LocalRequest.ACTION_SPEAK_LISTEN);
request.setCondition(Condition.CONDITION_IDENTIFY);
request.setIdentityProfile((String) outcome.getExtra());
} else {
qubit = outcome.getQubit();
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
}
break;
case COMMAND_UNKNOWN:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_UNKNOWN.name());
}
final int unknownAction = SPH.getCommandUnknownAction(mContext);
switch(unknownAction) {
case Unknown.UNKNOWN_STATE:
case Unknown.UNKNOWN_REPEAT:
if (SPH.getToastUnknown(mContext)) {
final EntangledPair entangledPair = new EntangledPair(Position.TOAST_SHORT, CC.COMMAND_UNKNOWN);
entangledPair.setToastContent(toResolve.get(0) + "??");
publishProgress(entangledPair);
}
break;
}
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
switch(unknownAction) {
case Unknown.UNKNOWN_STATE:
if (DEBUG) {
MyLog.i(CLS_NAME, "Unknown.UNKNOWN_STATE");
}
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
break;
case Unknown.UNKNOWN_REPEAT:
if (DEBUG) {
MyLog.i(CLS_NAME, "Unknown.UNKNOWN_STATE");
}
request.setUtterance(PersonalityResponse.getRepeatCommand(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_LISTEN);
break;
case Unknown.UNKNOWN_GOOGLE_SEARCH:
if (DEBUG) {
MyLog.i(CLS_NAME, "Unknown.UNKNOWN_STATE");
}
if (!ExecuteIntent.googleNow(mContext, toResolve.get(0))) {
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
SPH.setCommandUnknownAction(mContext, Unknown.UNKNOWN_STATE);
final EntangledPair entangledPair = new EntangledPair(Position.TOAST_SHORT, CC.COMMAND_UNKNOWN);
entangledPair.setToastContent(mContext.getString(R.string.error_google_now_broadcast));
publishProgress(entangledPair);
}
break;
case Unknown.UNKNOWN_WOLFRAM_ALPHA:
if (DEBUG) {
MyLog.i(CLS_NAME, "Unknown.UNKNOWN_STATE");
}
if (!ExecuteIntent.wolframAlpha(mContext, toResolve.get(0))) {
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
SPH.setCommandUnknownAction(mContext, Unknown.UNKNOWN_STATE);
final EntangledPair entangledPair = new EntangledPair(Position.TOAST_SHORT, CC.COMMAND_UNKNOWN);
entangledPair.setToastContent(mContext.getString(R.string.error_wolfram_alpha_broadcast));
publishProgress(entangledPair);
}
break;
case Unknown.UNKNOWN_TASKER:
if (DEBUG) {
MyLog.i(CLS_NAME, "Unknown.UNKNOWN_STATE");
}
if (!TaskerHelper.broadcastVoiceData(mContext, toResolve)) {
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
SPH.setCommandUnknownAction(mContext, Unknown.UNKNOWN_STATE);
final EntangledPair entangledPair = new EntangledPair(Position.TOAST_SHORT, CC.COMMAND_UNKNOWN);
entangledPair.setToastContent(mContext.getString(R.string.error_tasker_broadcast));
publishProgress(entangledPair);
}
break;
}
break;
case COMMAND_EMPTY_ARRAY:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_EMPTY_ARRAY.name());
}
request.setUtterance(PersonalityResponse.getErrorProfanityFilter(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
break;
case COMMAND_USER_CUSTOM:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_USER_CUSTOM.name());
}
if (!secure) {
outcome = new CommandCustom().getResponse(mContext, cch.getCommand(), sl, cr);
request.setUtterance(outcome.getUtterance());
request.setAction(outcome.getAction());
result = outcome.getOutcome();
} else {
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setUtterance(PersonalityResponse.getSecureErrorResponse(mContext, sl));
result = Outcome.SUCCESS;
}
break;
case COMMAND_SOMETHING_WEIRD:
if (DEBUG) {
MyLog.i(CLS_NAME, "DT " + CC.COMMAND_SOMETHING_WEIRD.name());
}
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
break;
default:
if (DEBUG) {
MyLog.w(CLS_NAME, "DT DEFAULT");
}
request.setUtterance(PersonalityResponse.getNoComprende(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setCommand(CC.COMMAND_UNKNOWN);
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "DT networkProceed failed");
}
request.setUtterance(PersonalityResponse.getNoNetwork(mContext, sl));
request.setAction(LocalRequest.ACTION_SPEAK_ONLY);
request.setCommand(CC.COMMAND_UNKNOWN);
}
return qubit;
}
use of ai.saiy.android.custom.CustomResolver in project Saiy-PS by brandall76.
the class QuantumHelper method resolve.
public CustomResolver resolve(@NonNull final Context ctx, @NonNull final SupportedLanguage sl, @NonNull final CommandRequest cr) {
final long then = System.nanoTime();
final CustomHelperHolder holder = new CustomHelper().getCustomisationHolder(ctx);
final CustomResolver resolver = new CustomResolver();
final CustomCommandHelper cch = new CustomCommandHelper();
final ArrayList<String> manipulatedVoiceData = new Profanity(ctx, cr.getResultsArray(), sl).remove();
resolver.setCustom(cch.isCustomCommand(ctx, manipulatedVoiceData, sl, holder.getCustomCommandArray()));
resolver.setCustomCommandHelper(cch);
resolver.setVoiceData(manipulatedVoiceData);
if (DEBUG) {
MyLog.getElapsed(CLS_NAME, then);
}
return resolver;
}
Aggregations