You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Jérôme Rocheteau <je...@univ-nantes.fr> on 2010/01/28 14:42:14 UTC

FeaturePath's built-in function "coveredText()"

Hello,

I'd like to known how to use the built-in function "coveredText()" described in the
API of the FeaturePath interface? For example, I'd like to select annotations of
type uima.tcas.Annotation covering the text "UIMA". How can I do that?

Thanks in advance,
Jérôme

Re: FeaturePath's built-in function "coveredText()"

Posted by Jérôme Rocheteau <je...@univ-nantes.fr>.
Hi,

I reply to my own mail; it could be useful for others. 

I don't use the built-in function of the FeaturePath interface.
Instead, I define a class CoveredTextConstraint that inherits 
from FSMatchConstraint as follows: 

import org.apache.uima.cas.FSMatchConstraint;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.jcas.tcas.Annotation;

public class CoveredTextConstraint implements FSMatchConstraint {
	
	private String coveredText;

	private void setCoveredText(String coveredText) {
		this.coveredText = coveredText;
	}
	
	private String getCoveredText() {
		return this.coveredText;
	}
	
	public CoveredTextConstraint(String coveredText) {
		this.setCoveredText(coveredText);
	}

	public boolean match(FeatureStructure fs) {
		if (fs instanceof Annotation) {
			Annotation a = (Annotation) fs;
			String coveredText = a.getCoveredText();
			return coveredText.equals(this.getCoveredText());
		}
		return false;
	}

}

An instance of this class is created by defining the required covered text within its
constructor. The method 'boolean match(FeatureStructure)' checks if this feature
structure is an instance of the class uima.tcas.Annotation, then gets its covered text and 
return true if and only if the latter is exactly the same as that of the required
one. That's all.

You can use this class as follows:

CoveredTextConstraint aCoveredTextConstraint = new CoveredTextConstraint(" ... ");
FSIterator<Annotation> anIterator = cas.getAnnotationIndex().iterator();
FSIterator<Annotation> anotherIterator =
  aCas.createFilteredIterator(anIterator,aCoveredTextConstraint);
...

HTH
Jérôme

Thu, 28 Jan 2010 14:42:14 +0100,
Jérôme Rocheteau <je...@univ-nantes.fr> a écrit :

> Hello,
> 
> I'd like to known how to use the built-in function "coveredText()" described in the
> API of the FeaturePath interface? For example, I'd like to select annotations of
> type uima.tcas.Annotation covering the text "UIMA". How can I do that?
> 
> Thanks in advance,
> Jérôme