use of de.tudarmstadt.ukp.dkpro.core.api.featurepath.FeaturePathException in project dkpro-tc by dkpro.
the class SimilarityPairFeatureExtractor method extract.
@Override
public Set<Feature> extract(JCas view1, JCas view2) throws TextClassificationException {
try {
double similarity;
switch(textSimilarityResource.getMode()) {
case text:
similarity = textSimilarityResource.getSimilarity(view1.getDocumentText(), view2.getDocumentText());
break;
case jcas:
similarity = ((JCasTextSimilarityMeasure) textSimilarityResource).getSimilarity(view1, view2);
break;
default:
List<String> f1 = getItems(view1);
List<String> f2 = getItems(view2);
// Remove "_" tokens
for (int i = f1.size() - 1; i >= 0; i--) {
if (f1.get(i) == null || f1.get(i).equals("_")) {
f1.remove(i);
}
}
for (int i = f2.size() - 1; i >= 0; i--) {
if (f2.get(i) == null || f2.get(i).equals("_")) {
f2.remove(i);
}
}
similarity = textSimilarityResource.getSimilarity(f1, f2);
}
return new Feature("Similarity" + textSimilarityResource.getName(), similarity, FeatureType.NUMERIC).asSet();
} catch (FeaturePathException e) {
throw new TextClassificationException(e);
} catch (SimilarityException e) {
throw new TextClassificationException(e);
}
}
Aggregations