예제 #1
0
        public static void getSentenceStemmsAndSubStemm(string lang, IEnumerable <string> sentence, Action <string, List <WordStemms> > onOK)
        {
            var stemmer = Creators.createStemmer(lang);

            if (stemmer == null)
            {
                return;
            }
            foreach (var word in sentence)
            {
                var all   = new List <WordStemms>();
                var first = new WordStemms()
                {
                    word = word
                };
                all.Add(first);
                stemm(stemmer, word, first.stemms);
                foreach (var subw in first.stemms.Where(w => w != word))
                {
                    var other = new WordStemms()
                    {
                        word = subw
                    };
                    stemm(stemmer, subw, other.stemms);
                    all.Add(other);
                }
                onOK(word, all);
            }
        }
예제 #2
0
        static List <string> getWordStemms(string lang, string word)
        {
            var stemmer = Creators.createStemmer(lang);
            var res     = new List <string>();

            stemm(stemmer, word, res);
            return(res);
        }
예제 #3
0
        public static void getSentenceStemms(string lang, IEnumerable <string> sentence, Action <string, List <string> > onWordOK)
        {
            var stemmer = Creators.createStemmer(lang);

            if (stemmer == null)
            {
                return;
            }
            var list = new List <string>();

            foreach (var word in sentence)
            {
                stemm(stemmer, word, list);
                onWordOK(word, list);
                list.Clear();
            }
        }
예제 #4
0
        public static List <TPosLen>[] wordBreak(string lang, IList <string> texts)
        {
            var breaker = Creators.createBreaker(lang);
            var res     = new List <TPosLen> [texts.Count];

            for (var i = 0; i < texts.Count; i++)
            {
                var pl   = res[i] = new List <TPosLen>();
                var word = texts[i];
                wordBreak(word, breaker, (type, pos, len) => {
                    if (type != PutTypes.put)
                    {
                        return;             // && type != PutTypes.alt) return;
                    }
                    pl.Add(new TPosLen {
                        Pos = pos, Len = len
                    });
                });
            }
            return(res);
        }
예제 #5
0
        public static IEnumerable <string> wordBreak(string lang, IEnumerable <string> sentences)
        {
            var breaker = Creators.createBreaker(lang);

            return(sentences.SelectMany(par => wordBreak(breaker, par)));
        }