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));
}
}
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;
}
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;
}
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;
}
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"));
}
Aggregations