@Override
  public void processCas(CAS aCAS) throws ResourceProcessException {
    // TODO Auto-generated method stub
    // String modelFileName = null;

    JCas jcas;
    try {
      jcas = aCAS.getJCas();
    } catch (CASException e) {
      throw new ResourceProcessException(e);
    }
    FSIterator it = jcas.getAnnotationIndex(MyTypeSystem.type).iterator();
    // String outFileName = "sample.out";
    String sent = jcas.getDocumentText();
    File outFile = new File(mOutputDir, mOutputName);

    while (it.hasNext()) {
      MyTypeSystem mts = (MyTypeSystem) it.next();
      int start = mts.getStart();
      int end = mts.getEnd();
      int ws = 0;
      String subs = sent.substring(0, start);
      for (char c : subs.toCharArray()) {
        if (c == ' ') {
          ws++;
        }
      }
      int wss = ws;
      subs = sent.substring(start, end);
      for (char c : subs.toCharArray()) {
        if (c == ' ') {
          ws++;
        }
      }
      ws++;
      start -= wss;
      end -= ws;

      String str = mts.getMark() + "|" + start+ " " + end + "|" + mts.getGene()
              + "\n";
      // serialize XCAS and write to output file
      FileWriter writer = null;
      BufferedWriter bw = null;
      try {
        writer = new FileWriter(outFile, true);
        bw = new BufferedWriter(writer);
        bw.append(str);

      } catch (IOException e) {
        throw new ResourceProcessException(e);
      } finally {
        try {
          bw.close();
        } catch (Exception ex) {
        }
        try {
          writer.close();
        } catch (Exception ex) {
        }

      }
    }
  }