Exemplo n.º 1
0
        public IEnumerable <Morpheme> FindLexemes(string word, int maxDistance)
        {
            using (Trace.Entering())
            {
                IEnumerable <Morpheme> result = Enumerable.Empty <Morpheme>();

                // Try to find exact lexemes.
                if (myLexemes.TryGetValues(word, out ReadOnlySet <Morpheme> lexemes))
                {
                    result = lexemes;
                }

                if (maxDistance > 0)
                {
                    // Also try to find lexemes which have similar morph.
                    IEnumerable <string> similarMorphs = myLexemes.Keys.FindSimilar(word, maxDistance);

                    if (lexemes != null)
                    {
                        // Note: skip morphemes already returned among exact lexemes.
                        result = result.Concat(similarMorphs.SelectMany(x => myLexemes[x].Where(y => !lexemes.Contains(y))));
                    }
                    else
                    {
                        result = result.Concat(similarMorphs.SelectMany(x => myLexemes[x]));
                    }
                }

                return(result);
            }
        }
Exemplo n.º 2
0
 public IEnumerable <Morpheme> FindNonLexemes(string morph)
 {
     using (Trace.Entering())
     {
         myNonLexemes.TryGetValues(morph, out ReadOnlySet <Morpheme> result);
         return(result ?? Enumerable.Empty <Morpheme>());
     }
 }
Exemplo n.º 3
0
        public void TryGetValues()
        {
            MultiKeyDistinctValueDictionary <string, string> dictionary = new MultiKeyDistinctValueDictionary <string, string>()
            {
                { "1", "2" },
                { "1", "3" },
                { "2", "1" },
                { "2", "2" },
            };


            Assert.IsFalse(dictionary.TryGetValues("bla", out ReadOnlySet <string> values));

            Assert.IsTrue(dictionary.TryGetValues("1", out values));
            Assert.AreEqual(2, values.Count);
            Assert.IsTrue(values.Contains("2"));
            Assert.IsTrue(values.Contains("3"));
        }