示例#1
0
        /// <summary>
        /// SubjectInfo 排序规则
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static int CompareSubJectInfo(SubjectInfo x, SubjectInfo y)
        {
            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're
                    // equal.
                    return 0;
                }
                else
                {
                    // If x is null and y is not null, y
                    // is greater.
                    return -1;
                }
            }
            else
            {
                // If x is not null...
                //
                if (y == null)
                // ...and y is null, x is greater.
                {
                    return 1;
                }
                else
                {
                    // ...and y is not null, compare the
                    // lengths of the two strings.
                    //
                    int retval = x.paragraphsStart.CompareTo(y.paragraphsStart);

                    if (retval != 0)
                    {
                        // If the strings are not of equal length,
                        // the longer string is greater.
                        //
                        return retval;
                    }
                    else
                    {
                        // If the strings are of equal length,
                        // sort them with ordinary string comparison.
                        //
                        return x.paragraphsNum.CompareTo(y.paragraphsNum);
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// 在指定范围内匹配,如果范围的start、end都为0,则在整个文件匹配
 /// </summary>
 /// <param name="doc"></param> 
 /// <param name="matchArray"></param>
 /// <param name="start">指定范围的起始</param>
 /// <param name="end">指定范围的结束</param>
 /// <param name="prelength">前缀长度</param>
 /// <returns></returns>
 public static List<SubjectInfo> SubjectSpot(Microsoft.Office.Interop.Word.Document doc, string[] matchArray, int start, int end)
 {
     List<SubjectInfo> list = new List<SubjectInfo>();
      object start1 = start;
      object end1 = end;
      int count = 0;//总共有多少段落
      //int prelength = 0;//匹配题目前缀如(1、)的长度用于截断
      if (start == 0 && end == 0)
      {
          count = doc.Paragraphs.Count;//针对整个文件统计数据行数
      }
      else
      {
          count = doc.Range(ref start1, ref end1).Paragraphs.Count;//正对选定的部分统计数据行数
      }
      for (int i = 0; i < count; i++)
      {
          string text = "";
          if (start == 0 && end == 0)
          {
              text = doc.Paragraphs[i + 1].Range.Text;
          }
          else
          {
              text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
          }
          if (text.ToString().Length > 1)//通过字段长度过滤来提高性能;
          {
              if (start == 0 && end == 0)//取整个文本中对应行的数据
              {
                  try
                  {
                      doc.Paragraphs[i + 1].Range.Copy();
                      text = ClipboardHelper.getClipboardText();//取整个文本中对应行的数据
                  }
                  catch
                  {
                      text = doc.Paragraphs[i + 1].Range.Text;//取整个文本中对应行的数据
                  }
              }
              else//取整个文本中选择的文本中对应行的数据
              {
                  try
                  {
                      doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Copy();
                      text = ClipboardHelper.getClipboardText();
                  }
                  catch
                  {
                      text = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Text;
                  }
              }
              if (MatchContent.match(matchArray, text))
              {
                  SubjectInfo si = new SubjectInfo();
                  si.paragraphsNum = i;
                  if (start == 0 && end == 0)
                  {
                      si.paragraphsStart = doc.Paragraphs[i + 1].Range.Start;
                      si.paragraphsEnd = doc.Paragraphs[i + 1].Range.End;
                  }
                  else
                  {
                      si.paragraphsStart = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.Start;
                      si.paragraphsEnd = doc.Range(ref start1, ref end1).Paragraphs[i + 1].Range.End;
                  }
                  if (MartianSpot.checkThisContentIsInTable(si.paragraphsStart, doc))//判断是否在表格范围
                  {
                      list.Add(si);
                  }
              }
          }
      }
      //排序题目信息(SubjectInfo)列表
      list.Sort(MartianSpot.CompareSubJectInfo);
      return list;
 }
示例#3
0
        /// <summary>
        /// 匹配大题结构
        /// </summary>
        /// <param name="doc">匹配的文档</param>
        /// <param name="progressBarSpot">匹配进度条</param>
        /// <param name="matchArray">对应试题层次匹配正则表达式</param>
        /// <returns></returns>
        public static List<SubjectInfo> SubjectSpot(Microsoft.Office.Interop.Word.Document doc, string[] matchArray)
        {
            List<SubjectInfo> list = new List<SubjectInfo>();
             int count = doc.Paragraphs.Count;
             for (int i = 0; i < count; i++)
             {
                 object text = doc.Paragraphs[i + 1].Range.Text;
                 if (text.ToString().Length > 3)//通过字段长度过滤来提高性能;
                 {
                     if (MatchContent.match(matchArray, text.ToString().TrimStart()))
                     {
                         SubjectInfo si = new SubjectInfo();
                         si.paragraphsNum = i;
                         si.paragraphsStart = doc.Paragraphs[i + 1].Range.Start;
                         si.paragraphsEnd = doc.Paragraphs[i + 1].Range.End;
                         if (MartianSpot.checkThisContentIsInTable(si.paragraphsStart, doc))//判断是否在表格范围
                         {
                             list.Add(si);
                         }
                     }

                     if (MatchContent.match(MatchArray.publicAnswer, text.ToString().TrimStart()))
                     {
                         SubjectInfo si = new SubjectInfo();
                         si.paragraphsNum = i;
                         si.paragraphsStart = doc.Paragraphs[i + 1].Range.Start;
                         si.paragraphsEnd = doc.Paragraphs[i + 1].Range.End;
                         if (MartianSpot.checkThisContentIsInTable(si.paragraphsStart, doc))//判断是否在表格范围
                         {
                             list.Add(si);
                         }
                         break;
                     }
                 }
             }
             //排序题目信息(SubjectInfo)列表
             list.Sort(MartianSpot.CompareSubJectInfo);
             return list;
        }