Map<String, Feature> featureMap = new HashMap<String, Feature>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation,
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { List<Feature> feats = new ArrayList<>(); for (Context context : this.contexts) { double[] contextVec = new double[dims]; int numComponents = 0; for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { if(this.vectors.containsKey(feature.getValue())){ double[] featVec = this.vectors.get(feature.getValue().toString().toLowerCase()); addToVector(contextVec, featVec); numComponents++; } } if(numComponents > 0){ for(int i = 0; i < dims; i++){ feats.add(new Feature(Feature.createName(this.name, context.getName(), String.valueOf(i)), contextVec[i] / numComponents)); } } } return feats; }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { LinkedHashMap<String,Double> runningTotals = new LinkedHashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), runningTotals.get(feature.getName()) + val); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { LinkedHashMap<String,Double> runningTotals = new LinkedHashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), runningTotals.get(feature.getName()) + val); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { HashMap<String,Double> runningTotals = new HashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), Double.max(runningTotals.get(feature.getName()), val)); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { HashMap<String,Double> runningTotals = new HashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), Double.max(runningTotals.get(feature.getName()), val)); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
List<Feature> extractedFeatures = new ArrayList<Feature>(); for (Context context : this.contexts) { extractedFeatures.addAll(context.extract( jCas, focusAnnotation,
@Override public <SEARCH_T extends Annotation> List<Feature> extract( JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { String featureName = extractor instanceof NamedFeatureExtractor1 ? ((NamedFeatureExtractor1<SEARCH_T>) extractor).getFeatureName() : null; List<String> values = new ArrayList<String>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { values.add(String.valueOf(feature.getValue())); } } Feature feature = new Feature(featureName, Joiner.on('_').join(values)); List<Feature> features = new ArrayList<Feature>(); features.add(new ContextFeature(this.getName(), feature)); return features; } }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { HashMap<String,Double> runningTotals = new HashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), Double.min(runningTotals.get(feature.getName()), val)); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { HashMap<String,Double> runningTotals = new HashMap<>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { try{ double val = Double.parseDouble(feature.getValue().toString()); if(!runningTotals.containsKey(feature.getName())){ runningTotals.put(feature.getName(), 0.0); } runningTotals.put(feature.getName(), Double.min(runningTotals.get(feature.getName()), val)); }catch(Exception e){ // just ignore this feature? } } } List<Feature> features = new ArrayList<>(); for(String key : runningTotals.keySet()){ features.add(new Feature(this.name + "_" + key, runningTotals.get(key))); } return features; }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into ngram features where sub-sequences feature values have been concatenated together. * * For example, Ngrams(2, context) will extract all bigrams of features generated in the given * context. * * @param n * The length of the n-gram features * @param contexts * The contexts which should be combined into an ngram. */ public Ngrams(int n, Context... contexts) { this.n = n; this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = this.n + "grams"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }
@Override public <SEARCH_T extends Annotation> List<Feature> extract( JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { List<Feature> features = new ArrayList<Feature>(); for (Context context : this.contexts) { for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { ContextFeature contextFeature = (ContextFeature) feature; Feature f2 = new Feature(contextFeature.feature.getName(), feature.getValue()); features.add(new ContextFeature(this.getName(), f2)); } } return features; } }
public <SEARCH_T extends Annotation> List<Feature> extract(JCas jCas, Annotation focusAnnotation, Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor) throws CleartkExtractorException { List<Feature> feats = new ArrayList<>(); for (Context context : this.contexts) { double[] contextVec = new double[dims]; int numComponents = 0; for (Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor)) { if(this.vectors.containsKey(feature.getValue())){ double[] featVec = this.vectors.get(feature.getValue().toString().toLowerCase()); addToVector(contextVec, featVec); numComponents++; } } if(numComponents > 0){ for(int i = 0; i < dims; i++){ feats.add(new Feature(Feature.createName(this.name, context.getName(), String.valueOf(i)), contextVec[i] / numComponents)); } } } return feats; }
@Override public <SEARCH_T extends Annotation> List<Feature> extract( JCas jCas, Annotation focusAnnotation, CleartkExtractor.Bounds bounds, Class<SEARCH_T> annotationClass, FeatureExtractor1<SEARCH_T> extractor ) throws CleartkExtractorException { List<Feature> features = new ArrayList<>(); for ( CleartkExtractor.Context context : this.contexts ) { for ( Feature feature : context.extract( jCas, focusAnnotation, bounds, annotationClass, extractor ) ) { WindowedContextFeature contextFeature = (WindowedContextFeature)feature; Feature f2 = new Feature( contextFeature.feature.getName(), feature.getValue() ); features.add( new WindowedContextFeature( this.getName(), f2 ) ); } } return features; }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a single ngram feature where all feature values have been concatenated together. That * is, it takes everything provided by the contexts and makes a single feature value from it. * For example, the code "new Ngram(new Preceding(2), new Following(2)))" if run on token * annotations would return the feature "A_B_D_E" for the token "C" in the text "A B C D E". * That is, it creates a single ngram from the preceding context and following context. Please * see org.cleartk.ml.feature.extractor.CleartkExtractorTest.testNgram() to run this example. * * * @param contexts * The contexts which should be combined into an ngram. */ public Ngram(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Ngram"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a bag of features where all features have the same name. * * @param contexts * The contexts which should be combined into a bag. */ public MinContext(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Min"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a bag of features where all features have the same name. * * @param contexts * The contexts which should be combined into a bag. */ public SumContext(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Sum"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a bag of features where all features have the same name. * * @param contexts * The contexts which should be combined into a bag. */ public SumContext(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Sum"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }
/** * Constructs a {@link CleartkExtractor.Context} which converts the features extracted by the argument contexts * into a bag of features where all features have the same name. * * @param contexts The contexts which should be combined into a bag. */ public WindowedBag( CleartkExtractor.Context... contexts ) { this.contexts = contexts; String[] names = new String[ contexts.length + 1 ]; names[ 0 ] = "Bag"; for ( int i = 1; i < names.length; ++i ) { names[ i ] = contexts[ i - 1 ].getName(); } this.name = Feature.createName( names ); }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a bag of features where all features have the same name. * * @param contexts * The contexts which should be combined into a bag. */ public MaxContext(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Max"; for (int i = 1; i < names.length; ++i) { names[i] = contexts[i - 1].getName(); } this.name = Feature.createName(names); }