예제 #1
0
        public IEnumerable <Alternative> Alternatives(string token)
        {
            if (_open)
            {
                _trie.EndUpdate();
                _open = false;
            }
            var alternatives = _alternatives.Alternatives(token);

            foreach (var alternative in alternatives)
            {
                var matches = _trie.EditLookup(alternative.Token, 1);
                foreach (var match in matches)
                {
                    if (match.Distance == 0)
                    {
                        yield return(new Alternative(match.Token, 1.0));

                        yield break;
                    }
                    else
                    {
                        yield return(new Alternative(match.Token, 1.0 / (1.0 + match.Distance)));
                    }
                }
            }
        }
예제 #2
0
        public IEnumerable <Interpretation> Interpretations(string input, int spansPerPosition, double threshold)
        {
            var tokens         = _tokenizer.Tokenize(input);
            var alternatives   = (from token in tokens select _alternatives.Alternatives(token));
            var spans          = _recognizer.Recognize(alternatives, spansPerPosition, threshold);
            var interpretation = new Interpretation(tokens, spans);

            yield return(interpretation);
        }
예제 #3
0
 public IEnumerable <Alternative> Alternatives(string token)
 {
     foreach (var alternative in _alternatives.Alternatives(token))
     {
         Alternative[] synonyms;
         if (!_synonyms.TryGetValue(alternative.Token, out synonyms))
         {
             yield return(alternative);
         }
         else
         {
             foreach (var synonym in synonyms)
             {
                 yield return(new Alternative(synonym.Token, synonym.Weight * alternative.Weight));
             }
         }
     }
 }