use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.
the class SampleEntityAnnotator method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
Feature entityFeature = type.getFeatureByBaseName(ENTITY_FEATURE);
Feature nameFeature = type.getFeatureByBaseName(NAME_FEATURE);
for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
if (NP.equals(tokenPOS) || NPS.equals(tokenPOS)) {
AnnotationFS entityAnnotation = jcas.getCas().createAnnotation(type, annotation.getBegin(), annotation.getEnd());
entityAnnotation.setStringValue(entityFeature, annotation.getCoveredText());
// "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
String name = "OTHER";
if (annotation.getCoveredText().equals("Apache"))
name = "ORGANIZATION";
entityAnnotation.setStringValue(nameFeature, name);
jcas.addFsToIndexes(entityAnnotation);
}
}
}
use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.
the class SamplePoSTagger method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
Feature posFeature = type.getFeatureByBaseName(FEATURE_NAME);
for (Annotation annotation : jcas.getAnnotationIndex(type)) {
String text = annotation.getCoveredText();
String pos = extractPoS(text);
annotation.setStringValue(posFeature, pos);
}
}
use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.
the class DummySentimentAnnotator method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
if ("jj".equals(tokenPOS)) {
if (Arrays.asList(positiveAdj).contains(annotation.getCoveredText())) {
DummySentimentAnnotation dummySentimentAnnotation = createSentimentAnnotation(jcas, annotation);
dummySentimentAnnotation.setMood("positive");
dummySentimentAnnotation.addToIndexes();
} else if (Arrays.asList(negativeAdj).contains(annotation.getCoveredText())) {
DummySentimentAnnotation dummySentimentAnnotation = createSentimentAnnotation(jcas, annotation);
dummySentimentAnnotation.setMood("negative");
dummySentimentAnnotation.addToIndexes();
}
}
}
}
use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.
the class UIMAToSolrMapper method map.
/**
* map features of a certain UIMA type to corresponding Solr fields based on the mapping
*
* @param typeName name of UIMA type to map
*/
void map(String typeName, Map<String, MapField> featureFieldsmapping) throws FieldMappingException {
try {
Type type = cas.getTypeSystem().getType(typeName);
for (FSIterator<FeatureStructure> iterator = cas.getFSIndexRepository().getAllIndexedFS(type); iterator.hasNext(); ) {
FeatureStructure fs = iterator.next();
for (String featureName : featureFieldsmapping.keySet()) {
MapField mapField = featureFieldsmapping.get(featureName);
String fieldNameFeature = mapField.getFieldNameFeature();
String fieldNameFeatureValue = fieldNameFeature == null ? null : fs.getFeatureValueAsString(type.getFeatureByBaseName(fieldNameFeature));
String fieldName = mapField.getFieldName(fieldNameFeatureValue);
if (log.isInfoEnabled()) {
log.info("mapping {}@{} to {}", new Object[] { typeName, featureName, fieldName });
}
String featureValue;
if (fs instanceof Annotation && "coveredText".equals(featureName)) {
featureValue = ((Annotation) fs).getCoveredText();
} else {
featureValue = fs.getFeatureValueAsString(type.getFeatureByBaseName(featureName));
}
if (log.isDebugEnabled()) {
log.debug("writing {} in {}", new Object[] { featureValue, fieldName });
}
document.addField(fieldName, featureValue);
}
}
} catch (Exception e) {
throw new FieldMappingException(e);
}
}
use of org.apache.uima.jcas.tcas.Annotation in project lucene-solr by apache.
the class DummyEntityAnnotator method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
if ("np".equals(tokenPOS) || "nps".equals(tokenPOS)) {
EntityAnnotation entityAnnotation = new EntityAnnotation(jcas);
entityAnnotation.setBegin(annotation.getBegin());
entityAnnotation.setEnd(annotation.getEnd());
String entityString = annotation.getCoveredText();
entityAnnotation.setEntity(entityString);
// "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
String name = "OTHER";
if (entityString.equals("Apache"))
name = "ORGANIZATION";
entityAnnotation.setName(name);
entityAnnotation.addToIndexes();
}
}
}
Aggregations