Exemple #1
0
        internal UtterancePattern(string patternDefinition, PatternConfiguration configuration)
        {
            PatternDefinition = patternDefinition;
            _patternWords     = patternDefinition.Split(' ').ToArray();
            _sentenceKeys     = new string[_patternWords.Length];
            _wordSets         = new HashSet <string> [_patternWords.Length];

            for (var wordIndex = 0; wordIndex < _patternWords.Length; ++wordIndex)
            {
                var word      = _patternWords[wordIndex];
                var targetSet = generateTargetSet(word, configuration);
                if (targetSet != null)
                {
                    _wordSets[wordIndex] = targetSet;
                    continue;
                }

                if (word.StartsWith(SentencePrefix))
                {
                    _sentenceKeys[wordIndex] = word.Substring(SentencePrefix.Length);
                    continue;
                }

                throw new NotSupportedException("Given construction '" + word + "' is not supported yet");
            }
        }
Exemple #2
0
        private HashSet <string> generateTargetSet(string word, PatternConfiguration configuration)
        {
            if (word.StartsWith(GroupPrefix))
            {
                var groupSet = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);
                var groupKey = word.Substring(GroupPrefix.Length);
                groupSet.UnionWith(configuration.GetGroup(groupKey));
                return(groupSet);
            }

            if (word.StartsWith(SentencePrefix))
            {
                return(null);
            }

            var singleWordSet = new HashSet <string>();

            singleWordSet.Add(word);

            return(singleWordSet);
        }