Search in sources :

Example 1 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.

the class AnnotationDetailEditorPanel method writeFeatureEditorModelsToCas.

private void writeFeatureEditorModelsToCas(TypeAdapter aAdapter, JCas aJCas) throws IOException {
    AnnotatorState state = getModelObject();
    List<FeatureState> featureStates = state.getFeatureStates();
    LOG.trace("writeFeatureEditorModelsToCas()");
    List<AnnotationFeature> features = new ArrayList<>();
    for (FeatureState featureState : featureStates) {
        features.add(featureState.feature);
        // For string features with extensible tagsets, extend the tagset
        if (CAS.TYPE_NAME_STRING.equals(featureState.feature.getType())) {
            String value = (String) featureState.value;
            if (value != null && featureState.feature.getTagset() != null && featureState.feature.getTagset().isCreateTag() && !annotationService.existsTag(value, featureState.feature.getTagset())) {
                Tag selectedTag = new Tag();
                selectedTag.setName(value);
                selectedTag.setTagSet(featureState.feature.getTagset());
                annotationService.createTag(selectedTag);
            }
        }
        LOG.trace("writeFeatureEditorModelsToCas() " + featureState.feature.getUiName() + " = " + featureState.value);
        aAdapter.setFeatureValue(state, aJCas, state.getSelection().getAnnotation().getId(), featureState.feature, featureState.value);
    }
    // Generate info message
    if (state.getSelection().getAnnotation().isSet()) {
        String bratLabelText = TypeUtil.getUiLabelText(aAdapter, selectByAddr(aJCas, state.getSelection().getAnnotation().getId()), features);
        info(generateMessage(state.getSelectedAnnotationLayer(), bratLabelText, false));
    }
}
Also used : AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) FeatureState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 2 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.

the class AnnotationDetailEditorPanel method populateTagsBasedOnRules.

/**
 * Adds and sorts tags based on Constraints rules
 */
