@Test public void numberOfHashTagsFeatureExtractorTest() throws Exception { AnalysisEngineDescription desc = createEngineDescription(NoOpAnnotator.class); AnalysisEngine engine = createEngine(desc); JCas jcas = engine.newJCas(); jcas.setDocumentLanguage("en"); jcas.setDocumentText("This is a very #emotional tweet ;-) #icouldcry #ILoveHashTags"); engine.process(jcas); TextClassificationTarget aTarget = new TextClassificationTarget(jcas, 0, jcas.getDocumentText().length()); aTarget.addToIndexes(); NumberOfHashTags extractor = new NumberOfHashTags(); List<Feature> features = new ArrayList<Feature>(extractor.extract(jcas, aTarget)); Assert.assertEquals(1, features.size()); for (Feature feature : features) { assertFeature(NumberOfHashTags.class.getSimpleName(), 3, feature); } }
@Override public Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget) throws TextClassificationException { Matcher hashTagMatcher = HASHTAG_PATTERN .matcher(jCas.getDocumentText().substring(aTarget.getBegin(), aTarget.getEnd())); int numberOfHashTags = 0; while (hashTagMatcher.find()) { numberOfHashTags++; } return new Feature(NumberOfHashTags.class.getSimpleName(), numberOfHashTags, FeatureType.NUMERIC).asSet(); }
NumberOfHashTags extends FeatureExtractorResource_ImplBase implements FeatureExtractor { @Override public Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget) throws TextClassificationException { Matcher hashTagMatcher = HASHTAG_PATTERN .matcher(jCas.getDocumentText().substring(aTarget.getBegin(), aTarget.getEnd())); int numberOfHashTags = 0; while (hashTagMatcher.find()) { numberOfHashTags++; } return new Feature(NumberOfHashTags.class.getSimpleName(), numberOfHashTags, FeatureType.NUMERIC).asSet(); } }
NumberOfHashTags extends FeatureExtractorResource_ImplBase implements FeatureExtractor { @Override public Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget) throws TextClassificationException { Matcher hashTagMatcher = HASHTAG_PATTERN .matcher(jCas.getDocumentText().substring(aTarget.getBegin(), aTarget.getEnd())); int numberOfHashTags = 0; while (hashTagMatcher.find()) { numberOfHashTags++; } return new Feature(NumberOfHashTags.class.getSimpleName(), numberOfHashTags, FeatureType.NUMERIC).asSet(); }  }
NumberOfHashTags extends FeatureExtractorResource_ImplBase implements FeatureExtractor { @Override public Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget) throws TextClassificationException { Matcher hashTagMatcher = HASHTAG_PATTERN .matcher(jCas.getDocumentText().substring(aTarget.getBegin(), aTarget.getEnd())); int numberOfHashTags = 0; while (hashTagMatcher.find()) { numberOfHashTags++; } return new Feature(NumberOfHashTags.class.getSimpleName(), numberOfHashTags, FeatureType.NUMERIC).asSet(); }  @Override Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget); }
NumberOfHashTags extends FeatureExtractorResource_ImplBase implements FeatureExtractor { @Override public Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget) throws TextClassificationException { Matcher hashTagMatcher = HASHTAG_PATTERN .matcher(jCas.getDocumentText().substring(aTarget.getBegin(), aTarget.getEnd())); int numberOfHashTags = 0; while (hashTagMatcher.find()) { numberOfHashTags++; } return new Feature(NumberOfHashTags.class.getSimpleName(), numberOfHashTags, FeatureType.NUMERIC).asSet(); }  @Override Set<Feature> extract(JCas jCas, TextClassificationTarget aTarget);  }