Need to compare the feature of two annotations which having same index position-UIMA RUTA - uima

I have two annotations named First and Second.In this I need to compare the feature of two annotations which having same index position.
First.csv:
Position1;0
Position2;1
Script:
DECLARE Second(INT secondpass);
"Position1"->Second;
WORDTABLE FirstList = 'First.csv';
DECLARE Annotation First(INT firstpass);
Document{->MARKTABLE(First, 2, FirstList,true,0,"",0, "firstpass" = 1 )};
DECLARE Text;
p1:First ANY*? p2:Second{p1.secondpass == p2.firstpass -> MARK(Text)};
p1:First # p2:Second{p1.secondpass == p2.firstpass -> MARK(Text)}; wont work because both annotations are in same positions.

Depending on how exactly the offsets need to be checked, something like the following would probably do:
p1:First{-> MARK(Text)}<-{p2:Second{p1.begin==p2.begin,p1.end==p2.end,p1.firstpass==p2.secondpass};};
or
p1:First{p1.firstpass == Second.secondpass -> MARK(Text)};
You can specify this also with a conjunct rule element (&), but I would recommend to avoid these if not really necessary.
DISCLAIMER: I am a developer of UIMA Ruta

Related

Conditional declaration by array of records

I try to create many components depending on the value of constant elements. These elements are organized in an array of records.
Dymola prints the translation log for the example below:
But I'm sure to use fixed conditions because I only perform allowed operations on constant values.
Here is the simple example of what I wantet to do:
model ConditionalComponent
type Enum = enumeration(one,two,three);
record Tmp
parameter Integer ID;
parameter Boolean active;
end Tmp;
record TmpNamed
parameter Enum name;
extends Tmp;
end TmpNamed;
function reorder
input TmpNamed inp[:];
output Tmp out[size(inp,1)];
algorithm
for elem in inp loop
out[elem.name] := Tmp(elem.ID, elem.active);
end for;
end reorder;
constant TmpNamed testIn[:] = {
TmpNamed(Enum.two,20,true),
TmpNamed(Enum.one,10,true),
TmpNamed(Enum.three,30,true)};
constant Tmp testOut1[:] = reorder({
TmpNamed(Enum.two,20,true),
TmpNamed(Enum.one,10,true),
TmpNamed(Enum.three,30,true)});
constant Tmp testOut2[:] = reorder(testIn);
constant Boolean active1 = testOut1[Enum.one].active;
constant Boolean active2 = testOut2[Enum.one].active;
Real t1=0 if testOut1[Enum.one].active;
//Real t2=0 if testOut2[Enum.one].active;
//Real t3=0 if active1;
//Real t4=0 if active2;
end ConditionalComponent;
The function reorder is intended to ease the management of large lists of named active components. Normally the constant testOut2 is used and created within the package ConditionalComponent. But for testing purposes ConditionalComponent is a model here. Actually I only want to use the line
Real t2=0 if testOut2[choice].active;
parameter Enum choice = Enum.one;
within other components, that have a parameter of type Enum. The declarations for t1, t3, t4 are only some tests that work, depending on what is left uncommented.
For example leaving the declaration for t1 and t3 uncommented works. But if one uses only the declaration for t1, it is not translated by Dymola.
The difference between t1 and t2 is, that the argument for reorder is passed directly or via the constant testIn.
I'm sure, that most parameter and constant prefixes are unnecessary and I tried hard to figure out the problem. But unfortunately I cannot decide whether Dymola is not working correctly or I did something wrong. And I've got no idea how to debug the translation process to figure it out by myself.
Can anyone tell me, what am I doing wrong?
Not something wrong, but it's just currently seen as too complicated and not handled.
A work-around is to split subscripting and element access:
constant Tmp testOut1_one=testOut1[Enum.one];
Real t1=0 if testOut1_one.active;

Refer to only lower index in System Verilog

