private static TokenNameFinderModel organizationModel;
private static TokenNameFinderModel personModel;
private static TokenNameFinderModel locationModel;
- private static TokenNameFinderModel timeModel;
private static TokenizerModel tokenModel;
public static List<String> classify(String str, List<String> entities, Config config) throws IOException {
classify(str, getOrganizationModel(), entities, config);
-
classify(str, getPersonModel(), entities, config);
classify(str, getLocationModel(), entities, config);
- classify(str, getTimeModel(), entities, config);
-
return entities;
}
return locationModel;
}
-
- private static TokenNameFinderModel getTimeModel() throws IOException {
- synchronized (OpenNLP.class) {
- if (timeModel == null) {
- InputStream inputStream = OpenNLP.class.getResourceAsStream("/en-ner-time.bin");
- timeModel = new TokenNameFinderModel(inputStream);
- }
- }
-
- return timeModel;
- }
private static List<String> classify(String str, TokenNameFinderModel model, List<String> entities, Config config) throws IOException {
String entity;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Instant;
+import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
final String FUNCTION_NAME = "getEntities";
EntityStat s;
List<EntityStat> stats;
+ Instant minInstant;
LOG.entering(CLASS_NAME, FUNCTION_NAME, cat);
articles = getArticles(cat, null);
+ minInstant = Instant.now().minus(15, ChronoUnit.DAYS);
+
entities = new HashMap<>();
- for (Article a: articles)
- if (a.getEntities() != null) {
+ for (Article a: articles)
+ if (a.getPublicationDate().isAfter(minInstant) && a.getEntities() != null)
for (String e: a.getEntities()) {
s = entities.get(e);
if (s == null) {
}
s.increment();
}
- }
-
+
stats = new ArrayList<>(entities.values());
stats.sort(new Comparator<EntityStat>() {