uima - 将 JAPE 规则转换为 UIMA RUTA
问题描述
是否有任何示例可以解释在 JAPE 规则的 RHS 部分编写的 JAVA 代码如何在 UIMA RUTA 中转换?还有什么方法可以获取 RUTA 中注释的功能?
解决方案
您是否可以在开始 RUTA 分析之前将注释(由其他系统发现)注入 RUTA?所以,如果这是问题,答案是“是的,这是可能的”。
你可以这样做:
private static createCASAnnotation(Cas cas, MyOwnAnnotation myOwnAnnotation) {
Type annotationType = cas.getTypeSystem().getType(myOwnAnnotation.getType());
if (annotationType != null) {
AnnotationFS casAnnotation = cas.createAnnotation(annotationType, myOwnAnnotation.getTextStart(), myOwnAnnotation.getTextEnd());
// Also possible to add features / child annotations
for (MyOwnAnnotation childAnnotation : myOwnAnnotation.getChildAnnotations()) {
String featureFullName = casAnnotation.getType().getName() + ":" + childAnnotation.getName();
Feature feature = casAnnotation.getCAS().getTypeSystem().getFeatureByFullName(featureFullName);
if (feature != null && feature.getRange().isPrimitive()
&& "uima.cas.String".equalsIgnoreCase(feature.getRange().getName())) {
casAnnotation.setStringValue(feature, childAnnotation.getText());
// Other options for example "uima.cas.Integer" -> casAnnotation.setIntValue(...
}
// if not primitive you can also add Annotation type:
// AnnotationFS childCASAnnotation = createCASAnnotation(...
// casAnnotation.setFeatureValue(feature, childCASAnnotation);
}
cas.addFsToIndexes(casAnnotation);
} else {
log.error("invalid type .... or something better");
// Or throw exception
}
}
MyOwnAnnotation 是来自您自己的域/系统的对象,可以是:
class MyAnnotation {
private final String value; // or text or fragment ...??
private final Long startIndex;
private final Long endIndex; // or use size/length
private final List<MyAnnotation> childAnnotations;
// constructor, builder pattern?, getters ....
}
代码示例用于演示该概念。
推荐阅读
- c# - 当我在 C# 中使用 inkcanvas1.Strokes.Erase 语句时,WPF-InkCanvas StrokeErased 事件未触发
- python - 遍历数据帧,编写字典并将浮点值附加到键
- javascript - React 中的动态 GraphQL 突变与模板文字
- javascript - 如何使用 Javascript 访问严格/显式 href 值?
- chart.js - 如何在 x 轴上显示半小时刻度
- wkhtmltopdf - 文本在表中重叠
- datomic - 排除某些 id 的查询
- kotlin - 模拟每个 {}.throws() 异常失败测试
- asp.net-core - Blazor - 使用移动设备访问已发布网站时出错
- google-analytics - 主机名流量和 ISP 域访问有什么区别?