private void populateTagsBasedOnRules(JCas aJCas, FeatureState aModel) {
    LOG.trace("populateTagsBasedOnRules(feature: " + aModel.feature.getUiName() + ")");
    AnnotatorState state = getModelObject();
    // Add values from rules
    String restrictionFeaturePath;
    switch(aModel.feature.getLinkMode()) {
        case WITH_ROLE:
            restrictionFeaturePath = aModel.feature.getName() + "." + aModel.feature.getLinkTypeRoleFeatureName();
            break;
        case NONE:
            restrictionFeaturePath = aModel.feature.getName();
            break;
        default:
            throw new IllegalArgumentException("Unsupported link mode [" + aModel.feature.getLinkMode() + "] on feature [" + aModel.feature.getName() + "]");
    }
    aModel.indicator.reset();
    // Fetch possible values from the constraint rules
    List<PossibleValue> possibleValues;
    try {
        FeatureStructure featureStructure = selectByAddr(aJCas, state.getSelection().getAnnotation().getId());
        Evaluator evaluator = new ValuesGenerator();
        // Only show indicator if this feature can be affected by Constraint rules!
        aModel.indicator.setAffected(evaluator.isThisAffectedByConstraintRules(featureStructure, restrictionFeaturePath, state.getConstraints()));
        possibleValues = evaluator.generatePossibleValues(featureStructure, restrictionFeaturePath, state.getConstraints());
        LOG.debug("Possible values for [" + featureStructure.getType().getName() + "] [" + restrictionFeaturePath + "]: " + possibleValues);
    } catch (Exception e) {
        error("Unable to evaluate constraints: " + ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Unable to evaluate constraints: " + e.getMessage(), e);
        possibleValues = new ArrayList<>();
    }
    // Fetch actual tagset
    List<Tag> valuesFromTagset = annotationService.listTags(aModel.feature.getTagset());
    // First add tags which are suggested by rules and exist in tagset
    List<Tag> tagset = compareSortAndAdd(possibleValues, valuesFromTagset, aModel.indicator);
    // Then add the remaining tags
    for (Tag remainingTag : valuesFromTagset) {
        if (!tagset.contains(remainingTag)) {
            tagset.add(remainingTag);
        }
    }
    // Record the possible values and the (re-ordered) tagset in the feature state
    aModel.possibleValues = possibleValues;
    aModel.tagset = tagset;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ArrayList(java.util.ArrayList) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) NoResultException(javax.persistence.NoResultException) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 3 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.

the class AnnotationFeatureForm method getBindTags.

Map<String, String> getBindTags() {
    AnnotationFeature f = annotationService.listAnnotationFeature(getModelObject().getSelectedAnnotationLayer()).get(0);
    TagSet tagSet = f.getTagset();
    Map<Character, String> tagNames = new LinkedHashMap<>();
    Map<String, String> bindTag2Key = new LinkedHashMap<>();
    for (Tag tag : annotationService.listTags(tagSet)) {
        if (tagNames.containsKey(tag.getName().toLowerCase().charAt(0))) {
            String oldBinding = tagNames.get(tag.getName().toLowerCase().charAt(0));
            String newBinding = oldBinding + tag.getName().toLowerCase().charAt(0);
            tagNames.put(tag.getName().toLowerCase().charAt(0), newBinding);
            bindTag2Key.put(newBinding, tag.getName());
        } else {
            tagNames.put(tag.getName().toLowerCase().charAt(0), tag.getName().toLowerCase().substring(0, 1));
            bindTag2Key.put(tag.getName().toLowerCase().substring(0, 1), tag.getName());
        }
    }
    return bindTag2Key;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.

the class JsonImportUtil method replaceTagSet.

private static TagSet replaceTagSet(Project project, ExportedTagSet importedTagSet, AnnotationSchemaService aAnnotationService) throws IOException {
    String importedTagSetName = importedTagSet.getName();
    de.tudarmstadt.ukp.clarin.webanno.model.TagSet tagsetInUse = aAnnotationService.getTagSet(importedTagSetName, project);
    // Remove all tags associated with Tagset
    aAnnotationService.removeAllTags(tagsetInUse);
    // Copy and update TagSet Information from imported tagset
    tagsetInUse.setDescription(importedTagSet.getDescription());
    tagsetInUse.setName(importedTagSetName);
    tagsetInUse.setLanguage(importedTagSet.getLanguage());
    tagsetInUse.setProject(project);
    aAnnotationService.createTagSet(tagsetInUse);
    // Add all tags from imported tagset
    for (ExportedTag tag : importedTagSet.getTags()) {
        Tag newTag = new Tag();
        newTag.setDescription(tag.getDescription());
        newTag.setName(tag.getName());
        newTag.setTagSet(tagsetInUse);
        aAnnotationService.createTag(newTag);
    }
    return tagsetInUse;
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag) ExportedTag(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)

Example 5 with Tag

use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.

the class CasToBratJsonTest method testGenerateBratJsonGetCollection.

/**
 * generate BRAT JSON for the collection informations
 *
 * @throws IOException
 *             if an I/O error occurs.
 */
@Test
public void testGenerateBratJsonGetCollection() throws IOException {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    String jsonFilePath = "target/test-output/output_cas_to_json_collection.json";
    GetCollectionInformationResponse collectionInformation = new GetCollectionInformationResponse();
    List<AnnotationLayer> layerList = new ArrayList<>();
    AnnotationLayer layer = new AnnotationLayer();
    layer.setId(1l);
    layer.setDescription("span annoattion");
    layer.setName("pos");
    layer.setType(WebAnnoConst.SPAN_TYPE);
    TagSet tagset = new TagSet();
    tagset.setId(1l);
    tagset.setDescription("pos");
    tagset.setLanguage("de");
    tagset.setName("STTS");
    Tag tag = new Tag();
    tag.setId(1l);
    tag.setDescription("noun");
    tag.setName("NN");
    tag.setTagSet(tagset);
    layerList.add(layer);
    collectionInformation.addCollection("/Collection1/");
    collectionInformation.addCollection("/Collection2/");
    collectionInformation.addCollection("/Collection3/");
    collectionInformation.addDocument("/Collection1/doc1");
    collectionInformation.addDocument("/Collection2/doc1");
    collectionInformation.addDocument("/Collection3/doc1");
    collectionInformation.addDocument("/Collection1/doc2");
    collectionInformation.addDocument("/Collection2/doc2");
    collectionInformation.addDocument("/Collection3/doc2");
    collectionInformation.setSearchConfig(new ArrayList<>());
    List<String> tagSetNames = new ArrayList<>();
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.POS);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.DEPENDENCY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.NAMEDENTITY);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFERENCE);
    tagSetNames.add(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.COREFRELTYPE);
    JSONUtil.generatePrettyJson(jsonConverter, collectionInformation, new File(jsonFilePath));
    assertThat(linesOf(new File("src/test/resources/output_cas_to_json_collection_expected.json"), "UTF-8")).isEqualTo(linesOf(new File(jsonFilePath), "UTF-8"));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) ArrayList(java.util.ArrayList) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) GetCollectionInformationResponse(de.tudarmstadt.ukp.clarin.webanno.brat.message.GetCollectionInformationResponse) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) File(java.io.File) Test(org.junit.Test)

Aggregations

Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)17 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)11 ExportedTag (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)7 ArrayList (java.util.ArrayList)7 ExportedTagSet (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet)5 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)5 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)4 IOException (java.io.IOException)4 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)3 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)3 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 File (java.io.File)2 HashSet (java.util.HashSet)2 UIMAException (org.apache.uima.UIMAException)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Options (com.googlecode.wicket.jquery.core.Options)1 TooltipBehavior (com.googlecode.wicket.jquery.ui.widget.tooltip.TooltipBehavior)1 ProjectType (de.tudarmstadt.ukp.clarin.webanno.api.ProjectType)1 FeatureState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.FeatureState)1