package cz.brmlab.yodaqa.pipeline;

//import de.tudarmstadt.ukp.dkpro.core.berkeleyparser.BerkeleyParser;
//import de.tudarmstadt.ukp.dkpro.core.clearnlp.ClearNlpDependencyParser;
//import de.tudarmstadt.ukp.dkpro.core.clearnlp.ClearNlpLemmatizer;
//import de.tudarmstadt.ukp.dkpro.core.clearnlp.ClearNlpPosTagger;
//import de.tudarmstadt.ukp.dkpro.core.clearnlp.ClearNlpSemanticRoleLabeler;
//import de.tudarmstadt.ukp.dkpro.core.maltparser.MaltParser;
//import de.tudarmstadt.ukp.dkpro.core.matetools.MateLemmatizer;
//import de.tudarmstadt.ukp.dkpro.core.matetools.MateParser;
//import de.tudarmstadt.ukp.dkpro.core.matetools.MatePosTagger;
//import de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpNameFinder;
//import de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpPosTagger;
import de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpSegmenter;
//import de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordLemmatizer;
//import de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordNamedEntityRecognizer;
//import de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordPosTagger;
import de.tudarmstadt.ukp.dkpro.core.stanfordnlp.StanfordParser;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.fit.component.CasDumpWriter;
import org.apache.uima.fit.factory.AggregateBuilder;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.resource.ResourceInitializationException;

import cz.brmlab.yodaqa.analysis.question.SVGenerator;
import cz.brmlab.yodaqa.analysis.question.FocusGenerator;
import cz.brmlab.yodaqa.analysis.question.ClueGenerator;
import cz.brmlab.yodaqa.analysis.question.LATGenerator;
import cz.brmlab.yodaqa.analysis.tycor.LATByWordnet;
import cz.brmlab.yodaqa.io.debug.DumpConstituents;

/**
 * Annotate the QuestionCAS.
 *
 * This is an aggregate AE that will run a variety of annotators on the
 * QuestionCAS, preparing it for the PrimarySearch and AnswerGenerator
 * stages. */

public class QuestionAnalysis /* XXX: extends AggregateBuilder ? */ {
	public static AnalysisEngineDescription createEngineDescription() throws ResourceInitializationException {
		AggregateBuilder builder = new AggregateBuilder();

		/* A bunch of DKpro-bound NLP processors (these are
		 * the giants we stand on the shoulders of) */

		/* XXX: Sorry for the mess below for now. We list all our
		 * alternatives for now, but will clean it up later. */

		/* Token features: */

		builder.add(AnalysisEngineFactory.createEngineDescription(OpenNlpSegmenter.class));

		/* POS, lemmas, constituents, dependencies: */
		// fast, reliable
		builder.add(AnalysisEngineFactory.createEngineDescription(
					StanfordParser.class,
					StanfordParser.PARAM_MAX_TOKENS, 40)); // more takes a lot of RAM and is sloow, StanfordParser is O(N^2)

		// slow startup, no dependencies, superseded
		//builder.add(AnalysisEngineFactory.createEngineDescription(BerkeleyParser.class));

		/* POS features: */

		// Generated by BerkeleyParser
		// fastest:
		//builder.add(AnalysisEngineFactory.createEngineDescription(OpenNlpPosTagger.class));
		/*
		builder.add(AnalysisEngineFactory.createEngineDescription(StanfordPosTagger.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(MatePosTagger.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(ClearNlpPosTagger.class));
		*/

		/* Lemma features: */

		// fastest and handling numbers correctly:
		//builder.add(AnalysisEngineFactory.createEngineDescription(StanfordLemmatizer.class));
		/*
		builder.add(AnalysisEngineFactory.createEngineDescription(ClearNlpLemmatizer.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(MateLemmatizer.class));
		*/

		/* Dependency features: */
		// no need for now

		// fastest and correct!
		//builder.add(AnalysisEngineFactory.createEngineDescription(MaltParser.class));
		/*
		// just wrong (Who received the Nobel Prize for Physiology and Medicine in the year 2012?) - everything depends on medicine
		builder.add(AnalysisEngineFactory.createEngineDescription(MateParser.class));
		// a bit wrong (Who received the Nobel Prize for Physiology and Medicine in the year 2012?) - 2012 depends on received
		builder.add(AnalysisEngineFactory.createEngineDescription(ClearNlpDependencyParser.class));
		*/

		/* Named Entities: */

		/*
		// sort of nice but we don't have use for them yet
		String[] ner_variants = {
		      "date", "location", "money", "organization",
		      "percentage", "person", "time"
		};
		for (String variant : ner_variants) {
			builder.add(AnalysisEngineFactory.createEngineDescription(
				OpenNlpNameFinder.class,
				OpenNlpNameFinder.PARAM_VARIANT, variant));
		}
		// too weak, we need very rich NE set
		builder.add(AnalysisEngineFactory.createEngineDescription(StanfordNamedEntityRecognizer.class));
		*/

		/* ...and misc extras: */

		/*
		// too sparse to be useful
		builder.add(AnalysisEngineFactory.createEngineDescription(ClearNlpSemanticRoleLabeler.class));
		*/


		/* Okay! Now, we can proceed with our key tasks. */

		builder.add(AnalysisEngineFactory.createEngineDescription(FocusGenerator.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(SVGenerator.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(ClueGenerator.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(LATGenerator.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(LATByWordnet.class));


		/* Some debug dumps of the intermediate CAS. */
		/* builder.add(AnalysisEngineFactory.createEngineDescription(DumpConstituents.class));
		builder.add(AnalysisEngineFactory.createEngineDescription(
			CasDumpWriter.class,
			CasDumpWriter.PARAM_OUTPUT_FILE, "/tmp/yodaqa-qacas.txt")); */

		return builder.createAggregateDescription();
	}
}

@@ -2635,22 +2635,16 @@
 ription(
-%0A%09%09%09%09%09
 Stanford
@@ -2659,119 +2659,11 @@
 lass
-,%0A%09%09%09%09%09StanfordParser.PARAM_MAX_TOKENS, 40)); // more takes a lot of RAM and is sloow, StanfordParser is O(N%5E2)
+));
 %0A%0A%09%09

Drop the StanfordParser token limit for a question