private static List <JmdictEntity> GetMatchedWords(WordInformation word, Database dictionary, string queryCommmand, bool isSkipSurfaceIfHasBaseForm, string conjungation = null)
        {
            //Use Dictionary to ensure unique entries
            Dictionary <int, JmdictEntity> entries = new Dictionary <int, JmdictEntity>();

            if (WordInformation.IsHave(word.BaseForm))
            {
                if (word.IsMaybeAmbiguousGodan())
                {
                    var allVariants = GetPossibleGodanVerb(word);
                    AddPossibleGodanVerbsDictionaryEntry(allVariants, dictionary, entries, conjungation);
                    if (allVariants.Count == 1)
                    {
                        AddPossibleSpecialSuruVerb(word, dictionary, conjungation, entries);
                    }
                }
                else
                {
                    if (word.IsIAdjectiveConjugation())
                    {
                        HandleIAdjective(word, dictionary, conjungation, entries);
                    }
                    else if (word.IsVerb())
                    {
                        HandleVerb(word, dictionary, conjungation, entries);
                    }
                    else if (word.IsAuxiliaryVerb())
                    {
                        AddVerbDictionaryEntry(word.BaseForm, dictionary, entries, conjungation);
                    }
                    else
                    {
                        AddAllDictionaryEntry(word.BaseForm + queryCommmand, dictionary, entries);
                    }
                }
            }
            if (word.BaseForm == null || entries.Count == 0 || !word.BaseForm.EqualsOrdinalIgnore(word.Surface))
            {
                if (entries.Count == 0 || !isSkipSurfaceIfHasBaseForm)
                {
                    AddAllDictionaryEntry(word.Surface + queryCommmand, dictionary, entries);
                }
            }

            return(entries.Values.ToList());
        }
예제 #2
0
        private static bool IsValidVerb(WordInformation word)
        {
            if (!word.IsVerb())
            {
                return(false);
            }

            if (word.IsBaseForm())
            {
                return(true);
            }

            if (!String.IsNullOrWhiteSpace(word.Conjugation))
            {
                return(true);
            }

            return(false);
        }
        private static void ReorderByPartOfSpeech(List <JmdictEntity> results, WordInformation word)
        {
            if (results.Count < 2)
            {
                return;
            }

            string pos = word.GetPartOfSpeechInEnglish();

            if (String.IsNullOrEmpty(pos))
            {
                return;
            }

            List <JmdictEntity> removed = new List <JmdictEntity>();

            for (int i = 0; i < results.Count;)
            {
                if (word.IsVerb() &&
                    (!results[i].PartOfSpeech.Contains("Godan") || !results[i].PartOfSpeech.Contains("Ichidan"))
                    )
                {
                    removed.Add(results[i]);
                    results.RemoveAt(i);
                }
                else if (!results[i].PartOfSpeech.Contains(pos))
                {
                    removed.Add(results[i]);
                    results.RemoveAt(i);
                }
                else
                {
                    i++;
                }
            }
            results.AddRange(removed);
        }
        private static List <JmdictEntity> TrySearchCompoundVerbs(WordInformation currentSelectedWord, int selectedIndex, List <WordInformation> words, Database japEngDictionary)
        {
            if (currentSelectedWord.IsVerb() && currentSelectedWord.IsMasuConjugation() &&
                (selectedIndex < (words.Count - 1)) &&
                words[selectedIndex + 1].IsVerb())
            {
                var nextWord = words[selectedIndex + 1];

                //Remove potential conjugation if has to make sure word is in its most baseform
                var nextWordBase = WordInformation.TryRemoveGodanPotential(nextWord, japEngDictionary);
                if (nextWordBase != null)
                {
                    nextWord = nextWordBase;
                }

                string baseForm     = currentSelectedWord.Surface + nextWord.BaseForm;
                var    compoundWord = new WordInformation(nextWord.FirstConjugationType, nextWord.FirstConjugationForm, baseForm, nextWord.PartOfSpeech, false, nextWord.Conjugation);
                compoundWord.AddWordPart(currentSelectedWord.Surface + nextWord.Surface,
                                         currentSelectedWord.Reading + nextWord.Reading,
                                         currentSelectedWord.Pronunciation + nextWord.Pronunciation);
                return(FindTokenPerfectMatchInDictionary(compoundWord, japEngDictionary));
            }
            return(null);
        }