Search in sources :

Example 1 with FeaturePathException

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);
    }
}
Also used : TextClassificationException(org.dkpro.tc.api.exception.TextClassificationException) FeaturePathException(de.tudarmstadt.ukp.dkpro.core.api.featurepath.FeaturePathException) SimilarityException(dkpro.similarity.algorithms.api.SimilarityException) Feature(org.dkpro.tc.api.features.Feature)

Aggregations

FeaturePathException (de.tudarmstadt.ukp.dkpro.core.api.featurepath.FeaturePathException)1 SimilarityException (dkpro.similarity.algorithms.api.SimilarityException)1 TextClassificationException (org.dkpro.tc.api.exception.TextClassificationException)1 Feature (org.dkpro.tc.api.features.Feature)1