@Override public List<Feature> extract(JCas view, FOCUS_T focusAnnotation) throws CleartkExtractorException { List<Feature> extracted = this.subExtractor.extract(view, focusAnnotation); List<Feature> result = new ArrayList<Feature>(); if (this.isTrained) { // We have trained / loaded a centroid tf*idf model, so now compute // a cosine similarity for the extracted values Map<String, Double> extractedFeatureMap = this.featuresToFeatureMap(extracted); result.add(new Feature(name, this.simFunction.distance(extractedFeatureMap, centroidMap))); } else { // We haven't trained this extractor yet, so just mark the existing features // for future modification, by creating one mega container feature result.add(new TransformableFeature(this.name, extracted)); } return result; }
@Override public Instance<OUTCOME_T> transform(Instance<OUTCOME_T> instance) { List<Feature> features = new ArrayList<Feature>(); List<Feature> featuresToTransform = new ArrayList<Feature>(); for (Feature feature : instance.getFeatures()) { if (this.isTransformable(feature)) { // Store off features for later similarity computation featuresToTransform.addAll(((TransformableFeature) feature).getFeatures()); } else { // pass through non-transformable features features.add(feature); } } // Create centroid similarity feature Map<String, Double> featureMap = this.featuresToFeatureMap(featuresToTransform); features.add(new Feature(this.name, new Double(this.simFunction.distance( featureMap, centroidMap)))); return new Instance<OUTCOME_T>(instance.getOutcome(), features); }