Search in sources :

Example 1 with Concept

use of ai.saiy.android.nlu.nuance.Concept in project Saiy-PS by brandall76.

the class NLUCoerce method validateNLUNuance.

/**
 * Validate the parameters prior to use.
 *
 * @param nluNuance the {@link NLUNuance} response object
 * @return true if the minimum parameters are present, false otherwise.
 */
private boolean validateNLUNuance(@NonNull final NLUNuance nluNuance) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "validateNLUNuance");
    }
    final List<Interpretation> interpretations = nluNuance.getInterpretations();
    if (interpretations != null) {
        for (final Interpretation interpretation : interpretations) {
            if (UtilsString.notNaked(interpretation.getLiteral())) {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "interpretation: getLiteral: " + interpretation.getLiteral());
                }
                if (interpretation.getAction() != null) {
                    if (interpretation.getAction().getIntent() != null) {
                        if (UtilsString.notNaked(interpretation.getAction().getIntent().getValue())) {
                            if (DEBUG) {
                                MyLog.i(CLS_NAME, "interpretation: getValue: " + interpretation.getAction().getIntent().getValue());
                                MyLog.i(CLS_NAME, "interpretation: getConfidence: " + interpretation.getAction().getIntent().getConfidence());
                            }
                            final Map<String, List<Concept>> map = interpretation.getConcept();
                            if (UtilsMap.notNaked(map)) {
                                for (final Map.Entry<String, List<Concept>> entry : map.entrySet()) {
                                    if (DEBUG) {
                                        MyLog.i(CLS_NAME, "key: " + entry.getKey() + " ~ " + entry.getValue());
                                    }
                                    final List<Concept> concepts = entry.getValue();
                                    if (UtilsList.notNaked(concepts)) {
                                        final int conceptSize = concepts.size();
                                        for (int i = 0; i < conceptSize; i++) {
                                            if (UtilsString.notNaked(concepts.get(i).getLiteral())) {
                                                if (DEBUG) {
                                                    MyLog.i(CLS_NAME, "concept: getLiteral: " + concepts.get(i).getLiteral());
                                                    MyLog.i(CLS_NAME, "concept: getValue: " + concepts.get(i).getValue());
                                                    MyLog.i(CLS_NAME, "concept: getRanges: " + Arrays.deepToString(concepts.get(i).getRanges()));
                                                }
                                                if (i == (conceptSize - 1)) {
                                                    return true;
                                                }
                                            } else {
                                                if (DEBUG) {
                                                    MyLog.w(CLS_NAME, "validateNLUNuance: literal naked");
                                                }
                                                break;
                                            }
                                        }
                                    } else {
                                        if (DEBUG) {
                                            MyLog.w(CLS_NAME, "validateNLUNuance: concepts naked");
                                        }
                                        break;
                                    }
                                }
                            } else {
                                if (DEBUG) {
                                    MyLog.i(CLS_NAME, "validateNLUNuance: no concepts to examine");
                                }
                                return true;
                            }
                        } else {
                            if (DEBUG) {
                                MyLog.w(CLS_NAME, "validateNLUNuance: value naked");
                            }
                            break;
                        }
                    } else {
                        if (DEBUG) {
                            MyLog.w(CLS_NAME, "validateNLUNuance: intent null");
                        }
                        break;
                    }
                } else {
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "validateNLUNuance: action null");
                    }
                    break;
                }
            } else {
                if (DEBUG) {
                    MyLog.w(CLS_NAME, "validateNLUNuance: literal naked");
                }
                break;
            }
        }
    } else {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "validateNLUNuance: interpretations null");
        }
    }
    return false;
}
Also used : Concept(ai.saiy.android.nlu.nuance.Concept) ArrayList(java.util.ArrayList) UtilsList(ai.saiy.android.utils.UtilsList) List(java.util.List) UtilsString(ai.saiy.android.utils.UtilsString) Interpretation(ai.saiy.android.nlu.nuance.Interpretation) Map(java.util.Map) UtilsMap(ai.saiy.android.utils.UtilsMap)

Aggregations

Concept (ai.saiy.android.nlu.nuance.Concept)1 Interpretation (ai.saiy.android.nlu.nuance.Interpretation)1 UtilsList (ai.saiy.android.utils.UtilsList)1 UtilsMap (ai.saiy.android.utils.UtilsMap)1 UtilsString (ai.saiy.android.utils.UtilsString)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1