0

我想计算具有 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、wikipedia、germanet 等。现在我注意到我需要的所有资源都在 uby ( https://www.ukp.tu-darmstadt.de/data/lexical-资源/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 的资源替换该资源,这样我就不必每次需要一个新资源时都重新包含一个新资源?所以我想使用 uby 资源而不是 ResourceFactory.getInstance().get("wordnet"),所以像 new Uby().getLexicalResource("wordnet") - 但是来自 uby 的 lexicalresource 与 LexicalSemanticResource 我不一样现在用于语义比较。所以:我不想使用例如 LexicalSemanticResource wordnet,而是使用 uby 的 wordnet 作为比较器。有没有办法做到这一点?

4

1 回答 1

0

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

有计划切换,但问题已经开放了一段时间: https ://github.com/dkpro/dkpro-similarity/issues/39

于 2017-07-06T18:45:01.477 回答