You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Rashad <ra...@gmail.com> on 2011/06/03 12:55:32 UTC
How to remove UIMA annotations?
Hi,
I'm reasonably new to UIMA and trying to get it to do what I want. I'm
attempting to perform entity extraction on 3 languages. I have an IF statement
at the start of each Analysis engine which skips if the language of the
document is not English for example - another AE detects the language to begin
with.
the next AE then tokenises this document (space tokeniser), next AE then
extracts entities and CAS consumer then writes this to disk.
However I don't want to write ALL the space tokenised annotations to the disk
aswell - only the extracted entities, as the files gets very large very
quickly! Once a token has been processed I want it to be removed from the CAS/
jCAS, but token.removeFromIndexes() (I'm using Java) just throws a concurrent
modification exception.
How do I get around this?
This is my code:
AnnotationIndex<Annotation> token = aJCas.getAnnotationIndex(Token.type);
FSIterator<Annotation> timeIter = token.iterator();
while (timeIter.hasNext()) {
Token currentToken = (Token) timeIter.next();
Token previousToken = null;
if (englishNamesAsTrie.search(currentToken.getToken().toLowerCase())) {
PersonName annotation = new PersonName(aJCas);
annotation.setBegin(currentToken.getBegin());
annotation.setEnd(currentToken.getEnd());
annotation.addToIndexes(aJCas);
currentToken.removeFromIndexes(aJCas)
}
}
}
Re: How to remove UIMA annotations?
Posted by Marshall Schor <ms...@schor.com>.
The best thing would be to not create them in the first place - is that a
possibility?
Some annotators make use of the ResultSpecification to avoid generating unwanted
annotations.
One thing to know is that while you can remove feature structures from CAS
Indexes, so they will not be found via the index, the space taken up by them in
the CAS is not reclaimed (until you completely "reset" the CAS to clear out
everything).
-Marshall
On 6/3/2011 8:07 AM, Rashad wrote:
> Ah I see.
>
> How would i go about removing ALL Token annotations?
>
> As they are useless to me as they are space tokenisers.
>
>
Re: How to remove UIMA annotations?
Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
You copy them from the index into a list and after that you iterate over the list to remove them from the indexes.
With uimaFIT and JCas wrappers you would write (there are similar calls for CAS in CasUtils).
// Copy the tokens into a new collection to avoid ConcurrentModificationExceptions
List<Token> tokens = new ArrayList<Token>(JCasUtils.select(jcas, Token.class));
for (Token t : tokens) {
t.removeFromIndexes();
}
With native UIMA native you'll have to go through the AnnotationIndex API as in your previous code example.
Cheers,
Richard
Am 03.06.2011 um 14:07 schrieb Rashad:
> Ah I see.
>
> How would i go about removing ALL Token annotations?
>
> As they are useless to me as they are space tokenisers.
--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab
FB 20 Computer Science Department
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------
Re: How to remove UIMA annotations?
Posted by Rashad <ra...@gmail.com>.
Ah I see.
How would i go about removing ALL Token annotations?
As they are useless to me as they are space tokenisers.
Re: How to remove UIMA annotations?
Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
Hello,
you need to collect the annotations that you want to remove in some list while you iterate over the annotation index. Once you are done iterating, you start iterating over that list to remove the annotations. You cannot add/remove annotations while you iterate over the annotation index, otherwise you get the ConcurrentModificationException.
Cheers,
Richard
Am 03.06.2011 um 12:55 schrieb Rashad:
> Hi,
>
> I'm reasonably new to UIMA and trying to get it to do what I want. I'm
> attempting to perform entity extraction on 3 languages. I have an IF statement
> at the start of each Analysis engine which skips if the language of the
> document is not English for example - another AE detects the language to begin
> with.
>
> the next AE then tokenises this document (space tokeniser), next AE then
> extracts entities and CAS consumer then writes this to disk.
>
> However I don't want to write ALL the space tokenised annotations to the disk
> aswell - only the extracted entities, as the files gets very large very
> quickly! Once a token has been processed I want it to be removed from the CAS/
> jCAS, but token.removeFromIndexes() (I'm using Java) just throws a concurrent
> modification exception.
>
> How do I get around this?
>
> This is my code:
>
> AnnotationIndex<Annotation> token = aJCas.getAnnotationIndex(Token.type);
> FSIterator<Annotation> timeIter = token.iterator();
> while (timeIter.hasNext()) {
> Token currentToken = (Token) timeIter.next();
> Token previousToken = null;
> if (englishNamesAsTrie.search(currentToken.getToken().toLowerCase())) {
> PersonName annotation = new PersonName(aJCas);
> annotation.setBegin(currentToken.getBegin());
> annotation.setEnd(currentToken.getEnd());
> annotation.addToIndexes(aJCas);
> currentToken.removeFromIndexes(aJCas)
> }
> }
> }
>
--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab
FB 20 Computer Science Department
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------