You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@uima.apache.org by Miguel Alvarez <mi...@gmail.com> on 2015/12/12 00:04:52 UTC
UIMA RUTA - Custom BLOCK extension
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 whole Document.
With this type of BLOCK one could loop through a series of annotations, and
for each of those annotations search in the whole document for something
else. I guess my first questions is: Is it even possible to do something
like this without creating a custom BLOCK extension?
I got something to work, but it doesn't seem to apply the conditions for the
block. This is more or less the code I have so far:
List<Type> types = ((RutaRuleElement)
rule.getRuleElements().get(0)).getMatcher().getTypes(getParent() == null ?
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
Re: UIMA RUTA - Custom BLOCK extension
Posted by Peter Klügl <pe...@averbis.com>.
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:
@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 whole Document.
> With this type of BLOCK one could loop through a series of annotations, and
> for each of those annotations search in the whole document for something
> else. I guess my first questions is: Is it even possible to do something
> like this without creating a custom BLOCK extension?
>
>
>
> I got something to work, but it doesn't seem to apply the conditions for the
> block. This is more or less the code I have so far:
>
>
>
> List<Type> types = ((RutaRuleElement)
> rule.getRuleElements().get(0)).getMatcher().getTypes(getParent() == null ?
> 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
>
>