예제 #1
0
        protected void  ReconstructWordformsMappings(string WordformsFileName)
        {
            if (File.Exists(WordformsFileName))
            {
                StreamReader reader = new StreamReader(WordformsFileName);
                string       Buffer;
                WordformsVariant.Clear();
                WordformsValues.Clear();

                while ((Buffer = reader.ReadLine()) != null)
                {
                    int i_DelimiterIndex = Buffer.IndexOf(" - ");
                    if (i_DelimiterIndex == -1)
                    {
                        //  Wordforms index corrupted - no delimiter found
                        continue;
                    }

                    string Lexeme = Buffer.Substring(0, i_DelimiterIndex);
                    Buffer = Buffer.Substring(i_DelimiterIndex + 3);
                    string[]  Wordforms      = Buffer.Split('|');
                    ArrayList FormsForLexeme = new ArrayList();

                    for (int i = 0; i < Wordforms.Length; i++)
                    {
                        //  Forbid adding the same wordform twice - this can
                        //  happen e.g. as the result of corruption or other
                        //  internal bugs.
                        string wordform = Wordforms[i];
                        if (FormsForLexeme.IndexOf(wordform) == -1)
                        {
                            FormsForLexeme.Add(wordform);
                            WordformsVariant[wordform] = FormsForLexeme.Count;
                        }
                    }
                    WordformsValues[Lexeme] = FormsForLexeme;
                }
                reader.Close();
            }
        }
예제 #2
0
        public int  StoreMapping(string wordform, string lexeme)
        {
            Debug.Assert(!WordformsVariant.Contains(wordform));

            int       derivationVariant;
            ArrayList forms;

            HashMap.Entry e = WordformsValues.GetEntry(lexeme);
            if (e != null)
            {
                forms = (ArrayList)e.Value;
            }
            else
            {
                forms = new ArrayList();
                WordformsValues[lexeme] = forms;
            }
            forms.Add(wordform);
            WordformsVariant[wordform] = derivationVariant = forms.Count;

            WordformsChanged = true;
            return(derivationVariant);
        }
예제 #3
0
        //---------------------------------------------------------------------
        //  NB: Exceptional conditions are possible if e.g. we failed to flush
        //      wordforms file into HD (due to any external conditions) and
        //      reread its previous state.
        //---------------------------------------------------------------------
        public string  GetLexemeMapping(string lexeme, int mapVariant)
        {
            if (mapVariant <= 0)
            {
                throw new ArgumentOutOfRangeException("DictionaryServer -- Mapping variant parameter must be positive.");
            }

            HashMap.Entry e = WordformsValues.GetEntry(lexeme);
            if (e == null)
            {
                throw new ArgumentException("DictionaryServer -- Illegal call to GetMappingLexeme - lexeme [" +
                                            lexeme + " is not present with index " + mapVariant);
            }

            ArrayList forms = (ArrayList)e.Value;

            if (mapVariant > forms.Count)
            {
                throw new ArgumentOutOfRangeException("DictionaryServer -- Mapping variant [" + mapVariant +
                                                      "] is greater than the number of possible wordforms " + forms.Count);
            }

            return((string)forms[mapVariant - 1]);
        }