Пример #1
0
 private static void InitStaticLexer()
 {
     lock (typeof(Morphology))
     {
         if (staticLexer == null)
         {
             staticLexer = new Morpha(new InputStreamReader(Runtime.@in));
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Lemmatize the word, being sensitive to the tag, using the
        /// passed in lexer.
        /// </summary>
        /// <param name="lowercase">
        /// If this is true, words other than proper nouns will
        /// be changed to all lowercase.
        /// </param>
        private static string Lemmatize(string word, string tag, Morpha lexer, bool lowercase)
        {
            bool   wordHasForbiddenChar = word.IndexOf('_') >= 0 || word.IndexOf(' ') >= 0 || word.IndexOf('\n') >= 0;
            string quotedWord           = word;

            if (wordHasForbiddenChar)
            {
                // choose something unlikely. Classical Vedic!
                quotedWord = quotedWord.ReplaceAll("_", "\u1CF0");
                quotedWord = quotedWord.ReplaceAll(" ", "\u1CF1");
                quotedWord = quotedWord.ReplaceAll("\n", "\u1CF2");
            }
            string wordtag = quotedWord + '_' + tag;

            try
            {
                lexer.SetOption(1, lowercase);
                lexer.Yyreset(new StringReader(wordtag));
                lexer.Yybegin(Morpha.scan);
                string wordRes = lexer.Next();
                lexer.Next();
                // go past tag
                if (wordHasForbiddenChar)
                {
                    wordRes = wordRes.ReplaceAll("\u1CF0", "_");
                    wordRes = wordRes.ReplaceAll("\u1CF1", " ");
                    wordRes = wordRes.ReplaceAll("\u1CF2", "\n");
                }
                return(wordRes);
            }
            catch (IOException)
            {
                log.Warning("Morphology.stem() had error on word " + word + '/' + tag);
                return(word);
            }
        }
Пример #3
0
 public Morphology(Reader @in, int flags)
 {
     lexer = new Morpha(@in);
     lexer.SetOptions(flags);
 }
Пример #4
0
 /// <summary>Process morphologically words from a Reader.</summary>
 /// <param name="in">The Reader to read from</param>
 public Morphology(Reader @in)
 {
     lexer = new Morpha(@in);
 }
Пример #5
0
 public Morphology()
 {
     lexer = new Morpha(new InputStreamReader(Runtime.@in));
 }