// Path: freya/freya-annotate/src/main/java/org/freya/model/learning/Vote.java
// public class Vote {
// 	// this is usually URI or DatatyepPropertyValueIdentifier
// 	Object identifier;
// 	
// 	volatile long id;
// 	volatile double score;
// 	volatile String function;
// 	public Object getIdentifier() {
// 		return identifier;
// 	}
// 	public void setIdentifier(Object identifier) {
// 		this.identifier = identifier;
// 	}
// 	public long getId() {
// 		return id;
// 	}
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 	public double getScore() {
// 		return score;
// 	}
// 	public void setScore(double score) {
// 		this.score = score;
// 	}
// 	public String getFunction() {
// 		return function;
// 	}
// 	public void setFunction(String function) {
// 		this.function = function;
// 	}
// }


import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.freya.model.learning.Vote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

package org.freya.learning;



// import org.apache.commons.logging.Log;
// import org.apache.commons.logging.LogFactory;
//import org.codehaus.jackson.JsonGenerationException;
//import org.codehaus.jackson.JsonParseException;
//import org.codehaus.jackson.map.JsonMappingException;
//import org.codehaus.jackson.map.ObjectMapper;
//import org.codehaus.jackson.type.TypeReference;


/**
 * this class is initialising the learning model from file; on start up it feeds it into the memory and then it saves it
 * at certain periods of time
 * 
 * @author danica
 * 
 */
@Component
public class LearningModel {
    private static final Logger logger = LoggerFactory.getLogger(LearningModel.class);


    Map<String, List<Vote>> votesMap = new ConcurrentHashMap<String, List<Vote>>();

    public Map<String, List<Vote>> getVotesMap() {
        return votesMap;
    }

    public void setVotesMap(Map<String, List<Vote>> votesMap) {
        this.votesMap = votesMap;
    }

    boolean learningEnabled = true;

    public boolean isLearningEnabled() {
        return learningEnabled;
    }

    public void setLearningEnabled(boolean learningEnabled) {
        this.learningEnabled = learningEnabled;
    }

    // String learningModelJsonFilePath;
    ObjectMapper mapper = new ObjectMapper();

    @Value("${org.freya.learning.model}") Resource learningModelFile;

    /**
     * this method is called on startup to load learning model from file if loadModelOnInitialization flat is set to
     * true
     */
    @PostConstruct
    public void loadLearningModelFromFile() {

        if (learningEnabled) {
            // read the path to the file
            try {
                if (learningModelFile.exists()) {
                    // and here's something different: instead of TwitterEntry,
                    // let's claim content is a Map!
                    TypeReference<ConcurrentHashMap<String, List<Vote>>> typeRef =
                                    new TypeReference<ConcurrentHashMap<String, List<Vote>>>() {};


// Path: freya/freya-annotate/src/main/java/org/freya/model/learning/Vote.java
// public class Vote {
// 	// this is usually URI or DatatyepPropertyValueIdentifier
// 	Object identifier;
// 	
// 	volatile long id;
// 	volatile double score;
// 	volatile String function;
// 	public Object getIdentifier() {
// 		return identifier;
// 	}
// 	public void setIdentifier(Object identifier) {
// 		this.identifier = identifier;
// 	}
// 	public long getId() {
// 		return id;
// 	}
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 	public double getScore() {
// 		return score;
// 	}
// 	public void setScore(double score) {
// 		this.score = score;
// 	}
// 	public String getFunction() {
// 		return function;
// 	}
// 	public void setFunction(String function) {
// 		this.function = function;
// 	}
// }


// Path: freya/freya-annotate/src/main/java/org/freya/learning/LearningModel.java
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.PostConstruct;
import org.apache.commons.io.FileUtils;
import org.freya.model.learning.Vote;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

package org.freya.learning;



// import org.apache.commons.logging.Log;
// import org.apache.commons.logging.LogFactory;
//import org.codehaus.jackson.JsonGenerationException;
//import org.codehaus.jackson.JsonParseException;
//import org.codehaus.jackson.map.JsonMappingException;
//import org.codehaus.jackson.map.ObjectMapper;
//import org.codehaus.jackson.type.TypeReference;


/**
 * this class is initialising the learning model from file; on start up it feeds it into the memory and then it saves it
 * at certain periods of time
 * 
 * @author danica
 * 
 */
@Component
public class LearningModel {
    private static final Logger logger = LoggerFactory.getLogger(LearningModel.class);


    Map<String, List<Vote>> votesMap = new ConcurrentHashMap<String, List<Vote>>();

    public Map<String, List<Vote>> getVotesMap() {
        return votesMap;
    }

    public void setVotesMap(Map<String, List<Vote>> votesMap) {
        this.votesMap = votesMap;
    }

    boolean learningEnabled = true;

    public boolean isLearningEnabled() {
        return learningEnabled;
    }

    public void setLearningEnabled(boolean learningEnabled) {
        this.learningEnabled = learningEnabled;
    }

    // String learningModelJsonFilePath;
    ObjectMapper mapper = new ObjectMapper();

    @Value("${org.freya.learning.model}") Resource learningModelFile;

    /**
     * this method is called on startup to load learning model from file if loadModelOnInitialization flat is set to
     * true
     */
    @PostConstruct
    public void loadLearningModelFromFile() {

        if (learningEnabled) {
            // read the path to the file
            try {
                if (learningModelFile.exists()) {
                    // and here's something different: instead of TwitterEntry,
                    // let's claim content is a Map!
                    TypeReference<ConcurrentHashMap<String, List<Vote>>> typeRef =
                                    new TypeReference<ConcurrentHashMap<String, List<Vote>>>() {};


                    Map<String, List<Vote>> votesMap = mapper.readValue(
