Setting feature value to the count of containing annotation in UIMA Ruta

天涯浪子 提交于 2019-12-05 20:14:06

There are several ways to express this in UIMA Ruta. My first guess would be something like:

// just to have an executable example
DECLARE Sentence;
DECLARE Annotation Down (INT sentence_index);
((# PERIOD){-> Sentence})+;
"down" -> Down;

// the acutal rule with a helper variable
INT index;
Sentence{CONTAINS(Down), CURRENTCOUNT(Sentence, index)} -> 
   {Down{-> Down.sentence_index = index};};

The rule matches on all sentences that contain a Down annotation. Additionally, CURRENTCOUNT counts the Sentence annotations upto the matched position and stores the values in the variable index. Then, an inlined rule (indicated by the first "->") matches on all Down annotations within the matched sentence and assigns the value of the variable to the feature of the matched Down annotation. Depending if you want to start with 0 or 1, you need to increment the assigned value:

... Down.sentence_index = (index+1)};};

The condition CURRENTCOUNT can also accept an min and max value in order to act like a real condition. It is realy old, so I don't know how it scales for large documents.

Here's another example, but this time without the CURRENTCOUNT condition and for storing the index in the Sentence annotation:

DECLARE Annotation Sentence (INT index);
DECLARE Annotation Down (INT sentence_index);
INT index;

(# PERIOD){-> Sentence, ASSIGN(index, (index + 1)), Sentence.index = index};
PERIOD (# PERIOD){-> Sentence, ASSIGN(index, (index + 1)), Sentence.index = index};
"down" -> Down;

Sentence{CONTAINS(Down) -> ASSIGN(index, Sentence.index)} 
  ->  {Down{-> Down.sentence_index = index};};

Mind that the rule for creating Sentence annotations in the first example cannot be used since it uses only one rule match and its actions are applied on the matched fragments. The rule in the second example results in many rule matches and thus applies the actions before the next rule match is processed. The copying between feautre values of different matching scopes is not really nice, but that will maybe be improved sometime.

If you have already Sentence annotations, you can assign the index with something like:

Sentence{-> ASSIGN(index, (index + 1)), Sentence.index = index};

Examples have been tested with UIMA Ruta 2.2.1-SNAPSHOT.

(I am a developer of UIMA Ruta)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!