Ejemplo n.º 1
0
 @Test
 public void testOnUnknownSynsets() {
   assertEquals(
       LeacockChodorow.min, rc.calcRelatednessOfSynset(null, n1Synsets.get(0)).getScore(), 0.0001);
   assertEquals(LeacockChodorow.min, rc.calcRelatednessOfWords(null, n1), 0.0001);
   assertEquals(LeacockChodorow.min, rc.calcRelatednessOfWords("", n1), 0.0001);
 }
Ejemplo n.º 2
0
 /**
  * Test method for {@link
  * edu.cmu.lti.similarity.RelatednessCalculator#calcRelatednessOfWords(java.lang.String,
  * java.lang.String)}.
  */
 @Test
 public void testHappyPathOnWordsWithPOS() {
   assertEquals(2.5902, rc.calcRelatednessOfWords(nv1 + "#n", nv2 + "#n"), 0.0001D);
   assertEquals(0.0000, rc.calcRelatednessOfWords(nv1 + "#n", nv2 + "#v"), 0.0001D);
   assertEquals(0.0000, rc.calcRelatednessOfWords(nv1 + "#v", nv2 + "#n"), 0.0001D);
   assertEquals(2.2335, rc.calcRelatednessOfWords(nv1 + "#v", nv2 + "#v"), 0.0001D);
   assertEquals(0.0000, rc.calcRelatednessOfWords(nv1 + "#other", nv2 + "#other"), 0.0001D);
 }
Ejemplo n.º 3
0
  /**
   * Test method for {@link
   * edu.cmu.lti.similarity.impl.LeacockChodorow#calcRelatedness(java.lang.String,
   * java.lang.String)}.
   */
  @Test
  public void testHappyPathOnSynsets() {
    // both japanese and english!, n and v

    // English pair
    assertEquals(
        2.9957, rc.calcRelatednessOfSynset(n1Synsets.get(1), n2Synsets.get(0)).getScore(), 0.0001);
    assertEquals(
        1.6094, rc.calcRelatednessOfSynset(n1Synsets.get(0), n2Synsets.get(0)).getScore(), 0.0001);
    assertEquals(
        2.6391, rc.calcRelatednessOfSynset(v1Synsets.get(0), v2Synsets.get(0)).getScore(), 0.0001);
    assertEquals(
        1.9459, rc.calcRelatednessOfSynset(v1Synsets.get(1), v2Synsets.get(0)).getScore(), 0.0001);
  }
 public static double run(String word1, String word2) {
   WS4JConfiguration.getInstance().setMFS(true);
   String word1_v = word1.substring(0, word1.indexOf('_'));
   String word1_n = word1.substring(word1.indexOf('_') + 1);
   String word2_v = word2.substring(0, word2.indexOf('_'));
   String word2_n = word2.substring(word2.indexOf('_') + 1);
   double s1 = rc.calcRelatednessOfWords(word1_v, word2_v);
   double s2 = rc.calcRelatednessOfWords(word1_n, word2_n);
   return s1 + s2;
 }
 public static double similarity(String w1, String w2) {
   WS4JConfiguration.getInstance().setMFS(true);
   if (w1 != null) w1 = w1.toLowerCase().replaceAll("-", "").replaceAll(" ", "");
   if (w2 != null) w2 = w2.toLowerCase().replaceAll("-", "").replaceAll(" ", "");
   // double res = 0.0d;
   // double res1 = simCalc.calcRelatednessOfWords(w1, w2);
   // res = res1;
   // double res2 = simCalc.calcRelatednessOfWords(w1.replace('-', ' '),
   // w2.replace('-', ' '));
   // if (res2 > res)
   // res = res2;
   // double res3 = simCalc.calcRelatednessOfWords(w1.replaceAll("-", ""),
   // w2.replaceAll("-", ""));
   // if (res3 > res)
   // res = res3;
   return simCalc.calcRelatednessOfWords(w1, w2);
 }
Ejemplo n.º 6
0
 /**
  * Test method for {@link
  * edu.cmu.lti.similarity.RelatednessCalculator#calcRelatednessOfWords(java.lang.String,
  * java.lang.String)}.
  */
 @Test
 public void testHappyPathOnWords() {
   assertEquals(2.9957, rc.calcRelatednessOfWords(n1, n2), 0.0001D);
   assertEquals(2.6391, rc.calcRelatednessOfWords(v1, v2), 0.0001D);
 }
Ejemplo n.º 7
0
  public static void main(String[] args) throws ClassNotFoundException, IOException {

    int nbPCA = 250;
    // String sourcePath = "/Vrac/3000693/RI_Image/bows_" + nbPCA + ".ser";
    String sourcePath = "/Users/remicadene/Dropbox/_Docs/UPMC/RI/bows_" + nbPCA + ".ser";
    int dimpsi = 0;
    Set<String> classes;

    // Modèle MultiClass
    // --------------------------------------------------------------------------------

    // Hyperparamètres
    double eps = 1e-2;
    double lambda = 1e-6;
    int maxIter = 100;

    // Définition du modèle
    DataSet<double[], String> dataSet = VisualIndexes.load(sourcePath);
    classes = dataSet.outputs();

    double min = Double.MAX_VALUE;
    double max = -Double.MAX_VALUE;

    int n = classes.size();
    double[][] distances = new double[n][n];
    double[][] new_distances = new double[n][n];
    ILexicalDatabase db = new NictWordNet();
    RelatednessCalculator calculator = new WuPalmer(db);

    HashMap<String, Integer> hm_classes = new HashMap<String, Integer>();
    int id = 0;
    for (String classe : classes) {
      hm_classes.put(classe, id);
      id++;
    }

    for (String word1 : classes) {
      int i = hm_classes.get(word1);
      for (String word2 : classes) {
        int j = hm_classes.get(word2);
        // this.distances[i][j] = calculator.calcRelatednessOfWords(word1, word2);
        if (i == j) {
          distances[i][j] = 0;
        } else {
          distances[i][j] = 1 - calculator.calcRelatednessOfWords(word1, word2);

          if (distances[i][j] < min) {
            min = distances[i][j];
          }
          if (distances[i][j] > max) {
            max = distances[i][j];
          }
        }
      }
    }

    // [a; b] -> [0.1 ; 2]
    // (1.9 * (x - a) / (b - a)) + .1
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i != j) {
          new_distances[i][j] = (distances[i][j] - min) * (2 - 0.1) / (max - min) + 0.1;
        }
      }
    }

    System.out.println("--------------");

    for (int i = 0; i < classes.size(); i++) {
      for (int j = i + 1; j < classes.size(); j++) {
        System.out.println("[" + i + "," + j + "]");
        System.out.println("avant: " + distances[i][j]);
        System.out.println("apres: " + new_distances[i][j]);
      }
    }

    System.out.println(max);

    System.out.println(min);

    double a =
        0.1 + (2 - 0.1) * (0.6 - 0.0714285714285714) / (0.15384615384615385 - 0.0714285714285714);
  }