I want to compute similarity between strings with dkpro similarity (https://dkpro.github.io/dkpro-similarity/), it works, like so:
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;
}
i use the class like this:
double intermscore = comparator.compareWords(word1, word2);
I use LexicalSemanticResource as resource for comparing, it can be wordnet, wikipedia, germanet etc. Now i noticed that all of the resources i need are in 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).
My question is: can i replace the resource with a resource from uby so I don't have to include a new resource again each time i need one? so instead of ResourceFactory.getInstance().get("wordnet"), i want to use the uby resource, so sth like new Uby().getLexicalResource("wordnet") - however lexicalresource from uby is not the same as LexicalSemanticResource i use now for semantic comparison. So: Instead of using e.g. LexicalSemanticResource wordnet, i want to use wordnet from uby for the comparators. Is there a way to do this?
There currently is no way to do this. Uby resources and LSR resources are not compatible.
There were plans to switch, but the issue has been open for a while: https://github.com/dkpro/dkpro-similarity/issues/39