Annotation1 Annotation2 Annotation3 Annotation2 Annotation4
Annotation2
BLOCK Annotation3{} {
// Extract some information from Annotation3’s features and store
them in variables
DOCUMENTBLOCK Annotation2{} {
// Use the information extracted from Annotation3 to determine
if this particular Annotation2 is the one I want
}
}
And I actually want the custom BLOCK extension to have the right
context when within the BLOCK. So I want the DOCUMENTBLOCK extension
to look for
Annotation2 in the whole document, but once you are inside the
DOCUMENTBLOCK
Annotation2 should be the new scope (as the current BLOCK statement
does right now).
So initially this is the code I tried:
public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) {
// Create a new stream of the whole document
RutaStream docStream =
stream.getWindowStream(stream.getCas().getDocumentAnnotation(),
stream.getCas().getDocumentAnnotation().getType());
BlockApply result = new BlockApply(this);
crowd.beginVisit(this, result);
RuleApply apply = rule.apply(docStream, crowd, true);
for (AbstractRuleMatch<? extends AbstractRule> eachMatch :
apply.getList()) {
if (eachMatch.matched()) {
List<AnnotationFS> matchedAnnotations = ((RuleMatch)
eachMatch).getMatchedAnnotations(null, null);
if (matchedAnnotations == null || matchedAnnotations.isEmpty()) {
continue;
}
AnnotationFS each = matchedAnnotations.get(0);
if (each == null) {
continue;
}
List<Type> types = ((RutaRuleElement)
rule.getRuleElements().get(0)).getMatcher().getTypes(getParent() == null ?
this : getParent(), docStream);
for (Type eachType : types) {
RutaStream window = docStream.getWindowStream(each, eachType);
for (RutaStatement element : getElements()) {
if (element != null) {
element.apply(window, crowd);
}
}
}
}
}
crowd.endVisit(this, result);
return result;
}
I thought I would just get a new stream that covers the whole
document, and apply the rules to that but the call “apply.getList()”
would never return anything even though I don’t have any conditions in
the RUTA script for the DOCUMENTBLOCK extension. And that is why I
ended up calling the method getAllOfType, because that one was working
fine, but of course, it doesn’t apply the conditions.
Any ideas why the “getList” wouldn’t return anything even though I am
passing a new stream that covers the whole document?
If I get this to work, I have no problems contributing it to the UIMA
RUTA project.
Cheers,
Miguel
From: Peter Klügl <
<http://gmane.org/get-address.php?address=peter.kluegl%2deqSzvFVgjydBD
gjK7y7 TUQ%40public.gmane.org> peter.kluegl@...>
Subject:
<http://news.gmane.org/find-root.php?message_id=566D5BCE.7070503%40ave
rbis.c
om> Re: UIMA RUTA - Custom BLOCK extension
Newsgroups: <http://news.gmane.org/gmane.comp.apache.uima.devel>
gmane.comp.apache.uima.devel
Date: 2015-12-13 11:51:42 GMT (14 hours and 50 minutes ago)
Hi,
oh yes, this is a nice extension. I was also already planning to add
something like this, but in my use cases the explicit referencing to
each matched annotation in the gobal context was missing. Thus, I am
implementing the annotation issues first.
It is possible to specify something like this right now in UIMA Ruta
but I would not recommend it. You could either spam/remove annotations
on the complete document or you could use the recursion functionality
of BLOCKs.
Now to the custom block:
You need to apply the head rule of the block in order to evaluate the
conditions. The scope is changed by the usage of a new restricted
RutaStream (windowStream). In order to retain the scope, just use the
given RutaStream.
Without having tested it, it could look something like:
<at> Override
public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) {
BlockApply result = new BlockApply(this);
crowd.beginVisit(this, result);
RuleApply apply = rule.apply(stream, crowd, true);
for (AbstractRuleMatch<? extends AbstractRule> eachMatch :
apply.getList()) {
if (eachMatch.matched()) {
for (RutaStatement element : getElements()) {
if (element != null) {
element.apply(stream, crowd);
}
}
}
}
crowd.endVisit(this, result);
return result;
}
Let me know if this helps.
Do you want to contribute the block extension?
Best,
Peter
Am 12.12.2015 um 00:04 schrieb Miguel Alvarez:
Hi,
I am in the process of developing a custom BLOCK extension that
instead of changing the scope of the block, it uses the scope of the
this : getParent(), stream);
for (Type eachType : types) {
//System.out.println("each Type: " +
eachType.getShortName());
for(AnnotationFS each :
stream.getAllofType(eachType))
{
RutaStream window = stream.getWindowStream(each,
eachType);
for (RutaStatement element : getElements()) {
if (element != null) {
element.apply(window, crowd);
}
}
}
}
I assume in order to apply the conditions I would need something like
this:
RuleApply apply = rule.apply(stream, crowd);
But for some reason this doesn't work, because I guess the scope has
already
been changed and it is not able to find any of the annotations in
within
the
scope.
Does this make any sense? Is there a better way to do this?
Any help would be much appreciated.
Cheers,
Miguel