我想计算具有dkpro相似度(https://dkpro.github.io/dkpro-similarity/)的字符串之间的相似性,它的工作原理如下:
import org.dkpro.similarity.algorithms.api.SimilarityException;
import org.dkpro.similarity.algorithms.api.TextSimilarityMeasure;
import org.dkpro.similarity.algorithms.lsr.LexSemResourceComparator;
import org.dkpro.similarity.algorithms.lsr.gloss.GlossOverlapComparator;
import org.dkpro.similarity.algorithms.lsr.path.JiangConrathComparator;
import org.dkpro.similarity.algorithms.lsr.path.LeacockChodorowComparator;
import org.dkpro.similarity.algorithms.lsr.path.LinComparator;
import org.dkpro.similarity.algorithms.lsr.path.ResnikComparator;
import org.dkpro.similarity.algorithms.lsr.path.WuPalmerComparator;
import de.tudarmstadt.ukp.dkpro.lexsemresource.LexicalSemanticResource;
import de.tudarmstadt.ukp.dkpro.lexsemresource.core.ResourceFactory;
import de.tudarmstadt.ukp.dkpro.lexsemresource.exception.LexicalSemanticResourceException;
import de.tudarmstadt.ukp.dkpro.lexsemresource.exception.ResourceLoaderException;
import learninggoals.analysis.controller.settingtypes.SimilarityAlgorithm;
public class SemResourceComparator implements WordsComparator{
private LexicalSemanticResource resource;
private LexSemResourceComparator comparator;
//en lang
public SemResourceComparator(String resourcetype, SimilarityAlgorithm algorithm, String lang) {
try {
resource = ResourceFactory.getInstance().get(resourcetype, lang);
} catch (ResourceLoaderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
switch(algorithm){
/*case ESA://this is vector
comparator = new GlossOverlapComparator(resource, false);
break;*/
case GLOSSOVERLAP:
comparator = new GlossOverlapComparator(resource, false);
break;
case JIANG_CONRATH:
comparator = new JiangConrathComparator(resource, resource.getRoot());
break;
case LEACOCK_CHODOROW:
comparator = new LeacockChodorowComparator(resource);
break;
case LIN:
comparator = new LinComparator(resource, resource.getRoot());
break;
case RESNIK:
comparator = new ResnikComparator(resource, resource.getRoot());
break;
case WUPALMER:
comparator = new WuPalmerComparator(resource, resource.getRoot());
break;
default:
break;
}
} catch (LexicalSemanticResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public double compareWords(String w1, String w2) {
try {
return comparator.getSimilarity(resource.getEntity(w1), resource.getEntity(w2));
} catch (SimilarityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (LexicalSemanticResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
我使用这样的类:
double intermscore = comparator.compareWords(word1, word2);
我使用LexicalSemanticResource作为比较资源,它可以是wordnet,维基百科,germanet等。现在我注意到我需要的所有资源都是uby(https://www.ukp.tu-darmstadt.de/data/lexical-resources/uby/,https://github.com/dkpro/dkpro-uby/blob/master/de.tudarmstadt.ukp.uby.lmf.api-asl/src/main/java/de/tudarmstadt/ukp/lmf/api/Uby.java)。
我的问题是:我可以用uby中的资源替换资源,所以每次需要时我都不需要再次包含新资源吗?因此,而不是ResourceFactory.getInstance()。get(“wordnet”),我想使用uby资源,所以像新的Uby()。getLexicalResource(“wordnet”) - 但是来自uby的lexicalresource与LexicalSemanticResource i不同现在用于语义比较。所以:而不是使用例如LexicalSemanticResource wordnet,我想使用uby的wordnet作为比较器。有没有办法做到这一点?
答案 0 :(得分:0)
目前无法做到这一点。 Uby资源和LSR资源不兼容。
有计划转换,但问题已经开放了一段时间: https://github.com/dkpro/dkpro-similarity/issues/39