blacklisted entities are now in the configuration file
[pnews.git] / war / src / main / java / pnews / servlet / ArticleProvider.java
index 4e85e83..ec74123 100644 (file)
@@ -74,7 +74,7 @@ public class ArticleProvider {
                 return false;
         }
         
-        private static Article toArticle(String link, SyndEntry entry, SyndFeed feed, String lang) {
+        private Article toArticle(String link, SyndEntry entry, SyndFeed feed, String lang) {
                 String desc, title, thumbnail, feedTitle, str;
                 Date date;
                 List<String> entities;
@@ -111,8 +111,8 @@ public class ArticleProvider {
                 entities = new ArrayList<>();
                 if (desc != null && lang.equals("en"))
                         try {
-                                NER.classify(title, entities);
-                                NER.classify(desc, entities);
+                                NER.classify(title, entities, config);
+                                NER.classify(desc, entities, config);
                         } catch (ClassCastException | ClassNotFoundException | IOException e1) {
                                 LOG.log(Level.SEVERE, "Cannot classify " + feedTitle, e1);                         
                         }
@@ -181,16 +181,24 @@ public class ArticleProvider {
         /**
          * Returns a copy.
          */
-        public List<Article> getArticles(Category cat)
+        public List<Article> getArticles(Category cat, String entity)
                         throws IllegalArgumentException, MalformedURLException, FeedException, IOException {
-                List<Article> articles;
+                List<Article> articles, result;                
                 
                 synchronized (articlesByCategory) {
                         articles = getArticlesForUpdate(cat);
                 }
                 
-                synchronized (articles) {
-                        return new ArrayList<>(articles);
+                synchronized (articles) {                       
+                        if (entity == null)
+                                return new ArrayList<>(articles);
+                        
+                        result = new ArrayList<>(articles.size());
+                        for (Article a: articles)
+                                if (a.hasEntity(entity))
+                                        result.add(a);
+                        
+                        return result;
                 }
         }
         
@@ -203,7 +211,7 @@ public class ArticleProvider {
                 
                 LOG.entering(CLASS_NAME, FUNCTION_NAME, cat);
                 
-                articles = getArticles(cat);
+                articles = getArticles(cat, null);
                 
                 entities = new HashMap<>();
                 for (Article a: articles)