package com.github.bot.curiosone.core.analysis;

import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Loading the dictionary from a file.
 *
 * @author Cosmo Pugliese && Francesco Natale.
 *
 */

public class DictionaryLoader {
  /**
   *The Uri containing the .properties file.
   */
  private static final String uri = "/dictionary/DataDict.properties";

  /**
   * The map which contains words and their sentiment's score.
   */
  private static Map<String, Double> dict;

  /**
   * Initializing of the properties.
   */
  private static Properties properties = new Properties();


  /**
   * Loading the .properties file in the dictionary.
   * @Return the loaded dictionary
   */
  public static Map<String, Double> loadDict() {
    Path path = null;
    try {
      URL resource = DictionaryLoader.class.getResource(uri);
      path = Paths.get(resource.toURI());
      properties.load(new FileInputStream(path.toString()));
    } catch (IOException|URISyntaxException e) {
      e.printStackTrace();
    }
    for (String key : properties.stringPropertyNames()) {
      dict.put(key, Double.parseDouble(properties.get(key).toString()));
    }
    return dict;
  }

}

@@ -286,24 +286,51 @@
 a.util.Map;%0A
+import java.util.Optional;%0A
 import java.
@@ -346,16 +346,16 @@
 erties;%0A
-
 %0A/**%0A * 
@@ -480,16 +480,62 @@
 oader %7B%0A
+%0A  private static DictionaryLoader instance;%0A%0A
   /**%0A  
@@ -883,16 +883,245 @@
 ies();%0A%0A
+  private DictionaryLoader() %7B%0A    dict = new HashMap%3C%3E();%0A    loadDict();%0A  %7D%0A%0A  public static DictionaryLoader getInstance() %7B%0A    if (instance == null) %7B%0A      instance = new DictionaryLoader();%0A    %7D%0A    return instance;%0A  %7D%0A
 %0A  /**%0A 
@@ -1216,29 +1216,30 @@
   */%0A  p
-ublic
+rivate
  static 
 Map%3CStri
@@ -1230,35 +1230,20 @@
  static 
-Map%3CString, Double%3E
+void
  loadDic
@@ -1670,21 +1670,107 @@
 %7D%0A  
-  return dict
+%7D%0A%0A  public Double getScore(String word) %7B%0A    return dict.containsKey(word) ? dict.get(word) : 0.0
 ;%0A  

make DictionaryLoader a singleton