package com.mattbachmann.nlpexperiments.detectors;

import com.mattbachmann.nlpexperiments.utils.TextUtils;
import opennlp.tools.namefind.NameFinderME;
import opennlp.tools.util.Span;

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

public abstract class AbstractNameDetector implements Detector {
    private final NameFinderME nameFinder;

    protected AbstractNameDetector(NameFinderME nameFinder) {
        this.nameFinder = nameFinder;
    }

    public List<String> findAll(String text) {
        List<String> results = new ArrayList<>();

        TextUtils.tokenizeBySentence(text).forEach(tokens -> {
            Span[] nameSpans = nameFinder.find(tokens);
            String[] names = Span.spansToStrings(nameSpans, tokens);
            results.addAll(Arrays.asList(names));
        });

        return results;
    }
}

@@ -514,24 +514,163 @@
 ing text) %7B%0A
+        return this.findAll(TextUtils.tokenizeBySentence(text));%0A    %7D%0A%0A    public List%3CString%3E findAll(List%3CString%5B%5D%3E tokensBySentence) %7B%0A
         List
@@ -716,34 +716,22 @@
         
-TextUtils.
 token
-ize
+s
 BySenten
@@ -732,22 +732,16 @@
 Sentence
-(text)
 .forEach

add a method that takes the tokens in directly so I only have to tokenize text once if I run something over multiple models