Пример #1
0
 public LexemeConstructor(ScriptMorphoAnalyzer morphAn, DictionaryServer dicServer)
 {
     _morphAn   = morphAn;
     _dicServer = dicServer;
 }
Пример #2
0
        //---------------------------------------------------------------------
        //  Using simple heuristics, reconstruct wordform (live form) from the
        //  lexeme and information, encoded in the bits of Offset
        //  - 100 - simple plural or 3rd person
        //  - 010 - participle I
        //  - 001 - continuous form
        //---------------------------------------------------------------------
        protected static string  ReconstructWordform(uint Offset, string lexeme, DictionaryServer dicServer)
        {
            string Context = lexeme;

            //-----------------------------------------------------------------
            if (isPlural(Offset))
            {
                if (lexeme.EndsWith("y"))
                {
                    Context = Context.Remove(lexeme.Length - 1, 1) + "ie";
                }
                Context += "s";
            }
            else
            if (isPast(Offset))
            {
                if (lexeme[lexeme.Length - 1] == 'y')
                {
                    Context  = Context.Remove(lexeme.Length - 1, 1);
                    Context += 'i';
                }

                if (Context[Context.Length - 1] != 'e')
                {
                    Context += 'e';
                }
                Context += 'd';
            }
            else
            if (isContinuous(Offset))
            {
                if (lexeme[lexeme.Length - 1] == 'e')
                {
                    Context = Context.Remove(lexeme.Length - 1, 1);
                }
                Context += "ing";
            }
            else
            if (isWordformIndex(Offset))
            {
                int index = RetrieveIndexFromBits(Offset);
                //-------------------------------------------------------------
                //  NB: Exceptional conditions are possible if e.g. DictionaryServer
                //      failed to flush wordforms file into HD (due to any
                //      external conditions) and reread its previous state.
                //-------------------------------------------------------------
                try
                {
                    Context = dicServer.GetLexemeMapping(lexeme, index);
                }
                catch (Exception exc)
                {
                    Trace.WriteLine("ContextConstructor -- Did not manage to find wordform mapping <" + index +
                                    "> for lexeme [" + lexeme + "] due to the exception:");
                    Trace.WriteLine(exc.Message);
                    Trace.WriteLine("ContextConstructor -- The lexeme value is used by default as the Wordform.");
                    Context = lexeme;
                }
            }

            return(Context);
        }