use of org.apache.stanbol.commons.caslight.Feature in project stanbol by apache.
the class UIMAToTriples method computeEnhancements.
public void computeEnhancements(ContentItem ci) throws EngineException {
FeatureStructureListHolder holder;
LiteralFactory literalFactory = LiteralFactory.getInstance();
try {
IRI uimaIRI = new IRI(uimaUri);
logger.info(new StringBuilder("Trying to load holder for ref:").append(uimaUri).toString());
holder = ci.getPart(uimaIRI, FeatureStructureListHolder.class);
for (String source : sourceNames) {
logger.info(new StringBuilder("Processing UIMA source:").append(source).toString());
List<FeatureStructure> sourceList = holder.getFeatureStructureList(source);
if (sourceList != null) {
logger.info(new StringBuilder("UIMA source:").append(source).append(" contains ").append(sourceList.size()).append(" annotations.").toString());
} else {
logger.info(new StringBuilder("Source list is null:").append(source).toString());
continue;
}
for (FeatureStructure fs : sourceList) {
String typeName = fs.getTypeName();
logger.debug(new StringBuilder("Checking ").append(typeName).toString());
if (tnfs.checkFeatureStructureAllowed(typeName, fs.getFeatures())) {
logger.debug(new StringBuilder("Adding ").append(typeName).toString());
IRI textAnnotation = EnhancementEngineHelper.createTextEnhancement(ci, this);
Graph metadata = ci.getMetadata();
String uriRefStr = uimaUri + ":" + typeName;
if (mappings.containsKey(typeName)) {
uriRefStr = mappings.get(typeName);
}
metadata.add(new TripleImpl(textAnnotation, DC_TYPE, new IRI(uriRefStr)));
if (fs.getFeature("begin") != null) {
metadata.add(new TripleImpl(textAnnotation, ENHANCER_START, literalFactory.createTypedLiteral(fs.getFeature("begin").getValueAsInteger())));
}
if (fs.getFeature("end") != null) {
metadata.add(new TripleImpl(textAnnotation, ENHANCER_END, literalFactory.createTypedLiteral(fs.getFeature("end").getValueAsInteger())));
}
if (fs.getCoveredText() != null && !fs.getCoveredText().isEmpty()) {
metadata.add(new TripleImpl(textAnnotation, ENHANCER_SELECTED_TEXT, new PlainLiteralImpl(fs.getCoveredText())));
}
for (Feature f : fs.getFeatures()) {
if (!f.getName().equals("begin") && !f.getName().equals("end") && tnfs.checkFeatureToConvert(typeName, f)) {
String predRefStr = uimaUri + ":" + f.getName();
if (mappings.containsKey(f.getName())) {
predRefStr = mappings.get(f.getName());
}
IRI predicate = new IRI(predRefStr);
metadata.add(new TripleImpl(textAnnotation, predicate, new PlainLiteralImpl(f.getValueAsString())));
}
}
}
}
}
} catch (NoSuchPartException e) {
logger.error(new StringBuilder("No UIMA results found with ref:").append(uimaUri).toString(), e);
}
}
use of org.apache.stanbol.commons.caslight.Feature in project stanbol by apache.
the class SaxUIMAServletResult2Offsets method startElement.
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
* java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String uri, String localName, String qname, Attributes attrs) throws SAXException {
if (!localName.equals("result")) {
elementCounter++;
String type = localName;
FeatureStructure fs = new FeatureStructure(sourceName + "." + localName + "#" + elementCounter, type);
for (int i = 0; i < attrs.getLength(); i++) {
String name = attrs.getQName(i);
String value = attrs.getValue(i);
if (checkIfInteger(value)) {
Feature<Integer> f = new Feature(name, value);
fs.addFeature(f);
} else {
Feature<String> f = new Feature(name, value);
fs.addFeature(f);
}
}
fsList.add(fs);
}
}
use of org.apache.stanbol.commons.caslight.Feature in project stanbol by apache.
the class UIMALocal method concertToCasLight.
private List<FeatureStructure> concertToCasLight(JCas jcas, String typeName) {
List<FeatureStructure> ret = new ArrayList<FeatureStructure>();
Type type = jcas.getTypeSystem().getType(typeName);
List<org.apache.uima.cas.Feature> featList = type.getFeatures();
for (FSIterator<org.apache.uima.cas.FeatureStructure> iterator = jcas.getFSIndexRepository().getAllIndexedFS(type); iterator.hasNext(); ) {
org.apache.uima.cas.FeatureStructure casFs = iterator.next();
logger.debug("Processing UIMA CAS FeatureSet:" + casFs.toString());
FeatureStructure newFs = new FeatureStructure(UUID.randomUUID().toString(), type.getShortName());
for (org.apache.uima.cas.Feature casF : featList) {
String fName = casF.getShortName();
logger.debug("Feature Name:" + fName);
if (casF.getRange().getName().equals("uima.cas.Sofa")) {
continue;
}
if (casF.getRange().isPrimitive()) {
logger.debug("Getting primitive value...");
if (casF.getRange().getName().equals("uima.cas.String")) {
String fVal = casFs.getStringValue(casF);
newFs.addFeature(new Feature<String>(fName, fVal));
} else if (casF.getRange().getName().equals("uima.cas.Integer")) {
int fVal = casFs.getIntValue(casF);
newFs.addFeature(new Feature<Integer>(fName, fVal));
} else if (casF.getRange().getName().equals("uima.cas.Short")) {
short fVal = casFs.getShortValue(casF);
newFs.addFeature(new Feature<Integer>(fName, (int) fVal));
} else if (casF.getRange().getName().equals("uima.cas.Byte")) {
byte fVal = casFs.getByteValue(casF);
newFs.addFeature(new Feature<Integer>(fName, (int) fVal));
} else if (casF.getRange().getName().equals("uima.cas.Double")) {
double fVal = casFs.getDoubleValue(casF);
newFs.addFeature(new Feature<Double>(fName, fVal));
} else if (casF.getRange().getName().equals("uima.cas.Float")) {
float fVal = casFs.getFloatValue(casF);
newFs.addFeature(new Feature<Double>(fName, (double) fVal));
} else {
Object fVal = casFs.clone();
newFs.addFeature(new Feature<Object>(fName, fVal));
}
} else {
logger.debug("Getting FeatureStructure value...");
throw new UnsupportedOperationException("This client cannot handle FeatureStructure features");
}
if (casFs instanceof Annotation && "coveredText".equals(fName)) {
newFs.setCoveredText(((Annotation) casFs).getCoveredText());
}
}
logger.debug("FeatureStructure:" + newFs);
ret.add(newFs);
}
return ret;
}
Aggregations