package cz.brmlab.brmson.blanqa.analysis;

import java.util.LinkedList;
import java.util.List;

import org.oaqa.model.SearchResult;

import cz.brmlab.brmson.blanqa.framework.data.Sentence;
import cz.brmlab.brmson.core.provider.opennlp.OpenNLPWrapper;

/**
 * Split text to a series of sentences.
 */

public class SentenceSplitter {
	private static final int MIN_SENTENCE_LENGTH = 3;

	/**
	 * Split a given result with a given text (may be preprocessed)
	 * to a list of contextualized sentences.
	 */
	public static List<Sentence> split(SearchResult srcResult, String srcText) {
		String[] sentenceTexts = OpenNLPWrapper.sentDetect(srcText);

		LinkedList<Sentence> sentences = new LinkedList<Sentence>();
		for (String text : sentenceTexts) {
			if (text.length() <= MIN_SENTENCE_LENGTH)
				continue;
			Sentence s = new Sentence(srcResult, text);
			if (sentences.size() > 0) {
				s.setPrev(sentences.getLast());
				sentences.getLast().setNext(s);
			}
			sentences.add(s);
		}

		return sentences;
	}

	public static void initialize() throws Exception {
		OpenNLPWrapper.initialize();
	}
}

@@ -1003,16 +1003,225 @@
 es;%0A%09%7D%0A%0A
+%09public static String join(List%3CSentence%3E sentences) %7B%0A%09%09StringBuilder sb = new StringBuilder();%0A%09%09for (Sentence s : sentences) %7B%0A%09%09%09sb.append(s.getText());%0A%09%09%09sb.append(%22. %22);%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D%0A%0A
 %09public 

New method