05juin 2011
Copier une annotation d'une vue à une autre dans UIMA
00:59 - Par Fabien Poulard - Geek & Technique - un commentaire
Lorsque l'on travaille avec plusieurs vues au sein d'un même CAS, on se retrouve rapidement confronté au besoin de recopier certaines annotations d'une vue vers une autre.
Il est possible de recréer l'annotation et de repositionner tous ses traits sur les mêmes valeurs que l'annotation d'origine. Cette approche est fastidieuse lorsque l'annotation est complexe, que l'on n'en connaît pas tous les traits ou bien lorsque l'on veut copier plusieurs annotations de types différentes.
Une autre approche, beaucoup plus souple, consiste à faire une copie profonde de l'objet Java du CAS correspondant à ladite annotation à l'aide de la méthode clone. Il faut alors penser à modifier la valeur du SOFA associée la nouvelle annotation sous peine de se voir refuser l'ajout de l'annotation copiée à l'index de la nouvelle vue.
La difficulté réside dans le fait que le trait contenant le SOFA n'est pas directement accessible. Il faut utiliser la méthode setFeatureValue pour mettre à jour la valeur :
Feature sofaFeature = annotation.getType().getFeatureByBaseName("sofa"); annotation.setFeatureValue(sofaFeature, view.getSofa());
Voici la méthode que j'utilise désormais pour copier mes annotations d'une vue à une autre :
public static Annotation copyAnnotationToView(Annotation a, JCas view) { // To copy the annotation we must process in three steps // 1- Clone the annotation from the original view Annotation a2 = (Annotation) a.clone(); // 2- Change the Sofa of the cloned annotation Feature sofaFeature = a2.getType().getFeatureByBaseName("sofa"); a2.setFeatureValue(sofaFeature, view.getSofa()); // 3- Add this annotation to the indexes of the new view a2.addToIndexes(view); return a2; }
un commentaire
Mike Firbank is turning his consideration towards the within in the developing. The power effective LED lights will substitute the previous and high-priced spotlights http://www.ratdresses.org/muslim-we... . The church has lately set up photo voltaic panels around the roof in the Cecil Norman constructing inside the church graveyard . It now gives green electrical energy for your numerous teams who utilize the constructing every day. Rector Firbank mentioned: The LED lights give a vivid distinct mild and decreases the electrical energy price to about 10% of what we are having to pay http://www.ratdresses.org/prom-dres... http://www.ratdresses.org/informal-... . We have some check types in currently. After you sit inside the aisle exactly where the LED lights are having a guide you receive a obvious mild. But if you go and sit beneath the regular bulb, http://www.ratdresses.org/bridesmad... a number of the pages are fairly shaded. http://www.ratdresses.org/prom-dres... ? The church had hoped it had funding in location final 12 months http://www.ratdresses.org , but due to the financial