/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.hsbo.fbg.sm4c.collect;

import de.hsbo.fbg.sm4c.classify.AbstractClassifier;
import de.hsbo.fbg.sm4c.classify.geotag.ArcGISGeoTagger;
import de.hsbo.fbg.sm4c.classify.geotag.GeoTagger;
import de.hsbo.fbg.sm4c.classify.geotag.LocationRecognizer;
import de.hsbo.fbg.sm4c.common.model.Location;
import de.hsbo.fbg.sm4c.common.model.MessageDocument;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Sebastian Drost
 */
public class FacebookMessageHandler implements MessageHandler{

    private static final Logger LOGGER = LogManager.getLogger(FacebookMessageHandler.class);

    private MessageDocument document;
    private AbstractClassifier classifier;
    private LocationRecognizer recognizer;
    private ArcGISGeoTagger geoTagger;

    public FacebookMessageHandler(AbstractClassifier classifier) {
        this.classifier = classifier;
        this.recognizer = new LocationRecognizer();
        this.geoTagger = new ArcGISGeoTagger();
    }

    public void processMessages(List<MessageDocument> documents) {
        documents.forEach(document -> {
            //do classyfying
            if (document.getContent()==null || document.getContent().isEmpty()){
                return;
            }
            String label = classifier.classify(document);
            LOGGER.info("Document " + document.getId() + " was classified as " + label);
            document.setLabel(label);

            //find location entities in message content
            List<String> locationEntities = recognizer.recognizeLocations(document.getContent());
            //if no entities found and message document is from Facebook
            //get location from source
            if (locationEntities.isEmpty()) {
//                    if(document.getService().equals(Services.FACEBOOK.toString())){
//                        
//                    }
            } else {
//                    List<Location> locations = geoTagger.geocode(locationEntities);
                geoTagger.geocode(locationEntities.get(0));

            }

        });
    }

}

@@ -295,38 +295,35 @@
 4c.c
-lassify.geotag.ArcGISGeoTagger
+ommon.model.MessageDocument
 ;%0Aim
@@ -348,31 +348,27 @@
 m4c.
-classify.geotag.GeoTagg
+geotag.ArcGISGeoCod
 er;%0A
@@ -391,25 +391,16 @@
 bg.sm4c.
-classify.
 geotag.L
@@ -429,99 +429,21 @@
 ort 
-de.hsbo.fbg.sm4c.common.model.Location;%0Aimport de.hsbo.fbg.sm4c.common.model.MessageDocumen
+java.util.Lis
 t;%0Ai
@@ -450,36 +450,45 @@
 mport java.util.
-List
+logging.Level
 ;%0Aimport org.apa
@@ -657,18 +657,23 @@
 eHandler
+ 
 %7B%0A
+    
 %0A    pri
@@ -758,16 +758,20 @@
 class);%0A
+    
 %0A    pri
@@ -912,26 +912,28 @@
 SGeo
-Tagg
+Cod
 er geo
-Tagger;%0A
+Coder;%0A    
 %0A   
@@ -1102,20 +1102,19 @@
 this.geo
-Tagg
+Cod
 er = new
@@ -1123,20 +1123,19 @@
 rcGISGeo
-Tagg
+Cod
 er();%0A  
@@ -1134,24 +1134,28 @@
 er();%0A    %7D%0A
+    
 %0A    public 
@@ -1320,10 +1320,12 @@
 nt()
+ 
 ==
+ 
 null
@@ -1360,16 +1360,17 @@
 Empty())
+ 
 %7B%0A      
@@ -2057,16 +2057,58 @@
  else %7B%0A
+                try %7B%0A                    
 //      
@@ -2201,33 +2201,41 @@
         
-geoTagger.geocode
+    geoCoder.findLocation
 (locatio
@@ -2253,16 +2253,155 @@
 et(0));%0A
+                %7D catch (Exception ex) %7B%0A                    LOGGER.error(%22Error during geocoding%22, ex);%0A                %7D%0A                
 %0A       
@@ -2407,16 +2407,28 @@
       %7D%0A
+            
 %0A       
@@ -2438,11 +2438,15 @@
 ;%0A    %7D%0A
+    
 %0A%7D%0A

fix message handler