You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ctakes.apache.org by Tomasz Oliwa <ol...@uchicago.edu> on 2016/04/08 00:15:48 UTC
Delete an OntologyConcept from a JCas using an Annotator
How can I delete an OntologyConcept from a JCas using an Annotator?
As an example, the following process method from an Annotator loops over all IdentifiedAnnotations, and is supposed to simply remove all OntologyConcepts. However, it does not remove anything from the CAS. I can still see all OntologyConcepts in the CAS Visual Debugger after running it.
public void process(JCas aJCas) throws AnalysisEngineProcessException {
JFSIndexRepository indexes = aJCas.getJFSIndexRepository();
Iterator neItr = indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator();
while (neItr.hasNext()) {
IdentifiedAnnotation neAnnot = (IdentifiedAnnotation) neItr.next();
FSArray ocArr = neAnnot.getOntologyConceptArr();
if (ocArr != null) {
for (int i = 0; i < ocArr.size(); i++) {
OntologyConcept oc = (OntologyConcept) ocArr.get(i);
oc.removeFromIndexes(aJCas);
aJCas.removeFsFromIndexes(oc);
}
}
}
}
If I change the code above to do neAnnot.removeFromIndexes(aJCas); to remove the whole IdentifiedAnnotation, this works and the annotation is removed and not displayed in the CAS Visual Debugger.
But how can I remove OntologyConcepts?
Am I missing an API call? Does the API have a problem here?
Regards,
Tomasz
RE: Delete an OntologyConcept from a JCas using an Annotator
Posted by Tomasz Oliwa <ol...@uchicago.edu>.
Sean,
This does the trick, thanks.
Regards,
Tomasz
________________________________________
From: Finan, Sean [Sean.Finan@childrens.harvard.edu]
Sent: Thursday, April 07, 2016 6:34 PM
To: dev@ctakes.apache.org
Subject: RE: Delete an OntologyConcept from a JCas using an Annotator
Hi Tomasz,
Just in case nobody has a better answer: I think that you might need to may a new array at size n-1 , then copy all ontology concepts that you do want, then set the annotation's ontology concept array to be the new one.
Sean
-----Original Message-----
From: Tomasz Oliwa [mailto:oliwa@uchicago.edu]
Sent: Thursday, April 07, 2016 6:16 PM
To: dev@ctakes.apache.org
Subject: Delete an OntologyConcept from a JCas using an Annotator
How can I delete an OntologyConcept from a JCas using an Annotator?
As an example, the following process method from an Annotator loops over all IdentifiedAnnotations, and is supposed to simply remove all OntologyConcepts. However, it does not remove anything from the CAS. I can still see all OntologyConcepts in the CAS Visual Debugger after running it.
public void process(JCas aJCas) throws AnalysisEngineProcessException {
JFSIndexRepository indexes = aJCas.getJFSIndexRepository();
Iterator neItr = indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator();
while (neItr.hasNext()) {
IdentifiedAnnotation neAnnot = (IdentifiedAnnotation) neItr.next();
FSArray ocArr = neAnnot.getOntologyConceptArr();
if (ocArr != null) {
for (int i = 0; i < ocArr.size(); i++) {
OntologyConcept oc = (OntologyConcept) ocArr.get(i);
oc.removeFromIndexes(aJCas);
aJCas.removeFsFromIndexes(oc);
}
}
}
}
If I change the code above to do neAnnot.removeFromIndexes(aJCas); to remove the whole IdentifiedAnnotation, this works and the annotation is removed and not displayed in the CAS Visual Debugger.
But how can I remove OntologyConcepts?
Am I missing an API call? Does the API have a problem here?
Regards,
Tomasz
RE: Delete an OntologyConcept from a JCas using an Annotator
Posted by "Finan, Sean" <Se...@childrens.harvard.edu>.
Hi Tomasz,
Just in case nobody has a better answer: I think that you might need to may a new array at size n-1 , then copy all ontology concepts that you do want, then set the annotation's ontology concept array to be the new one.
Sean
-----Original Message-----
From: Tomasz Oliwa [mailto:oliwa@uchicago.edu]
Sent: Thursday, April 07, 2016 6:16 PM
To: dev@ctakes.apache.org
Subject: Delete an OntologyConcept from a JCas using an Annotator
How can I delete an OntologyConcept from a JCas using an Annotator?
As an example, the following process method from an Annotator loops over all IdentifiedAnnotations, and is supposed to simply remove all OntologyConcepts. However, it does not remove anything from the CAS. I can still see all OntologyConcepts in the CAS Visual Debugger after running it.
public void process(JCas aJCas) throws AnalysisEngineProcessException {
JFSIndexRepository indexes = aJCas.getJFSIndexRepository();
Iterator neItr = indexes.getAnnotationIndex(IdentifiedAnnotation.type).iterator();
while (neItr.hasNext()) {
IdentifiedAnnotation neAnnot = (IdentifiedAnnotation) neItr.next();
FSArray ocArr = neAnnot.getOntologyConceptArr();
if (ocArr != null) {
for (int i = 0; i < ocArr.size(); i++) {
OntologyConcept oc = (OntologyConcept) ocArr.get(i);
oc.removeFromIndexes(aJCas);
aJCas.removeFsFromIndexes(oc);
}
}
}
}
If I change the code above to do neAnnot.removeFromIndexes(aJCas); to remove the whole IdentifiedAnnotation, this works and the annotation is removed and not displayed in the CAS Visual Debugger.
But how can I remove OntologyConcepts?
Am I missing an API call? Does the API have a problem here?
Regards,
Tomasz