I have a bit array A[32][16].
I want to check if any of the lower index values have a certain pattern.
For eg.
A[1][8:0] may have that pattern A[2][8:0] may also have that pattern.
Any thing from A[31 - 0][8:0] may have that pattern. Is there a way to refer to all the higher index components in a single statement.
something like A[5'bxxxxx][8:0] ?
There is no syntax to select a non-contiguous set of bits from an array, packed or unpacked, in a single selection. If A is an unpacked array, you can use one of the array reduction methods to create an expression that might suit your needs.
if (A.or() with (item[8:0] == your_pattern) ) // if any match
if (A.and() with (item[8:0] == your_pattern) ) // if all match
If A is a packed array, you could use replication concatenation to match all
if ( {32{ {8'b?,your_pattern} } } ?== A )

How to match specific tokens in UIMA Ruta?

DECLARE A,B;
DECLARE Annotation C(Annotation firstA, Annotation secondA,...);
"token1|token2|...|tokenn" -> A;
"token3|token4" -> B;
A A B {->MARK(C,1,3)};
I did with GATHER
(A COMMA A B) {-> GATHER(C,1,4,"firstA"=1,"secondA" = 3,"B"=4)};
But how about in case of unknown sequence of A type? as below, how can it be possible to store all A in features? The number of features are also unknown. In plan java, we declare String array and can add element, but in Ruta seems to be no as such process.
(A (COMMA A)+ B) {-PARTOF(C) -> GATHER(C,beginPosition,endPosition,"firstA"=1,"secondA" = 3,"thirdA"=?,so on)};
Annotations in UIMA refer to the complete span, from the begin offset to the end offset. So, if you want to specify something with two elements, then a simple annotation is not sufficient. You cannot create an annotation of the type C that covers the first A and the B but not the second A.
However, you can store the important information in feature values. How to implement it depends on various things.
If there are always exactly two annotation you want to remember, then add two features to type C and assign the feature values in the given rule, e.g., by CREATE(C,1,3,"first" = A, "second" = B ).
You can also use different actions like GATHER, or use one FSArray feature in order to store the annotations.
A complete example with a FSArray:
DECLARE A, B;
DECLARE Annotation C (FSArray as, B b);
"A" -> A;
"B" -> B;
(A (COMMA A)+ B){-PARTOF(C) -> CREATE(C, "as" = A, "b" = B)};
If applied on a text like "A, A, A B", the last rule creates one annotation of type C that stores three A annotations in the feature "as" and one B annotation in the feature "b"

How to test, if an element is in a list?

Is there a built-in function to test, if a given element is in a list in Rexx?
I could not find one. The alternative would be to loop over the list and check each element manually.
No (unless things have changed); just loop through the list.
An alternative is instead / as well have a lookup variable
i.e.
lookup. = 0 /* not all versions of Rexx support
default initialisation like this */
....
addToList:
parse arg item
numberInList = numberInList + 1
list.numberInList = item
lookup.item = 1
return
You can then check if item is in the list by
if lookup.item = 1 then do
......
It depends what you mean by a list.
At work, I use classic REXX. I frequently store lists of words in a single variable, space delimited. So WORDPOS() is the built-in function I use.
If you are using a List class in ooREXX. then why not use the hasItem method from the Collection class.

Matching a list (of tags) with another and detecting presence of common elements

My requirement is to match tags. In the example, this particular HourConstraint checks the TeacherHour assigned to Hour(23).
Specifically, it checks TeacherHour.attributes["tags"] for the values ["asst_ct","teacher_john_smith"] and detects atleast one match, two in this case (both "asst_ct" and "teacher_john_smith") .
TeacherHour:
id: 47
assigned_hour: Null
attributes:Map<List<String>>
"tags":["asst_ct","no_strenuous_duties","kinda_boring","teacher_john_smith"]
"another_attribute":[...]
HourConstraint:
hour: Hour(23)
attribute: "tags"
values_list: ["asst_ct","teacher_john_smith"]
Question: How do I detect the presence (true or false) of common elements between two lists?
Drools Expert has memberOf and contains, but they check a scalar vs a collection, never a collection vs a collection.
I see two potential ways:
introduce a function boolean isIntersecting(list,list) and tell Drools to use that for truth checking
Implement TeacherHour.attributes[] as a string instead of a list and HourConstraint.valueslist as a regular expression that can match that list
There are a few options. Most straight forward is to use the Collections class to do that for you:
rule X
when
$t: TeacherHour( )
HourConstraint( Collections.disjoint( $t.attributes["tags"], values_list ) == false )
...
If this is something you would use often in your rules, then I recommend wrapping that function in a pluggable operator, supported by Drools. Lets say you name the operator "intersect", you can then write your rules like this:
rule X
when
$t: TeacherHour( )
HourConstraint( values_list intersect $t.attributes["tags"] )
...
A third option, is to use "from", but that is less efficient in runtime as it causes iterations on the first list:
rule X
when
$t: TeacherHour( )
$tag : String() from $t.attributes["tags"]
exists( HourConstraint( values_list contains $tag ) )
...