overlapping annotations


ivy
 

Hi, I need to retrieve 2 matched tags of two adjusting annotations, but sometimes the second annotation (partially) overlaps the first one, in which case, only the first is found and consumed so that the second one can’t be found anymore. Ann. B within/contains ann. A doesn’t work.  Could you point me to how I can overcome this? Is it possible to remove the annotation once consumed, in the same rule? Where can I find more about it (with examples) in the documentation(link)?  Thanks!

Ivy


Ian Roberts
 

There's a few possible ways to approach this depending on the exact details of what you're trying to find and exactly what you mean by "2 matched tags".  It'll generally involve determining some wider context within which the two different annotations need to be "matched" - in the simplest case this might be a rule like

Phase: FindInSentence
Input: Sentence
Options: control = appelt

Rule: InSentence
({Sentence contains AnnA, Sentence contains AnnB}):sent
-->
:sent.HasBothTags = {}
Or conversely you could match the AnnA and AnnB separately in one phase and use some Java RHS code to add a feature to the containing sentence:
Phase: FindAAndB
Input: AnnA AnnB
Options: control = all

Rule: HasA
{AnnA}):match
-->
:match {
  for(Annotation sentence : gate.Utils.getCoveringAnnotations(inputAS, matchAnnots, "Sentence")) {
    sentence.getFeatures().put("hasAnnA", "true");
  }
}

Rule: HasB
({AnnB}):match
-->
:match {
  for(Annotation sentence : gate.Utils.getCoveringAnnotations(inputAS, matchAnnots, "Sentence")) {
    sentence.getFeatures().put("hasAnnB", "true");
  }
}

then a subsequent phase can look for {Sentence.hasAnnA == "true", Sentence.hasAnnB == "true"}. You can extend this technique in various ways, for example you can copy specific features up from the AnnA and AnnB annotations onto the Sentence with
sentence.getFeatures().put("somethingFromA", gate.Utils.getOnlyAnn(matchAnnots).getFeatures().get("something"));
and then use those when later matching the sentences.