Пример #1
0
 public void maxFrom(Model model, Element element)
 {
     if (from == null)
     {
         from = new int[tagScore.Length];
     }
     var pTagScore = element.tagScore;
     double rate = 0;
     for (var i = 0; i < tagScore.Length; i++)
     {
         var maxValue = MIN;
         for (var j = 0; j < pTagScore.Length; j++)
         {
             if ((rate = model.tagRate(j, i)) == double.MinValue)
             {
                 continue;
             }
             var value = (pTagScore[j] + tagScore[i]) + rate;
             if (value > maxValue)
             {
                 maxValue = value;
                 from[i] = j;
             }
         }
         tagScore[i] = maxValue;
     }
 }
Пример #2
0
        public static List<Element> Str2Elements(string str)
        {
            if (str == null || str.Trim().Length == 0)
            {
                return new List<Element>();
            }

            var chars = AlertStr(str);
            var maxLen = chars.Length - 1;
            var list = new List<Element>();
            outLable:
            for (var i = 0; i < chars.Length; i++)
            {
                Element element;
                if (chars[i] >= '0' && chars[i] <= '9')
                {
                    element = new Element('M');
                    list.Add(element);
                    if (i == maxLen)
                    {
                        goto outLable;
                    }
                    var c = chars[++i];
                    while (c == '.' || c == '%' || (c >= '0' && c <= '9'))
                    {
                        if (i == maxLen)
                        {
                            goto outLable;
                        }
                        c = chars[++i];
                        element.IncrementLen();
                    }
                    i--;
                }
                else if (chars[i] >= 'a' && chars[i] <= 'z')
                {
                    element = new Element('W');
                    list.Add(element);
                    if (i == maxLen)
                    {
                        goto outLable;
                    }
                    var c = chars[++i];
                    while (c >= 'a' && c <= 'z')
                    {
                        if (i == maxLen)
                        {
                            goto outLable;
                        }
                        c = chars[++i];
                        element.IncrementLen();
                    }
                    i--;
                }
                else
                {
                    list.Add(new Element(chars[i]));
                }
            }
            return list;
        }