Exemplo n.º 1
0
        public FullLemmaInfo[] FastFindAllWord(string word)
        {
            word = word.ToUpper();

            List <FullLemmaInfo> result = new List <FullLemmaInfo>();

            if (Lemmas.ContainsKey(word))
            {
                foreach (LemmaInfo li in Lemmas[word].GetItems())
                {
                    FlexiaModel   flexiaModel = this.FlexiaModels[li.FlexiaModelNo];
                    FullLemmaInfo fi          = new FullLemmaInfo(li.FlexiaModelNo,
                                                                  li.AccentModelNo,
                                                                  li.CommonAncode);
                    fi.CommonLemma = word;
                    fi.CommonMF    = flexiaModel.FirstMF;
                    fi.CurrentMF   = flexiaModel.FirstMF;
                    result.Add(fi);
                }
            }

            for (int i = 0; i <= word.Length && i < FastFlexia.Length; i++)
            {
                string end = word.Substring(word.Length - i);

                List <int> nos;
                if (FastFlexia[i].TryGetValue(end, out nos))
                {
                    foreach (int iFlexiaModelNo in nos)
                    {
                        FlexiaModel     flexiaModel = this.FlexiaModels[iFlexiaModelNo];
                        MorphologicForm morphForm   = flexiaModel.FindMorphologicFormByFlex(end);
                        {
                            if (word.StartsWith(morphForm.PrefixStr))
                            {
                                string commonWord = word.Substring(morphForm.PrefixStr.Length, word.Length - morphForm.FlexiaStr.Length - morphForm.PrefixStr.Length) + flexiaModel.FirstFlex;
                                if (Lemmas.ContainsKey(commonWord))
                                {
                                    foreach (LemmaInfo li in Lemmas[commonWord].GetItems())
                                    {
                                        if (li.FlexiaModelNo == iFlexiaModelNo)
                                        {
                                            FullLemmaInfo fi = new FullLemmaInfo(li.FlexiaModelNo,
                                                                                 li.AccentModelNo,
                                                                                 li.CommonAncode);
                                            fi.CommonLemma = commonWord;
                                            fi.CommonMF    = flexiaModel.FirstMF;
                                            fi.CurrentMF   = morphForm;
                                            result.Add(fi);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(result.ToArray());
        }
Exemplo n.º 2
0
        //private FullLemmaInfo SlowFindWord(string word)
        //{
        //    Set<FullLemmaInfo> result = SlowFindAllWord(word);

        //    if (result.Count == 0)
        //        return FullLemmaInfo.Unknown;

        //    FullLemmaInfo maxFlex = new FullLemmaInfo();
        //    foreach (FullLemmaInfo fi in result.Keys)
        //    {
        //        if (fi.CurrentMF.FlexiaStr != null
        //            && (maxFlex.CurrentMF.FlexiaStr == null
        //            || fi.CurrentMF.FlexiaStr.Length > maxFlex.CurrentMF.FlexiaStr.Length))
        //            maxFlex = fi;
        //    }
        //    return maxFlex;
        //}

        //private Set<FullLemmaInfo> SlowFindAllWord(string word)
        //{
        //    word = word.ToUpper();
        //    Set<FullLemmaInfo> result = new Set<FullLemmaInfo>();
        //    if (FlexiaModels != null)
        //        for (int iFlexiaModelNo = 0; iFlexiaModelNo < FlexiaModels.Count; iFlexiaModelNo++)
        //        {
        //            FlexiaModel flexiaModel = this.FlexiaModels[iFlexiaModelNo];
        //            if (flexiaModel.Flexia != null && flexiaModel.Flexia.Values.Count != 0)
        //                foreach (MorphologicForm morphForm in flexiaModel.Flexia.Values)
        //                {
        //                    if (word.EndsWith(morphForm.FlexiaStr) && (word.StartsWith(morphForm.PrefixStr)))
        //                    {
        //                        string commonWord = word.Substring(morphForm.PrefixStr.Length, word.Length - morphForm.FlexiaStr.Length - morphForm.PrefixStr.Length) + flexiaModel.FirstFlex;
        //                        if (Lemmas.ContainsKey(commonWord))
        //                        {
        //                            foreach(
        //                            if (Lemmas[commonWord].FlexiaModelNo == iFlexiaModelNo)
        //                            {
        //                                FullLemmaInfo fi = new FullLemmaInfo(Lemmas[commonWord].FlexiaModelNo,
        //                                    Lemmas[commonWord].AccentModelNo,
        //                                    Lemmas[commonWord].CommonAncode);
        //                                fi.CommonLemma = commonWord;
        //                                fi.CommonMF = flexiaModel.FirstMF;
        //                                fi.CurrentMF = morphForm;
        //                                result.Add(fi);
        //                            }
        //                        }
        //                    }
        //                }
        //        }

        //    return result;
        //}

        #endregion

        #region New/Fast find functions

#if ENABLE_FAST_FINDING
        public FullLemmaInfo FastFindWord(string word)
        {
            //Set<FullLemmaInfo> result = FindAllWord(word);
            FullLemmaInfo[] result = FastFindAllWord(word);

            if (result.Length == 0)
            {
                return(FullLemmaInfo.Unknown);
            }

            FullLemmaInfo maxFlex = new FullLemmaInfo();

            foreach (FullLemmaInfo fi in result)
            {
                if (fi.CurrentMF.FlexiaStr != null &&
                    (maxFlex.CurrentMF.FlexiaStr == null ||
                     fi.CurrentMF.FlexiaStr.Length > maxFlex.CurrentMF.FlexiaStr.Length))
                {
                    maxFlex = fi;
                }
            }
            return(maxFlex);
        }
Exemplo n.º 3
0
 public void Add(FullLemmaInfo fullLemmaInfo)
 {
     Result.Add(fullLemmaInfo);
 }