Exemple #1
0
        public IEnumerable<DefinitionGroup> GetDefinitions(string word)
        {
            word = word.ToLowerInvariant();

            var definitions = new List<DefinitionGroup>();

            var parts = GetDefinitionParts(word);
            definitions.AddRange(parts.Select(part => new DefinitionGroup(new[] { part })));

            // try `-ne` and `-que`
            foreach (var enc in Enclitics)
            {
                if (word.EndsWith(enc))
                {
                    var baseWord = word.Substring(0, word.Length - enc.Length);
                    var entry = GetEnclitic(enc);
                    var encliticStem = entry.GetStems().Single();
                    var encliticDefined = new DefinitionPart(encliticStem, new Span(baseWord.Length, enc.Length), entry.GetStems().SelectMany(s => s.GetForms()));
                    var baseMatches = GetDefinitionParts(baseWord);
                    foreach (var baseMatch in baseMatches)
                    {
                        definitions.Add(new DefinitionGroup(new[] { baseMatch, encliticDefined }));
                    }
                }
            }

            return definitions;
        }
Exemple #2
0
        private IEnumerable<DefinitionPart> GetDefinitionParts(string word)
        {
            var result = new List<DefinitionPart>();
            var matchingStems = _stemCache.GetValues(word);
            foreach (var stem in matchingStems)
            {
                var forms = new List<WordForm>();
                if (word.StartsWith(stem.StemPart))
                {
                    foreach (var form in stem.GetForms())
                    {
                        if (word.Length == form.Stem.StemPart.Length + form.Suffix.Length && word.EndsWith(form.Suffix))
                        {
                            forms.Add(form);
                        }
                    }
                }

                if (forms.Count > 0)
                {
                    var part = new DefinitionPart(stem, new Span(0, word.Length), forms);
                    result.Add(part);
                }
            }

            return result;
        }