public static void convertPKUtoCWS(String inputFolder, String outputFile, final int begin, final int end) throws IOException
    {
        final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
        CorpusLoader.walk(inputFolder, new CorpusLoader.Handler()
                          {
                              int doc = 0;

                              @Override
                              public void handle(Document document)
                              {
                                  ++doc;
                                  if (doc < begin || doc > end) return;
                                  try
                                  {
                                      List<List<Word>> sentenceList = convertComplexWordToSimpleWord(document.getComplexSentenceList());
                                      if (sentenceList.size() == 0) return;
                                      for (List<Word> sentence : sentenceList)
                                      {
                                          if (sentence.size() == 0) continue;
                                          int index = 0;
                                          for (IWord iWord : sentence)
                                          {
                                              bw.write(iWord.getValue());
                                              if (++index != sentence.size())
                                              {
                                                  bw.write(' ');
                                              }
                                          }
                                          bw.newLine();
                                      }
                                  }
                                  catch (IOException e)
                                  {
                                      e.printStackTrace();
                                  }
                              }
                          }

        );
        bw.close();
    }
public static void convertPKUtoCWS ( String inputFolder , String outputFile , final int begin , final int end ) throws IOException { final BufferedWriter bw = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( outputFile ) , "UTF-8" ) ) ; CorpusLoader . walk ( inputFolder , new CorpusLoader . Handler ( ) { int doc = 0 ; @ Override public void handle ( Document document ) { ++ doc ; if ( doc < begin || doc > end ) return ; try { List < List < Word > > sentenceList = convertComplexWordToSimpleWord ( document . getComplexSentenceList ( ) ) ; if ( sentenceList . size ( ) == 0 ) return ; for ( List < Word > sentence : sentenceList ) { if ( sentence . size ( ) == 0 ) continue ; int index = 0 ; for ( IWord iWord : sentence ) { bw . write ( iWord . getValue ( ) ) ; if ( ++ index != sentence . size ( ) ) { bw . write ( ' ' ) ; } } bw . newLine ( ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } ) ; bw . close ( ) ; }
将人民日报格式的分词语料转化为空格分割的语料

@param inputFolder 输入人民日报语料的上级目录(该目录下的所有文件都是一篇人民日报分词文章)
@param outputFile  输出一整个CRF训练格式的语料
@param begin       取多少个文档之后
@param end
@throws IOException 转换过程中的IO异常