Beispiel #1
0
        private ParseResult parseTextPart(string text, ParseOptions parseOptions)
        {
            DynamicParseResult[] scoreTable = new DynamicParseResult[text.Length + 1];
            for (int i = 0; i <= text.Length; ++i)
            {
                scoreTable[i] = new DynamicParseResult {
                    score = i * (-10000), parsed = null
                };
            }
            for (int i = 0; i < text.Length; ++i)
            {
                double             skipScore    = scoreTable[i].score - (("ぁぃぅぇぉゃゅょっ".IndexOf(text[i]) != -1) ? -1 : 10000); // ignore lower letters
                DynamicParseResult oldSkipScore = scoreTable[i + 1];
                if (oldSkipScore.score < skipScore)
                {
                    oldSkipScore.score  = skipScore;
                    oldSkipScore.parsed = null;
                }
                IEnumerable <EdictMatchWithType> matches = dict.findMatching(text, i);
                foreach (EdictMatchWithType match in matches)
                {
                    IEnumerable <InflectionState> inflections;
                    inflections = inflect.findMatching(match.matchType == EdictMatchType.FROM_KATAKANA, match.match.getAllPOS(), text, i + match.match.stemLength);
                    foreach (InflectionState inf in inflections)
                    {
                        int    totalLength = match.match.stemLength + inf.length;
                        string matchText   = text.Substring(i, totalLength);
                        if (Settings.app.isWordBanned(matchText, match.matchType))
                        {
                            continue;
                        }
                        double baseFormMult;
                        if (match.match.entries[0].entry.getText() == matchText)
                        {
                            baseFormMult = 1.05;
                        }
                        else
                        {
                            baseFormMult = 1.0;
                        }
                        double score = scoreTable[i].score + match.match.getMultiplier(inf.POS, inf.suffix.Length == 0) * getLengthMultiplier(totalLength) * baseFormMult;
                        if (parseOptions != null)
                        {
                            score += parseOptions.bonusRating(matchText);
                        }
                        DynamicParseResult oldScore = scoreTable[i + totalLength];
                        if (oldScore.parsed != null && oldScore.parsed.asText() == matchText)
                        {
                            (oldScore.parsed as WordParseResult).addMatch(match, inf, score);
                            if (oldScore.score < score)
                            {
                                oldScore.score = score;
                            }
                        }
                        else
                        {
                            if (oldScore.score < score)
                            {
                                oldScore.score  = score;
                                oldScore.parsed = new WordParseResult(matchText, match, inf, score);
                            }
                        }
                    }
                }
            }

            IList <ParseResult> results = new List <ParseResult>();
            int x = text.Length;

            while (x > 0)
            {
                DynamicParseResult res = scoreTable[x];
                if (res.parsed == null)
                {
                    results.Add(ParseResult.unparsed(text[x - 1].ToString()));
                    x -= 1;
                }
                else
                {
                    results.Add(res.parsed);
                    x -= res.parsed.length;
                }
            }
            return(ParseResult.concat(results.Reverse()));
        }