Search code examples
uimaruta

UIMA Ruta flexible annotation with variable sequence order


I am new to UIMA and trying to annotate a sequence based on Dependencies. I want to annotate the governor and dependent, but want to be able to annotate it no matter which of the two comes first in the sequence.

I think my problem currently is the syntax, this is one of the versions I tried:

INT beginPos;
INT endPos;
(Dependency.DependencyType == "xcomp")->{
{beginPos = Math.min{Dependency.Dependent.begin, Dependency.Governor.begin};
LOG("beginPos: " + beginPos);
{endPos = Math.max{Dependency.Dependent.end, Dependency.Governor.end};
//LOG("beginPos: " + beginPos + ", endPos: " + endPos);
{->CREATE(type.annotation.EGPConstruct, "begin" = beginPos, "end" = endPos, "constructID" = 2103)}};};

I get the messages "EarlyExitException" at "{begin", "Expecting SEMI but found =" at "..Pos = Math.min" and "Mismatched Input: {" at "{endPos"

Can someone help me debug this? Thanks!


Solution

  • There are at least two problems in your rules:

    • this is no valid Ruta syntax: {beginPos = Math.min{Dependency.Dependent.begin, Dependency.Governor.begin}; You cannot use Java code directly in a Ruta rule.
    • there is a semicolon missing at the end = 2103)}<>};};

    As Ruta is a generic script language, there are always different approaches how to solve an annotation task. According to your example above, this could look like:

    DECLARE Dependency (STRING DependencyType, Annotation Governor, Annotation Dependent);
    DECLARE EGPConstruct(INT constructID);
    
    
    // mock example
    c:CW{-> d:Dependency, d.DependencyType="xcomp",d.Governor=c,d.Dependent=s} s:SW;
    s:SW c:CW{-> d:Dependency, d.DependencyType="xcomp",d.Governor=c,d.Dependent=s};
    
    
    INT beginPos = 0;
    INT endPos = 0;
    
    dep:Dependency{dep.DependencyType=="xcomp"} -> {
        g:dep.Governor{-> beginPos=g.begin, endPos=g.end};
        d:dep.Dependent{d.begin<beginPos -> beginPos=d.begin};
        d:dep.Dependent{d.end>endPos -> endPos=d.end};
        dep{-> CREATE(EGPConstruct, "constructID"=1, "begin"=beginPos, "end"=endPos)};
    };
    

    Result