Преобразование правила JAPE в UIMA RUTA - PullRequest
0 голосов
/ 06 декабря 2018

Существует ли какой-либо пример, объясняющий, как код JAVA, написанный в RHS-части правила JAPE, может быть преобразован в UIMA RUTA?Также есть ли способ узнать особенности аннотаций в RUTA?

1 Ответ

0 голосов
/ 07 декабря 2018

Есть ли у вас вопрос, можете ли вы вводить аннотации (найденные другими системами) в 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 ....
}

Примеры кодадля демонстрации концепции.

...