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 { 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; }
/** * 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); }
/** * 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); }
/** * 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 Bag(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); }
/** * Constructs a {@link Context} which converts the features extracted by the argument contexts * into a bag of count features. * * @param contexts * The contexts which should be combined into a bag. */ public Count(Context... contexts) { this.contexts = contexts; String[] names = new String[contexts.length + 1]; names[0] = "Count"; 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); }