Java 将dkpro语义相似性与uby一起使用

Java 将dkpro语义相似性与uby一起使用,java,semantics,lexical-analysis,dkpro-core,semantic-comparison,Java,Semantics,Lexical Analysis,Dkpro Core,Semantic Comparison,我想用dkpro similarity()计算字符串之间的相似性,它是这样工作的: import org.dkpro.similarity.algorithms.api.SimilarityException; import org.dkpro.similarity.algorithms.api.TextSimilarityMeasure; import org.dkpro.similarity.algorithms.lsr.LexSemResourceComparator; import or

我想用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、wikipedia、germanet等。现在我注意到我需要的所有资源都在uby(,)中


我的问题是:我是否可以用uby的资源替换该资源,这样我就不必在每次需要时都重新包含新资源?因此,我不想使用ResourceFactory.getInstance().get(“wordnet”),而是想使用uby资源,比如新的uby().getLexicalResource(“wordnet”)——但是uby的lexicalresource与我现在用于语义比较的LexicalSemanticResource不同。所以:我想使用uby的wordnet作为比较器,而不是使用例如词典语义资源wordnet。有办法做到这一点吗?

目前没有办法做到这一点。Uby资源和LSR资源不兼容

有计划进行转换,但问题已经存在一段时间了: