Search code examples
conditional-statementsuimaruta

UIMA RUTA - How to simulate a IF-ELSE-Condition?


I am currently trying to solve the following use-case in RUTA:

If a Fragment contains one or more words from a WordlistA, then CREATE(Process, "finished" = "true")
If the Fragment contains none of the words from the WordlistA, then CREATE(Process, "finished" = "false")

So the created annotation Process@finished should be either true or false but never 'true' and 'false' at the same time.

I tried this one:

DECLARE Process (STRING finsihed);
WORDLIST WordlistA = 'mywordlist.txt';
Document{-> MARKFAST(ProcessTerm, WordlistA)};
Fragment {} -> {ProcessTerm {-> CREATE(Process, "finished" = "true")};};
Fragment {-CONTAINS(ProcessTerm) -> CREATE(Process, "finished" = "false")};

As far as I can see, the second rule matches always!? But why? As a result the ProcessTerm@finished annotation contains 'true' and 'false' if the first rule matches, too.

What is the best way to achive the use-case using RUTA? In my opinion, I need something like an IF-ELSE-Statement.

As the use case changed a little bit in the last two hours into

If a **Document** contains one or more words from a WordlistA, then CREATE(Process, "finished" = "true")
If the **Document** contains none of the words from the WordlistA, then CREATE(Process, "finished" = "false")

I am now using Peters proposal in the following way:

Document->{
  Document{CONTAINS(ProcessTerm)-> CREATE(Process, "finished" = "true")};
  Document{-PARTOF(Process) -> CREATE(Process, "finished" = "false")};
};

Solution

  • There is no IF-THEN construct in Ruta (yet). The most similar thing would be two BLOCK constructs with mutually excluding conditions. Well, that can also be achieved with rules.

    To your rules: If the second rule matches always, then there are no (visible) ProcessTerm annotations within each Fragment annotation.

    In your first rule, you create the Process annotation for each ProcessTerm annotation within each Fragment annotation.

    If I did not misinterpret your description, I would assume that this could be what you are looking for:

    Fragment {CONTAINS(ProcessTerm) -> CREATE(Process, "finished" = "true")};
    Fragment {-CONTAINS(ProcessTerm) -> CREATE(Process, "finished" = "false")};
    

    This iterates over all Fragment annotations twice which is not really necessary. You could also do something like (or any variant with BLOCK and variables):

    Fragment->{
      Document{CONTAINS(ProcessTerm)-> CREATE(Process, "finished" = "true")};
      Document{-PARTOF(Process) -> CREATE(Process, "finished" = "false")};
    };
    

    DICLAIMER: I am a developer of UIMA Ruta