package mpqareader; import se.lth.cs.nlp.nlputils.annotations.*; import java.util.*; public class ExtractSubjSent { private static int nclue1, nclue2, nobj; private static boolean isXMLTag(String s) { return s.contains("<") || s.contains(">"); } private static void printSentence(String[] tokens, int start, int end, String[] cls) { if(end - start > 2 && tokens[start].equals("AR") && tokens[start+1].equals(":")) { return; } if(end - start > 2 && tokens[start].equals("EN") && tokens[start+1].equals(":")) { start += 2; } while(start < end && start < tokens.length && isXMLTag(tokens[start])) start++; if(start >= end) return; if(cls == null) System.out.println(""); else { System.out.print(""); } for(int i = start; i < end; i++) { String t = tokens[i]; if(!isXMLTag(t)) System.out.println(tokens[i]); } System.out.println(); } private static void processText(AnnotatedText text) { System.err.println(text.getProperty("mpqa_file")); System.out.println(""); AnnotationLayer senLayer = text.layers.get(0); for(Span sen: (AnnotationLayer) senLayer) { String[] cls = MPQAToLK.classifySubjSen(sen, text); if(cls == null) nobj++; printSentence(text.tokens, sen.tokenStart, sen.tokenEnd, cls); } } public static void main(String[] argv) { Iterator i = MPQAReader.processDirectory(argv[0]); while(i.hasNext()) { AnnotatedText t = i.next(); processText(t); } System.err.println(nclue1); System.err.println(nclue2); System.err.println(nobj); } }