Exemple #1
0
        public IEnumerable <string> GetResult(string text)
        {
            string result = string.Empty;

            try
            {
                result = AnalyzeMultiLine(text);
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, "形態素解析に失敗しました。" + e.Message + "\t" + GetText());
                tagger.Dispose();
                tagger = null;
            }
            System.IO.StringReader sr   = new System.IO.StringReader(result);
            List <string>          list = new List <string>();

            string[] hinshiArray = null;
            if (UseHinshi != null)
            {
                hinshiArray = UseHinshi.Split(',');
            }
            while (sr.Peek() > -1)
            {
                string line = sr.ReadLine();

                bool flag = false;
                if (line.Length > 0 && line != "EOS")
                {
                    if (UseHinshi != null)
                    {
                        string hinsi = MecabAnalyzeLine(line, MecabViewType.品詞);
                        if (hinsi != null)
                        {
                            foreach (var item in hinshiArray)
                            {
                                if (hinsi.Contains(item))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        string t = MecabAnalyzeLine(line, ViewType);
                        if (t != null)
                        {
                            list.Add(t);
                        }
                        else
                        {
                            ReportManage.ErrReport(this, "MecabLineの解析に失敗しました" + line);
                        }
                    }
                }
            }
            return(list);
        }
Exemple #2
0
        public override void Run(bool runChildren)
        {
            string result = string.Empty;

            try
            {
                result = AnalyzeMultiLine(GetText());
            }
            catch (Exception e)
            {
                ReportManage.ErrReport(this, "形態素解析に失敗しました。" + e.Message + "\t" + GetText());
                tagger.Dispose();
                tagger = null;
            }
            System.IO.StringReader sr   = new System.IO.StringReader(result);
            List <string>          list = new List <string>();

            string[] hinshiArray = null;
            if (UseHinshi != null)
            {
                hinshiArray = UseHinshi.Split(',');
            }
            while (sr.Peek() > -1)
            {
                string line = sr.ReadLine();

                bool flag = false;
                if (line.Length > 0 && line != "EOS")
                {
                    if (UseHinshi != null)
                    {
                        string hinsi = MecabAnalyzeLine(line, MecabViewType.品詞);
                        if (hinsi != null)
                        {
                            foreach (var item in hinshiArray)
                            {
                                if (hinsi.IndexOf(item) == 0)
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        string t = MecabAnalyzeLine(line, ViewType);
                        if (t != null)
                        {
                            list.Add(t);
                        }
                        else
                        {
                            ReportManage.ErrReport(this, "MecabLineの解析に失敗しました" + line);
                        }
                    }
                }
            }

            base.RunChildrenForArray(runChildren, list);
        }