cleaning up code, added multi sentence support, build out caches, did other stuff i forgot
This commit is contained in:
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package FunctionLayer.StanfordParser;
|
||||
|
||||
import edu.cmu.lti.lexical_db.ILexicalDatabase;
|
||||
import edu.cmu.lti.lexical_db.NictWordNet;
|
||||
import edu.cmu.lti.ws4j.RelatednessCalculator;
|
||||
import edu.cmu.lti.ws4j.impl.HirstStOnge;
|
||||
import edu.cmu.lti.ws4j.impl.JiangConrath;
|
||||
import edu.cmu.lti.ws4j.impl.LeacockChodorow;
|
||||
import edu.cmu.lti.ws4j.impl.Lesk;
|
||||
import edu.cmu.lti.ws4j.impl.Lin;
|
||||
import edu.cmu.lti.ws4j.impl.Path;
|
||||
import edu.cmu.lti.ws4j.impl.Resnik;
|
||||
import edu.cmu.lti.ws4j.impl.WuPalmer;
|
||||
import edu.cmu.lti.ws4j.util.WS4JConfiguration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class SimilarityMatrix {
|
||||
|
||||
private String PrimaryString;
|
||||
private String SecondaryString;
|
||||
private double distance;
|
||||
|
||||
public double getDistance() {
|
||||
return distance;
|
||||
}
|
||||
|
||||
public void setDistance(double distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
}
|
||||
|
||||
public SimilarityMatrix(String str1, String str2, double result) {
|
||||
this.PrimaryString = str1;
|
||||
this.SecondaryString = str2;
|
||||
this.distance = result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @return ws4j distance caluclation add infinitum absurdum
|
||||
*/
|
||||
public double getDistanceCalculations() {
|
||||
ILexicalDatabase db = new NictWordNet();
|
||||
WS4JConfiguration.getInstance().setMFS(true);
|
||||
RelatednessCalculator rc1 = new WuPalmer(db);
|
||||
RelatednessCalculator rc2 = new Resnik(db);
|
||||
RelatednessCalculator rc3 = new JiangConrath(db);
|
||||
RelatednessCalculator rc4 = new Lin(db);
|
||||
RelatednessCalculator rc5 = new LeacockChodorow(db);
|
||||
RelatednessCalculator rc6 = new Path(db);
|
||||
RelatednessCalculator rc7 = new Lesk(db);
|
||||
RelatednessCalculator rc8 = new HirstStOnge(db);
|
||||
double maxScore = -1D;
|
||||
List<RelatednessCalculator> RCList = new ArrayList();
|
||||
RCList.add(rc1);
|
||||
RCList.add(rc2);
|
||||
RCList.add(rc3);
|
||||
RCList.add(rc4);
|
||||
RCList.add(rc5);
|
||||
RCList.add(rc6);
|
||||
RCList.add(rc7);
|
||||
RCList.add(rc8);
|
||||
for (RelatednessCalculator rc : RCList) {
|
||||
double s = rc.calcRelatednessOfWords(PrimaryString, SecondaryString);
|
||||
s /= 1000;
|
||||
if (s > 0.000000) {
|
||||
System.out.println("s: " + s + "\n" + " PrimaryString: " + PrimaryString + "\n" + " SecondaryString: " + SecondaryString + "\n"
|
||||
+ " rc: " + rc.toString() + "\n");
|
||||
}
|
||||
String str = String.format("%.12f", s);
|
||||
if (str.contains(",")) {
|
||||
str = str.substring(0, str.indexOf(","));
|
||||
}
|
||||
int strend = str.length() > 6 ? 6 : str.length();
|
||||
str = str.substring(0, strend);
|
||||
double score = Double.valueOf(str);
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
}
|
||||
}
|
||||
return maxScore == -1D ? 0.00 : maxScore;
|
||||
}
|
||||
|
||||
public String getPrimaryString() {
|
||||
return PrimaryString;
|
||||
}
|
||||
|
||||
public void setPrimaryString(String PrimaryString) {
|
||||
this.PrimaryString = PrimaryString;
|
||||
}
|
||||
|
||||
public String getSecondaryString() {
|
||||
return SecondaryString;
|
||||
}
|
||||
|
||||
public void setSecondaryString(String SecondaryString) {
|
||||
this.SecondaryString = SecondaryString;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user