package de.tudarmstadt.awesome.erclaerung.pipeline;

import static org.apache.uima.fit.factory.AnalysisEngineFactory.createEngineDescription;
import static org.apache.uima.fit.factory.CollectionReaderFactory.createReaderDescription;
import static org.apache.uima.fit.factory.ExternalResourceFactory.createExternalResourceDescription;
import static org.apache.uima.fit.pipeline.SimplePipeline.runPipeline;

import java.io.File;
import java.util.Arrays;

import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.collection.CollectionReaderDescription;
import org.apache.uima.fit.component.CasDumpWriter;
import org.kohsuke.args4j.Argument;

import de.tudarmstadt.awesome.erclaerung.readers.BonnerXMLReader;
import de.tudarmstadt.ukp.dkpro.core.tokit.BreakIteratorSegmenter;
import de.tudarmstadt.ukp.dkpro.tc.core.Constants;
import de.tudarmstadt.ukp.dkpro.tc.core.task.uima.ExtractFeaturesConnector;
import de.tudarmstadt.ukp.dkpro.tc.features.length.NrOfSentencesDFE;
import de.tudarmstadt.ukp.dkpro.tc.features.length.NrOfTokensDFE;
import de.tudarmstadt.ukp.dkpro.tc.weka.writer.WekaDataWriter;

/**
 * This the main pipeline which is called when an analysis is supposed to take place
 * 
 * @author Patrick Lerner
 *
 */
public class AnalysisPipeline {
	private File input;

	@Argument
	public void setInputFile(File input) {
		this.input = input;
	}

	/**
	 * This method is called once the pipeline has been properly set up to start the process
	 */
	public void run() throws Exception {
		if (this.input == null)
			throw new RuntimeException("Input of pipeline is empty.");

		// Initialize the bonner korpora
		CollectionReaderDescription cr = createReaderDescription(BonnerXMLReader.class,
		                BonnerXMLReader.PARAM_SOURCE_LOCATION, "src/main/resources/bonner_korpora/*.xml");

		AnalysisEngineDescription seg = createEngineDescription(BreakIteratorSegmenter.class);

		Object[] featureExtractors = new Object[] { createExternalResourceDescription(NrOfTokensDFE.class),
		                createExternalResourceDescription(NrOfSentencesDFE.class) };

		AnalysisEngineDescription fea = createEngineDescription(ExtractFeaturesConnector.class,
		// output directory
		                ExtractFeaturesConnector.PARAM_OUTPUT_DIRECTORY, "target/temp_feature_output",
		                // writer
		                ExtractFeaturesConnector.PARAM_DATA_WRITER_CLASS, WekaDataWriter.class,
		                // learning mode (single label, i.e. only based on dialect for now)
		                ExtractFeaturesConnector.PARAM_LEARNING_MODE, Constants.LM_SINGLE_LABEL,
		                // whole document extraction
		                ExtractFeaturesConnector.PARAM_FEATURE_MODE, Constants.FM_DOCUMENT,
		                // probably good for something (copied from example)
		                ExtractFeaturesConnector.PARAM_ADD_INSTANCE_ID, true,
		                // which extractos are to be used
		                ExtractFeaturesConnector.PARAM_FEATURE_EXTRACTORS, Arrays.asList(featureExtractors));

		AnalysisEngineDescription cc = createEngineDescription(CasDumpWriter.class, CasDumpWriter.PARAM_OUTPUT_FILE,
		                "target/output.txt");

		runPipeline(cr, seg, fea, cc);
	}
}

@@ -2186,17 +2186,18 @@
 or.class
-,
+);
 %0A%09%09// ou
@@ -2213,32 +2213,38 @@
 ctory%0A%09%09
-                
+fea.setAttributeValue(
 ExtractF
@@ -2316,56 +2316,47 @@
 put%22
-,%0A%09%09                // writer%0A%09%09                
+);%0A%09%09// writer%0A%09%09fea.setAttributeValue(
 Extr
@@ -2425,114 +2425,76 @@
 lass
-,%0A%09%09                // learning mode (single label, i.e. only based on dialect for now)%0A%09%09                
+);%0A%09%09// single label (only dialect for now)%0A%09%09fea.setAttributeValue(
 Extr
@@ -2564,75 +2564,64 @@
 ABEL
-,%0A%09%09                // whole document extraction%0A%09%09                
+);%0A%09%09// scope is whole document%0A%09%09fea.setAttributeValue(
 Extr
@@ -2686,99 +2686,78 @@
 MENT
-,%0A%09%09                // probably good for something (copied from example)%0A%09%09                
+);%0A%09%09// something rather (was in the example)%0A%09%09fea.setAttributeValue(
 Extr
@@ -2808,36 +2808,27 @@
 true
-,%0A%09%09                // which
+);%0A%09%09// the feature
  ext
@@ -2836,14 +2836,11 @@
 acto
+r
 s 
-are 
 to b
@@ -2845,35 +2845,60 @@
  be used
-%0A%09%09                
+ (as defined above)%0A%09%09fea.setAttributeValue(
 ExtractF

Reformat the ugly text block caused by lack of conciseness in Java