首页 > 解决方案 > 将 JAPE 规则转换为 UIMA RUTA

问题描述

是否有任何示例可以解释在 JAPE 规则的 RHS 部分编写的 JAVA 代码如何在 UIMA RUTA 中转换?还有什么方法可以获取 RUTA 中注释的功能?

标签: uimagateruta

解决方案


您是否可以在开始 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 ....
}

代码示例用于演示该概念。


推荐阅读