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.º 3
0
 public static RelatednessCalculator createCalculator() {
   ILexicalDatabase db = new NictWordNet();
   WS4JConfiguration.getInstance().setMFS(true);
   System.out.println("Creating an instance of WuPalmer to calculate similarity between words...");
   return new WuPalmer(db);
 }