package cz.brmlab.yodaqa.io.interactive;

import org.apache.uima.UimaContext;
import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.FSIndex;
import org.apache.uima.cas.FSIterator;
import org.apache.uima.fit.component.JCasConsumer_ImplBase;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;

import cz.brmlab.yodaqa.model.FinalAnswer.Answer;

/**
 * A trivial consumer that will extract the final answer and print it
 * on the standard output for the user to "officially" see.
 *
 * Pair this with InteractiveCollectionReader.
 */

public class InteractiveAnswerPrinter extends JCasConsumer_ImplBase {

	public void initialize(UimaContext context)
			throws ResourceInitializationException {
		super.initialize(context);
	}

	public void process(JCas jcas) throws AnalysisEngineProcessException {
		FSIndex idx = jcas.getJFSIndexRepository().getIndex("SortedAnswers");
		FSIterator answers = idx.iterator();
		if (answers.hasNext()) {
			Answer answer = (Answer) answers.next();
			System.out.println(answer.getText());
		} else {
			System.out.println("No answer found.");
		}
	}
}

@@ -1020,16 +1020,62 @@
 xt()) %7B%0A
+%09%09%09int i = 1;%0A%09%09%09while (answers.hasNext()) %7B%0A%09
 %09%09%09Answe
@@ -1109,24 +1109,25 @@
 .next();%0A%09%09%09
+%09
 System.out.p
@@ -1133,16 +1133,31 @@
 println(
+(i++) + %22. %22 + 
 answer.g
@@ -1164,18 +1164,67 @@
 etText()
-);
+ + %22 (conf. %22 + answer.getConfidence() + %22)%22);%0A%09%09%09%7D
 %0A%09%09%7D els

Print all answer records including their confidence and rank