private void buildInstanceList(String file) throws IOException {

		System.out.print("generating training instances ...");

		CoNLLReader reader = new CoNLLReader(file);

		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream(fp), charset));
		
		LabelAlphabet postagAlphabet = factory.buildLabelAlphabet("postag");

		int count = 0;
		while (reader.hasNext()) {

			Sentence instance = (Sentence) reader.next();
			int[] heads = (int[]) instance.getTarget();
			ParsingState state = new ParsingState(instance,factory);
			while (!state.isFinalState()) {
				// 左右焦点词在句子中的位置
				int[] lr = state.getFocusIndices();

				HashSparseVector features = state.getFeatures();
				ParsingState.Action action = getAction(lr[0], lr[1],
						heads);
				state.next(action);
				if (action == ParsingState.Action.LEFT)
					heads[lr[1]] = -1;
				if (action == ParsingState.Action.RIGHT)
					heads[lr[0]] = -1;

				// writer.write(String.valueOf(instance.postags[lr[0]]));
				String pos = instance.getTagAt(lr[0]);
				postagAlphabet.lookupIndex(pos);
				writer.write(pos);
				writer.write(" ");
				switch (action) {
				case LEFT:
					writer.write("L");
					break;
				case RIGHT:
					writer.write("R");
					break;
				default:
					writer.write("S");
				}
				writer.write(" ");
				int[] idx = features.indices();
				Arrays.sort(idx);
				for (int i = 0; i < idx.length; i++) {
					writer.write(String.valueOf(idx[i]));
					writer.write(" ");
				}
				writer.newLine();

			}
			writer.write('\n');
			writer.flush();
			count++;
		}
		writer.close();

		System.out.println(" ... finished");
		System.out.printf("%d instances have benn loaded.\n\n", count);
	}
private void buildInstanceList ( String file ) throws IOException { System . out . print ( "generating training instances ..." ) ; CoNLLReader reader = new CoNLLReader ( file ) ; BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( fp ) , charset ) ) ; LabelAlphabet postagAlphabet = factory . buildLabelAlphabet ( "postag" ) ; int count = 0 ; while ( reader . hasNext ( ) ) { Sentence instance = ( Sentence ) reader . next ( ) ; int [ ] heads = ( int [ ] ) instance . getTarget ( ) ; ParsingState state = new ParsingState ( instance , factory ) ; while ( ! state . isFinalState ( ) ) { int [ ] lr = state . getFocusIndices ( ) ; HashSparseVector features = state . getFeatures ( ) ; ParsingState . Action action = getAction ( lr [ 0 ] , lr [ 1 ] , heads ) ; state . next ( action ) ; if ( action == ParsingState . Action . LEFT ) heads [ lr [ 1 ] ] = - 1 ; if ( action == ParsingState . Action . RIGHT ) heads [ lr [ 0 ] ] = - 1 ; String pos = instance . getTagAt ( lr [ 0 ] ) ; postagAlphabet . lookupIndex ( pos ) ; writer . write ( pos ) ; writer . write ( " " ) ; switch ( action ) { case LEFT : writer . write ( "L" ) ; break ; case RIGHT : writer . write ( "R" ) ; break ; default : writer . write ( "S" ) ; } writer . write ( " " ) ; int [ ] idx = features . indices ( ) ; Arrays . sort ( idx ) ; for ( int i = 0 ; i < idx . length ; i ++ ) { writer . write ( String . valueOf ( idx [ i ] ) ) ; writer . write ( " " ) ; } writer . newLine ( ) ; } writer . write ( '\n' ) ; writer . flush ( ) ; count ++ ; } writer . close ( ) ; System . out . println ( " ... finished" ) ; System . out . printf ( "%d instances have benn loaded.\n\n" , count ) ; }
生成训练实例

以Yamada分析算法，从单个文件中生成特征以及训练样本

@param file
单个训练文件
@throws Exception