cleanup and refactored to move to net.wpitchoune package
[pnews.git] / war / src / main / java / pnews / servlet / ArticleProvider.java
index bdba835..55898a4 100644 (file)
@@ -27,11 +27,13 @@ import com.rometools.rome.io.FeedException;
 import com.rometools.rome.io.SyndFeedInput;
 import com.rometools.rome.io.XmlReader;
 
-import pnews.Article;
-import pnews.Category;
-import pnews.EntityStat;
-import pnews.Feed;
-import pnews.NER;
+import net.wpitchoune.pnews.Article;
+import net.wpitchoune.pnews.ArticleStore;
+import net.wpitchoune.pnews.Category;
+import net.wpitchoune.pnews.Config;
+import net.wpitchoune.pnews.EntityStat;
+import net.wpitchoune.pnews.Feed;
+import net.wpitchoune.pnews.classifier.NamedEntityRecognizer;
 
 public class ArticleProvider {
         private static final String CLASS_NAME = ArticleProvider.class.getName();
@@ -70,7 +72,7 @@ public class ArticleProvider {
         private boolean exists(String articleLink, List<Article> articles) {
                 synchronized (articles) {
                         for (Article a: articles)
-                                if (a.link.equals(articleLink))
+                                if (a.getLink().equals(articleLink))
                                         return true;
                 }
                 return false;
@@ -91,7 +93,6 @@ public class ArticleProvider {
         
         private Article toArticle(String link, SyndEntry entry, SyndFeed feed, String lang, Instant instant) {
                 String desc, title, thumbnail, feedTitle, str;
-                Date date;
                 List<String> entities;
                 
                 feedTitle = feed.getTitle();
@@ -119,9 +120,9 @@ public class ArticleProvider {
                 entities = new ArrayList<>();
                 if (lang.equals("en"))
                         try {
-                                NER.classify(title, entities, config);
+                                NamedEntityRecognizer.classify(title, entities, config);
                                 if (desc != null)
-                                        NER.classify(desc, entities, config);
+                                        NamedEntityRecognizer.classify(desc, entities, config);
                         } catch (ClassCastException | ClassNotFoundException | IOException e1) {
                                 LOG.log(Level.SEVERE, "Cannot classify " + feedTitle, e1);                         
                         }
@@ -159,13 +160,13 @@ public class ArticleProvider {
                                 Collections.sort(articles, new Comparator<Article>() {
                                         @Override
                                         public int compare(Article o1, Article o2) {
-                                                if (o1.publicationDate == o2.publicationDate)
+                                                if (o1.getPublicationDate() == o2.getPublicationDate())
                                                         return 0;
-                                                if (o1.publicationDate == null)
+                                                if (o1.getPublicationDate() == null)
                                                         return 1;
-                                                if (o2.publicationDate == null)
+                                                if (o2.getPublicationDate() == null)
                                                         return -1;
-                                                return o2.publicationDate.compareTo(o1.publicationDate);
+                                                return o2.getPublicationDate().compareTo(o1.getPublicationDate());
                                         }
                                 });
                         }