// perform the window parsing - used to do coreref, plus get initial named entities, sentiment, and tokens
public static Document parse(String text, int windowSize, JSONArray spacyEntities, JSONArray dbpediaEntities) {
		Document result = new Document();
		result._originaltext = text;
		result._sentences    = new java.util.ArrayList<Sentence>();
		List<String> splitSentences = StanfordNLP.splitSentences(text);
		int lastFoundPosition = -1;
		int lastSentenceLength = 1;
		int sentenceCount      = 0;
		int runningSentinmentScore = 0; 
		// perform the window parsing - used to do coreref, plus get initial named entities, sentiment, and tokens
		for (int sentenceIndex = 0; sentenceIndex < splitSentences.size(); sentenceIndex++) {
			SplitResult sr = getTextWindow(splitSentences, sentenceIndex,windowSize);
			Annotation sentenceDoc = StanfordNLP.annotateText(sr.text);
		    List<CoreMap> sentences = sentenceDoc.get(CoreAnnotations.SentencesAnnotation.class);
		    CoreMap sentence = sentences.get(sr.sentencePositionToUse);
	    	sentenceCount++;
	    	String sentenceText = sentence.get(CoreAnnotations.TextAnnotation.class);
	    	int documentPosition = text.indexOf(sentenceText,lastFoundPosition);
	    	if (documentPosition == -1) { 
	    		documentPosition = lastFoundPosition + lastSentenceLength;
	    	}
	    	java.util.List<Token> sentenceTokens = Token.extractTokens(sentence, sentenceCount);
	    	Sentence s = new Sentence(sentenceText, documentPosition, sentenceCount, sentenceTokens);
	    	Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
            int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
            s.setSentiment(sentiment);
            runningSentinmentScore += sentiment;
            List<String> resolvedSentences = Coreference.resolveCoreferences(sentenceDoc);
            s.setCorefText(resolvedSentences.get(sr.sentencePositionToUse));
	    	result._sentences.add(s);
	    	lastFoundPosition = documentPosition;
	    	lastSentenceLength = sentenceText.length();
		}
		result._sentimentScore =  ((double) runningSentinmentScore) / sentenceCount;
		// reparse to get openIE / relations items
		int baseSentenceIndex = -1;
		for (Sentence s: result._sentences) {
			Annotation sentenceDoc = StanfordNLP.annotateText(s.getCorefText());
			baseSentenceIndex++;
			java.util.List<Token> sentenceTokens = Token.extractTokens(sentenceDoc.get(CoreAnnotations.SentencesAnnotation.class).get(0), baseSentenceIndex);
			java.util.List<TripleRelation> triples = TripleRelation.extractTriples(sentenceDoc, baseSentenceIndex);
			triples = TripleRelation.valiadateTriples(triples, sentenceTokens);
			List<AnnotatedProposition> minieTriplesAP =  StanfordNLP.extractMinIETriples(s.getCorefText());
			java.util.List<TripleRelation> minetriples = TripleRelation.extractTriples(minieTriplesAP, baseSentenceIndex);
			minetriples = TripleRelation.valiadateTriples(minetriples, sentenceTokens);
			java.util.List<TripleRelation> combinedTriples = TripleRelation.combine(triples, minetriples);
			combinedTriples = TripleRelation.reduceTriples(combinedTriples, FilterStyle.FILTER_TO_MAXIMIZE_SUBJ_OBJ_MINIMIZE_RELATION);
			//combinedTriples = TripleRelation.reduceTriples(combinedTriples, FilterStyle.FILTER_TO_MINIMIZE_TERMS);
			TripleRelation.augmentSubjectObjectWithStanfordNER(combinedTriples,s.getNamedEntities());
			TripleRelation.augmentSubjectObjectWithSpacyNER(combinedTriples, spacyEntities, s.getStartPosition(), s.getStartPosition() + s.getOriginalText().length());
			TripleRelation.augmentSubjectObjectWithDBPedia(combinedTriples, dbpediaEntities, s.getStartPosition(), s.getStartPosition() + s.getOriginalText().length());
			s.setTripleRelations(combinedTriples);
		}
		return result;
	}
int sentenceCount = 0;
int runningSentinmentScore = 0;
// perform the window parsing - used to do coreref, plus get initial named entities, sentiment, and tokens
for (int sentenceIndex = 0; sentenceIndex < splitSentences.size(); sentenceIndex++) {
SplitResult sr = getTextWindow(splitSentences, sentenceIndex,windowSize);
public static Document parse(String text, int windowSize, JSONArray spacyEntities, JSONArray dbpediaEntities) {
Document result = new Document();
result._originaltext = text;
result._sentences = new java.util.ArrayList<Sentence>();
List<String> splitSentences = StanfordNLP.splitSentences(text);
int lastFoundPosition = -1;
int lastSentenceLength = 1;
int sentenceCount = 0;
int runningSentinmentScore = 0;
// perform the window parsing - used to do coreref, plus get initial named entities, sentiment, and tokens
for (int sentenceIndex = 0; sentenceIndex < splitSentences.size(); sentenceIndex++) {
SplitResult sr = getTextWindow(splitSentences, sentenceIndex,windowSize);
Annotation sentenceDoc = StanfordNLP.annotateText(sr.text);
List<CoreMap> sentences = sentenceDoc.get(CoreAnnotations.SentencesAnnotation.class);
CoreMap sentence = sentences.get(sr.sentencePositionToUse);
sentenceCount++;
String sentenceText = sentence.get(CoreAnnotations.TextAnnotation.class);
int documentPosition = text.indexOf(sentenceText,lastFoundPosition);
if (documentPosition == -1) {
documentPosition = lastFoundPosition + lastSentenceLength;
public static Document parse(String text, int windowSize, JSONArray spacyEntities, JSONArray dbpediaEntities) {
Document result = new Document();
result._originaltext = text;
result._sentences = new java.util.ArrayList<Sentence>();
List<String> splitSentences = StanfordNLP.splitSentences(text);
int lastFoundPosition = -1;
int lastSentenceLength = 1;
int sentenceCount = 0;
int runningSentinmentScore = 0;
// perform the window parsing - used to do coreref, plus get initial named entities, sentiment, and tokens
for (int sentenceIndex = 0; sentenceIndex < splitSentences.size(); sentenceIndex++) {
SplitResult sr = getTextWindow(splitSentences, sentenceIndex,windowSize);
Annotation sentenceDoc = StanfordNLP.annotateText(sr.text);
List<CoreMap> sentences = sentenceDoc.get(CoreAnnotations.SentencesAnnotation.class);
CoreMap sentence = sentences.get(sr.sentencePositionToUse);
sentenceCount++;
String sentenceText = sentence.get(CoreAnnotations.TextAnnotation.class);
int documentPosition = text.indexOf(sentenceText,lastFoundPosition);
if (documentPosition == -1) {
documentPosition = lastFoundPosition + lastSentenceLength;
}
java.util.List<Token> sentenceTokens = Token.extractTokens(sentence, sentenceCount);
Sentence s = new Sentence(sentenceText, documentPosition, sentenceCount, sentenceTokens);
Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
s.setSentiment(sentiment);
runningSentinmentScore += sentiment;
List<String> resolvedSentences = Coreference.resolveCoreferences(sentenceDoc);
s.setCorefText(resolvedSentences.get(sr.sentencePositionToUse));
result._sentences.add(s);