public Configuration()
        {
            iniFilePath = resolveFilePath(CONFIG_FILE_NAME);

            loadLocal();
            loadGlobal();

            merged = new IniData();
            merged.Merge(global);
            merged.Merge(local);

            string matchingMode = Get("Dialogue", "SubsetMatchingMode", Enum.GetName(typeof(SubsetMatchingMode), DEFAULT_GRAMMAR_MATCHING_MODE));

            try {
                if (matchingMode.ToLower() == "none")
                {
                    enableDialogueSubsetMatching = false;
                    Trace.TraceInformation("Dialogue SubsetMatchingMode Disabled");
                }
                else
                {
                    configuredMatchingMode = (SubsetMatchingMode)Enum.Parse(typeof(SubsetMatchingMode), matchingMode, true);
                    Trace.TraceInformation("Set Dialogue SubsetMatchingMode to {0}", configuredMatchingMode);
                }
            } catch (Exception ex) {
                Trace.TraceError("Failed to parse SubsetMatchingMode from ini file, falling back to default");
                Trace.TraceError(ex.ToString());
                configuredMatchingMode = DEFAULT_GRAMMAR_MATCHING_MODE;
            }

            goodbyePhrases = getPhrases("Dialogue", "goodbyePhrases");
            pausePhrases   = getPhrases("SpeechRecognition", "pausePhrases");
            resumePhrases  = getPhrases("SpeechRecognition", "resumePhrases");

            string nmlExpStr = Get("SpeechRecognition", "normalizeExpression", DEFAULT_NORMALIZE_EXPRESSION);

            if (nmlExpStr.Length > 0)
            {
                normalizeExpression  = new Regex(nmlExpStr);
                normalizeReplacement = Get("SpeechRecognition", "normalizeReplacement", DEFAULT_NORMALIZE_REPLACEMENT);
            }

            string opExpStr = Get("SpeechRecognition", "optionalExpression", DEFAULT_OPTIONAL_EXPRESSION);

            if (opExpStr.Length > 0)
            {
                optionalExpression  = new Regex(opExpStr);
                optionalReplacement = Get("SpeechRecognition", "optionalReplacement", DEFAULT_OPTIONAL_REPLACEMENT);
            }

            string localeStr = Get("SpeechRecognition", "Locale", "");

            if (localeStr.Length > 0)
            {
                locale = new CultureInfo(localeStr);
            }

            consoleCommandList = CommandList.FromIniSection(merged, "ConsoleCommands", this);
            consoleCommandList.PrintToTrace();
        }
Exemple #2
0
 internal static void ValidateSubsetMatchingCriteriaArgument(SubsetMatchingMode subsetMatchingCriteria, string paramName)
 {
     if ((uint)subsetMatchingCriteria > 3u)
     {
         throw new ArgumentException(SR.Get(SRID.EnumInvalid, paramName), paramName);
     }
 }
Exemple #3
0
        public void Append(string phrase, SubsetMatchingMode subsetMatchingCriteria)
        {
            Helpers.ThrowIfEmptyOrNull(phrase, nameof(phrase));
            GrammarBuilder.ValidateSubsetMatchingCriteriaArgument(subsetMatchingCriteria, nameof(subsetMatchingCriteria));

            AddItem(new GrammarBuilderPhrase(phrase, subsetMatchingCriteria));
        }
 public SrgsSubset(string text, SubsetMatchingMode matchingMode)
 {
     Helpers.ThrowIfEmptyOrNull(text, "text");
     if (matchingMode != SubsetMatchingMode.OrderedSubset && matchingMode != 0 && matchingMode != SubsetMatchingMode.OrderedSubsetContentRequired && matchingMode != SubsetMatchingMode.SubsequenceContentRequired)
     {
         throw new ArgumentException(SR.Get(SRID.InvalidSubsetAttribute), "matchingMode");
     }
     _matchMode = matchingMode;
     _text      = text.Trim(Helpers._achTrimChars);
     Helpers.ThrowIfEmptyOrNull(_text, "text");
 }
Exemple #5
0
        internal static void ValidateSubsetMatchingCriteriaArgument(SubsetMatchingMode subsetMatchingCriteria, string paramName)
        {
            switch (subsetMatchingCriteria)
            {
            case SubsetMatchingMode.OrderedSubset:
            case SubsetMatchingMode.OrderedSubsetContentRequired:
            case SubsetMatchingMode.Subsequence:
            case SubsetMatchingMode.SubsequenceContentRequired:
                break;

            default:
                throw new ArgumentException(SR.Get(SRID.EnumInvalid, paramName), paramName);
            }
        }
