JAPE Features
Contents
- 1. To check on the RHS that an annotation has a certain feature value (in this case, a Token that's an adjective)
- 2. Clone a feature map
- 3. Copy all the features from one annotation to another
- 4. Print the count for each word of an annotation type with a certain feature
- 5. To do mathematical operations on the value of a feature that's a string (e.g. value of a Lookup annotation from the gazetteer)
1. To check on the RHS that an annotation has a certain feature value (in this case, a Token that's an adjective)
if (anAnn.getType().equals("Token") &&
anAnn.getFeatures().containsKey("category") &&
anAnn.getFeatures().get("category").equals("JJ") )
2. Clone a feature map
FeatureMap fm = (FeatureMap)((SimpleFeatureMapImpl)ann.getFeatures()).clone();
3. Copy all the features from one annotation to another
FeatureMap newAnnFeatures = Factory.newFeatureMap(); newAnnFeatures.putAll(oldAnn.getFeatures());
4. Print the count for each word of an annotation type with a certain feature
Here the annotation type is "Token" and the feature is "category=JJ" for adjective.
Phase: Count
Input: Token
Options: control = once
Rule: Count
{Token}
-->
{
Map<String, Integer> countByStringMap = new TreeMap<String, Integer>();
FeatureMap featureMap = Factory.newFeatureMap();
featureMap.put("category", "JJ");
for (Annotation annotation : inputAS.get("Token", featureMap)) {
String string = (String) annotation.getFeatures().get("string");
Integer count = (Integer) countByStringMap.get(string);
if (count == null) {
countByStringMap.put(string, 1);
} else {
countByStringMap.put(string, count + 1);
}
}
for (Map.Entry entry : countByStringMap.entrySet()) {
System.out.println( entry.getKey() + "," + entry.getValue());
}
}
5. To do mathematical operations on the value of a feature that's a string (e.g. value of a Lookup annotation from the gazetteer)
({Lookup.score >=0.5}):tag
-->
...
float score = Float.parseFloat(sentiAnn.getFeatures().get("score").toString());
float newScore = score * 2;
features.put("score", newScore);
...




