Index get_index(string p, int pos, int i, Tagger tagger)
        {
            if (p[i] != '[')
            {
                return(new Index(null, i));
            }
            i++;
            var isInRow = true;
            var col     = 0;
            var row     = 0;
            var neg     = 1;

            if (p[i] == '-')
            {
                neg = -1;
                i++;
            }

            for (; i < p.Length; i++)
            {
                var c = p[i];
                if (isInRow)
                {
                    if (c >= '0' && c <= '9')
                    {
                        row = 10 * row + (c - '0');
                    }
                    else if (c == ',')
                    {
                        isInRow = false;
                    }
                    else
                    {
                        return(new Index(null, i));
                    }
                }
                else
                {
                    if (c >= '0' && c <= '9')
                    {
                        col = 10 * col + (c - '0');
                    }
                    else if (c == ']')
                    {
                        break;
                    }
                    else
                    {
                        return(new Index(null, i));
                    }
                }
            }

            row *= neg;

            if (col < 0 || col >= xsize_)
            {
                return(new Index(null, i));
            }
            var idx = pos + row;

            if (idx < 0)
            {
                return(new Index("_B-" + (-idx).ToString(), i));;
            }
            if (idx >= tagger.word_num)
            {
                return(new Index("_B+" + (idx - tagger.word_num + 1).ToString(), i));
            }

            return(new Index(tagger.x_[idx][col], i));
        }
 public StringBuilder apply_rule(string p, int pos, StringBuilder resultContainer, Tagger tagger)
 {
     resultContainer.Clear();
     for (var i = 0; i < p.Length; i++)
     {
         if (p[i] == '%')
         {
             i++;
             if (p[i] == 'x')
             {
                 i++;
                 var res = get_index(p, pos, i, tagger);
                 i = res.idx;
                 if (res.value == null)
                 {
                     return(null);
                 }
                 resultContainer.Append(res.value);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             resultContainer.Append(p[i]);
         }
     }
     return(resultContainer);
 }