package bschecker.bluesheets;

import bschecker.util.Error;
import bschecker.util.ErrorList;
import bschecker.util.Tools;
import bschecker.util.UtilityMethods;
import opennlp.tools.parser.Parse;

/**
 * Finds verbs in the passive voice. (9)
 * @author tedpyne
 * @author JeremiahDeGreeff
 */
public class PassiveVoice extends Bluesheet {
	
	private static final String[] TO_BE_CONJ = {"be", "am", "is", "are", "was", "were", "been", "being"};
	
	
	/**
	 * Finds all instances of passive voice in a paragraph.
	 * @param line the paragraph in which to find errors
	 * @param parses a Parse array of each sentence of the line
	 * @return an ErrorList which for each Error references start token, end token, and, optionally, a note
	 */
	@Override
	protected ErrorList findErrors(String line, Parse[] parses) {
		ErrorList errors = new ErrorList(line);
		int tokenOffset = 0;
		for(Parse parse : parses) {
			String sentence = parse.getText();
			ErrorList sentenceErrors = new ErrorList(sentence);
			String[] tokens = Tools.getTokenizer().tokenize(sentence);
			String[] tags = Tools.getPOSTagger().tag(tokens);
			for(int i = 1; i < tokens.length; i++)
				if(UtilityMethods.arrayContains(TO_BE_CONJ, tokens[i]) && i < tokens.length - 1) {
					int j = i + 1;
					while(tags[j].equals("RB") && j < tokens.length)
						j++;
					if(tags[j].equals("VBN"))
						sentenceErrors.add(new Error(i, j));
				}
			UtilityMethods.removeErrorsInQuotes(sentenceErrors, parse, false);
			errors.addAllWithOffset(sentenceErrors, tokenOffset);
			tokenOffset += tokens.length;
		}
		return errors;
	}
	
}

@@ -24,16 +24,45 @@
 heets;%0A%0A
+import java.util.ArrayList;%0A%0A
 import b
@@ -82,16 +82,16 @@
 .Error;%0A
-
 import b
@@ -267,27 +267,8 @@
 (9)%0A
- * @author tedpyne%0A
  * @
@@ -1006,245 +1006,252 @@
 %0A%09%09%09
-String%5B%5D tokens = Tools.getTokenizer().tokenize(sentence);%0A%09%09%09String%5B%5D tags = Tools.getPOSTagger().tag(token
+ArrayList%3CParse%3E vpParses = UtilityMethods.findParsesWithTag(parse, new String%5B%5D %7B%22VP%22%7D);%0A%09%09%09for(Parse vpParse : vpParse
 s)
-;
 %0A%09%09%09
-for(int i = 1; i %3C tokens.length; i++)%0A%09%09%09%09if(UtilityMethods.arrayContains(TO_BE_CONJ, tokens%5Bi%5D) && i %3C tokens.length - 1
+%09if(vpParse.getChildCount() %3E 1 && UtilityMethods.arrayContains(TO_BE_CONJ, vpParse.getChildren()%5B0%5D.getCoveredText())
 ) %7B%0A
@@ -1262,16 +1262,12 @@
 %09int
- j =
  i 
-+
+=
  1;%0A
@@ -1281,57 +1281,65 @@
 ile(
-tags%5Bj%5D.equals(%22RB%22) && j %3C tokens.length
+vpParse.getChildren()%5Bi%5D.getType().equals(%22ADVP%22)
 )%0A%09%09%09%09%09%09
 j++;
@@ -1334,17 +1334,17 @@
 )%0A%09%09%09%09%09%09
-j
+i
 ++;%0A%09%09%09%09
@@ -1351,30 +1351,220 @@
 %09if(
-tags%5Bj%5D.equals(%22VBN%22))
+vpParse.getChildren()%5Bi%5D.getType().equals(%22VP%22) && vpParse.getChildren()%5Bi%5D.getChildren()%5B0%5D.getType().equals(%22VBN%22)) %7B%0A%09%09%09%09%09%09int start = UtilityMethods.getIndexOfParse(vpParse.getChildren()%5B0%5D.getChildren()%5B0%5D);
 %0A%09%09%09
@@ -1599,15 +1599,34 @@
 ror(
-i, j));
+start, start + i));%0A%09%09%09%09%09%7D
 %0A%09%09%09
@@ -1777,14 +1777,54 @@
  += 
-tokens
+Tools.getTokenizer().tokenize(parse.getText())
 .len

rewrite passive voice to use parses