Exemple #6
0
        public static void appendPhrase(GrammarBuilder builder, string phrase, Configuration config, bool isSubsetMatchingEnabled = false)
        {
            var optionalExpression          = config.GetOptionalExpression();
            var optionalReplacement         = "\0" + config.GetOptionalReplacement() + "\0";
            SubsetMatchingMode matchingMode = config.getConfiguredMatchingMode();

            if (optionalExpression == null)
            {
                if (isSubsetMatchingEnabled)
                {
                    builder.Append(phrase, matchingMode);
                }
                else
                {
                    builder.Append(phrase);
                }
                return;
            }

            phrase = optionalExpression.Replace(phrase, optionalReplacement);
            var phraseParts = phrase.Split('\0');

            for (int i = 0; i < phraseParts.Length; i++)
            {
                string part = phraseParts[i];
                if (part.Trim().Length == 0)
                {
                    continue;
                }

                // Even numbers are non-optional and odd numbers are optional
                if (i % 2 == 0)
                {
                    if (isSubsetMatchingEnabled)
                    {
                        builder.Append(part, matchingMode);
                    }
                    else
                    {
                        builder.Append(part);
                    }
                    //Trace.TraceInformation("no op exp: {1}", i, part);
                }
                else
                {
                    builder.Append(part, 0, 1);
                    //Trace.TraceInformation("op exp: {1}", i, part);
                }
            }
        }
        private DialogueList(long id, List <string> lines, Configuration config)
        {
            this.id     = id;
            this.config = config;

            SubsetMatchingMode matchingMode   = config.getConfiguredMatchingMode();
            List <string>      goodbyePhrases = config.GetGoodbyePhrases();

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];
                if (line == null || line.Trim() == "")
                {
                    continue;
                }
                try {
                    Grammar g = new Grammar(config.IsSubsetMatchingEnabled() ? new GrammarBuilder(line, matchingMode) : new GrammarBuilder(line));
                    grammarToIndex[g] = i;
                }
                catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for line {0} due to exception:\n{1}", line, ex.ToString());
                }
            }

            foreach (string phrase in goodbyePhrases)
            {
                if (phrase == null || phrase.Trim() == "")
                {
                    continue;
                }
                Trace.TraceInformation("Found goodbye phrase: '{0}'", phrase);
                try {
                    Grammar g = new Grammar(new GrammarBuilder(Phrases.normalize(phrase), matchingMode));
                    grammarToIndex[g] = -2;
                } catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for exit dialogue phrase {0} due to exception:\n{1}", phrase, ex.ToString());
                }
            }
        }
        private GrammarBuilderPhrase(string phrase, bool subsetMatching, SubsetMatchingMode subsetMatchingCriteria)
        {
            _phrase         = string.Copy(phrase);
            _subsetMatching = subsetMatching;
            switch (subsetMatchingCriteria)
            {
            case SubsetMatchingMode.OrderedSubset:
                _matchMode = MatchMode.OrderedSubset;
                break;

            case SubsetMatchingMode.OrderedSubsetContentRequired:
                _matchMode = MatchMode.OrderedSubsetContentRequired;
                break;

            case SubsetMatchingMode.Subsequence:
                _matchMode = MatchMode.Subsequence;
                break;

            case SubsetMatchingMode.SubsequenceContentRequired:
                _matchMode = MatchMode.SubsequenceContentRequired;
                break;
            }
        }
        public Configuration()
        {
            iniFilePath = resolveFilePath(CONFIG_FILE_NAME);

            loadLocal();
            loadGlobal();

            merged = new IniData();
            merged.Merge(global);
            merged.Merge(local);

            string matchingMode = Get("Dialogue", "SubsetMatchingMode", Enum.GetName(typeof(SubsetMatchingMode), DEFAULT_GRAMMAR_MATCHING_MODE));

            try {
                if (matchingMode.ToLower() == "none")
                {
                    enableDialogueSubsetMatching = false;
                    Trace.TraceInformation("Dialogue SubsetMatchingMode Disabled");
                }
                else
                {
                    configuredMatchingMode = (SubsetMatchingMode)Enum.Parse(typeof(SubsetMatchingMode), matchingMode, true);
                    Trace.TraceInformation("Set Dialogue SubsetMatchingMode to {0}", configuredMatchingMode);
                }
            } catch (Exception ex) {
                Trace.TraceError("Failed to parse SubsetMatchingMode from ini file, falling back to default");
                Trace.TraceError(ex.ToString());
                configuredMatchingMode = DEFAULT_GRAMMAR_MATCHING_MODE;
            }

            goodbyePhrases = getPhrases("Dialogue", "goodbyePhrases");
            pausePhrases   = getPhrases("SpeechRecognition", "pausePhrases");
            resumePhrases  = getPhrases("SpeechRecognition", "resumePhrases");

            consoleCommandList = CommandList.FromIniSection(merged, "ConsoleCommands");
            consoleCommandList.PrintToTrace();
        }
        ISubset IElementFactory.CreateSubset(IElement parent, string text, MatchMode matchMode)
        {
            SubsetMatchingMode matchingMode = SubsetMatchingMode.Subsequence;

            switch (matchMode)
            {
            case MatchMode.OrderedSubset:
                matchingMode = SubsetMatchingMode.OrderedSubset;
                break;

            case MatchMode.OrderedSubsetContentRequired:
                matchingMode = SubsetMatchingMode.OrderedSubsetContentRequired;
                break;

            case MatchMode.Subsequence:
                matchingMode = SubsetMatchingMode.Subsequence;
                break;

            case MatchMode.SubsequenceContentRequired:
                matchingMode = SubsetMatchingMode.SubsequenceContentRequired;
                break;
            }
            return(new SrgsSubset(text, matchingMode));
        }
Exemple #11
0
 public GrammarBuilder(string phrase, SubsetMatchingMode subsetMatchingCriteria)
     : this()
 {
     Append(phrase, subsetMatchingCriteria);
 }
 internal GrammarBuilderPhrase(string phrase, SubsetMatchingMode subsetMatchingCriteria)
     : this(phrase, true, subsetMatchingCriteria)
 {
 }