package com.kalnee.trivor.engine.insights.generators;

import static com.kalnee.trivor.engine.utils.CollectionUtils.*;
import static com.kalnee.trivor.engine.utils.TagsEnum.*;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;

import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.kalnee.trivor.engine.models.Insight;
import com.kalnee.trivor.engine.models.Sentence;
import com.kalnee.trivor.engine.models.Subtitle;

public class PresentPerfectGenerator implements InsightGenerator<List<String>> {

	private static final Logger LOGGER = LoggerFactory.getLogger(PresentPerfectGenerator.class);

	private static final List<String> MUST_CONTAIN = Arrays.asList(
		"Have", "Has", "Haven't", "Hasn't", "haven't", "hasn't", "have", "has", "'ve"
	);
	private static final List<String> MUST_CONTAIN_NON_3RD = Arrays.asList(VBP.name(), VBN.name(), PRP.name());
	private static final List<String> MUST_CONTAIN_3RD = Arrays.asList(VBZ.name(), VBN.name(), PRP.name());
	private static final List<String> MUST_NOT_CONTAIN = Arrays.asList(
		VBG.name(), VBD.name()
	);

	@Override
	public String getDescription() {
		return "Present Perfect Tense";
	}

	@Override
	public String getCode() {
		return "present-perfect";
	}

	public Insight<List<String>> getInsight(Subtitle subtitle) {
		final List<String> sentences = subtitle.getSentences()
			.stream()
			.filter(s -> anyMatch(s.getSentence(), MUST_CONTAIN)
				&& (allMatch(s.getSentenceTags(), MUST_CONTAIN_NON_3RD) || allMatch(s.getSentenceTags(), MUST_CONTAIN_3RD))
				&& noneMatch(s.getSentenceTags(), MUST_NOT_CONTAIN))
			.map(Sentence::getSentence)
			.collect(toList());

		LOGGER.info(
			format("%s: %d/%d (%.2f%%)", getCode(), sentences.size(), subtitle.getSentences().size(),
			(sentences.size() * 100d / subtitle.getSentences().size()))
		);

		return new Insight<>(getCode(), sentences);
	}
}

@@ -47,39 +47,32 @@
 rators;%0A%0Aimport 
-static 
 com.kalnee.trivo
@@ -84,31 +84,22 @@
 ine.
-utils.CollectionUtils.*
+models.Insight
 ;%0Aim
@@ -103,23 +103,16 @@
 %0Aimport 
-static 
 com.kaln
@@ -132,113 +132,129 @@
 ine.
-utils.TagsEnum.*;%0Aimport static java.lang.String.format;%0Aimport static java.util.stream.Collectors.toList
+models.Sentence;%0Aimport com.kalnee.trivor.engine.models.Subtitle;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0A%0Ai
@@ -312,65 +312,14 @@
 ort 
-org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport
+static
  com
@@ -336,38 +336,47 @@
 ivor.engine.
-models.Insight
+utils.CollectionUtils.*
 ;%0Aimport com
@@ -364,32 +364,39 @@
 Utils.*;%0Aimport 
+static 
 com.kalnee.trivo
@@ -408,72 +408,113 @@
 ine.
-models.Sentence;%0Aimport com.kalnee.trivor.engine.models.Subtitle
+utils.TagsEnum.*;%0Aimport static java.lang.String.format;%0Aimport static java.util.stream.Collectors.toList
 ;%0A%0Ap
@@ -1149,16 +1149,147 @@
 me()%0A%09);
+%0A%09private static final List%3CString%3E MUST_NOT_CONTAIN_MODAL = Arrays.asList(%0A            %22will%22, %22Will%22, %22won't%22, %22Won't%22, %22'll%22%0A%09);
 %0A%0A%09@Over
@@ -1790,16 +1790,85 @@
 CONTAIN)
+%0A                && anyMatch(s.getSentence(), MUST_NOT_CONTAIN_MODAL)
 )%0A%09%09%09.ma

Fix Present Perfect tests