package gr.iti.mklab.sfc.processors;

import java.util.Map;

import gr.iti.mklab.classifiers.ClassificationResult;
import gr.iti.mklab.classifiers.EnvironmentalClassification;
import gr.iti.mklab.framework.common.domain.Item;
import gr.iti.mklab.framework.common.domain.config.Configuration;

public class EnvironmentalClassifier extends Processor {

	EnvironmentalClassification ec;
	
	public EnvironmentalClassifier(Configuration configuration) {
		super(configuration);
		
		ec = new EnvironmentalClassification();
	}

	@Override
	public void process(Item item) {
		String lang = item.getLanguage();
		
		String text = "";
		String title = item.getTitle();
		String description = item.getDescription();
		
		if(title != null) {
			text += " " + title;
		}
		if (description != null) {
			text +=  " " + title;
		}

		try {
			ClassificationResult result = ec.classify(text, lang, false);
		
			Map<String, Double> probMap = result.getFirstClassifierProbabilityMap();		
			
			if(probMap.get("Relevant") > 0.5) {
				item.addTopic("environment", probMap.get("Relevant"));
				Map<String, Double> subTopics = result.getSecondClassifierProbabilitityMap();
				for(String subTopic : subTopics.keySet()) {
					item.addTopic(subTopic, subTopics.get(subTopic));
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println(item.toString());
	}

	public static void main(String...args) {
		System.out.println("TEST");
		
		EnvironmentalClassifier clssf = new EnvironmentalClassifier(null);
		
		Item item = new Item();
		item.setLanguage("en");
		item.setTitle("it was first held in 1974 to raise awareness about marine pollution human overpopulation& global warming #WorldEnvironmentDay");
		
		clssf.process(item);
		
	}
}

@@ -345,16 +345,24 @@
 sor %7B%0A%0A%09
+private 
 Environm
@@ -385,16 +385,43 @@
 ion ec;%0A
+%09private double threshold;%0A
 %09%0A%09publi
@@ -504,16 +504,101 @@
 on);%0A%09%09%0A
+%09%09threshold = Double.parseDouble(configuration.getParameter(%22threshold%22, %220.2%22));%0A%09%09%0A
 %09%09ec = n
@@ -1313,24 +1313,72 @@
 keySet()) %7B%0A
+%09%09%09%09%09if(subTopics.get(subTopic) %3E threshold) %7B%0A%09
 %09%09%09%09%09item.ad
@@ -1416,24 +1416,31 @@
 subTopic));%0A
+%09%09%09%09%09%7D%0A
 %09%09%09%09%7D%0A%09%09%09%7D%0A%09

Add threshold to environmental classifier