uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jérôme Rocheteau <jerome.rochet...@univ-nantes.fr>
Subject Re: FeaturePath's built-in function "coveredText()"
Date Fri, 05 Mar 2010 12:42:50 GMT
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 <jerome.rocheteau@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


Mime
View raw message