fixed computing of entities when the article does not have a description
[pnews.git] / war / src / main / java / pnews / servlet / ArticleProvider.java
index 5d4959b..bdba835 100644 (file)
@@ -4,6 +4,7 @@ import java.io.IOException;
 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;
@@ -116,10 +117,11 @@ public class ArticleProvider {
                 }
                                 
                 entities = new ArrayList<>();
-                if (desc != null && lang.equals("en"))
+                if (lang.equals("en"))
                         try {
                                 NER.classify(title, entities, config);
-                                NER.classify(desc, entities, config);
+                                if (desc != null)
+                                        NER.classify(desc, entities, config);
                         } catch (ClassCastException | ClassNotFoundException | IOException e1) {
                                 LOG.log(Level.SEVERE, "Cannot classify " + feedTitle, e1);                         
                         }
@@ -220,14 +222,17 @@ public class ArticleProvider {
                 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) {
@@ -236,8 +241,7 @@ public class ArticleProvider {
                                         }
                                         s.increment();
                                 }                
-                        }
-                
+               
                 stats = new ArrayList<>(entities.values());
                 stats.sort(new Comparator<EntityStat>() {