package annotators;

import static org.apache.uima.fit.util.JCasUtil.select;

import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.fit.component.JCasAnnotator_ImplBase;
import org.apache.uima.jcas.JCas;

import types.TextualSegment;
import de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token;

import java.util.ArrayList;
import java.util.regex.*;

public class TextualSegmentAnnotator extends JCasAnnotator_ImplBase {
	//private String boundary_regex_ = "([0-9]+)|(\\.|@|_|\\/|\\\\|:)";
			
	@Override
	public void process(JCas jCas) throws AnalysisEngineProcessException {
		// TODO Auto-generated method stub
		/*/
		Pattern p = Pattern.compile(boundary_regex_); 
		Matcher m = p.matcher(jCas.getDocumentText());
		
		ArrayList<Integer> l = new ArrayList<Integer>();
		int pred = 0;
		while(m.find()) {
			TextualSegment b = new TextualSegment(jCas, pred, Math.max(m.start(0), m.start(1)));
			b.addToIndexes();
			pred = Math.max(m.start(0), m.start(1))+(Math.max(m.end(0), m.end(1)) - Math.max(m.start(0), m.start(1)))+1;
		}
		//*/
		ArrayList<Character> digits = new ArrayList<Character>();
		for (Character i = '0'; i != '9'+1; ++i)
			digits.add(i);
		ArrayList<Character> caps = new ArrayList<Character>();
		for (Character i = 'A'; i != 'Z' + 1; ++i)
			caps.add(i);
		String text = jCas.getDocumentText() + " ";
		int pred = 0;
		boolean skip = false;
		boolean digit_read = false;
		for(int i = 0; i < text.length(); ++i) {
			if (skip) {
				skip = false;
				continue;
			}
			if (text.charAt(i) == '.' && (text.charAt(i+1) == ' ' || text.charAt(i+1) == '\n')) {
				TextualSegment seg = new TextualSegment(jCas, pred, i);
				seg.addToIndexes();
				pred = i+2;
				skip = true;
			}
			else if (text.charAt(i) == '\n' && caps.contains(text.charAt(i+1))) {
				TextualSegment seg = new TextualSegment(jCas, pred, i);
				seg.addToIndexes();
				pred = i+1;
			}
			else if (!digit_read && digits.contains(text.charAt(i))) {
				TextualSegment seg = new TextualSegment(jCas, pred, i);
				seg.addToIndexes();
				pred = i+1;
				skip = true;
				digit_read = true;
			}
			else if (digit_read && text.charAt(i) == ' ') {
				digit_read = false;
				pred = i+1;
			}
		}
	}

}

@@ -25,54 +25,26 @@
 ort 
-static org.apache.uima.fit.util.JCasUtil.selec
+java.util.ArrayLis
 t;%0A%0A
@@ -242,129 +242,8 @@
 ent;
-%0Aimport de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.regex.*;
 %0A%0Apu
@@ -314,77 +314,8 @@
 e %7B%0A
-%09//private String boundary_regex_ = %22(%5B0-9%5D+)%7C(%5C%5C.%7C@%7C_%7C%5C%5C/%7C%5C%5C%5C%5C%7C:)%22;%0A
 %09%09%09%0A
@@ -401,471 +401,8 @@
 n %7B%0A
-%09%09// TODO Auto-generated method stub%0A%09%09/*/%0A%09%09Pattern p = Pattern.compile(boundary_regex_); %0A%09%09Matcher m = p.matcher(jCas.getDocumentText());%0A%09%09%0A%09%09ArrayList%3CInteger%3E l = new ArrayList%3CInteger%3E();%0A%09%09int pred = 0;%0A%09%09while(m.find()) %7B%0A%09%09%09TextualSegment b = new TextualSegment(jCas, pred, Math.max(m.start(0), m.start(1)));%0A%09%09%09b.addToIndexes();%0A%09%09%09pred = Math.max(m.start(0), m.start(1))+(Math.max(m.end(0), m.end(1)) - Math.max(m.start(0), m.start(1)))+1;%0A%09%09%7D%0A%09%09//*/%0A
 %09%09Ar

remove some shitty comments