use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.
the class AutomationPage method createDetailEditor.
private AnnotationDetailEditorPanel createDetailEditor() {
return new AnnotationDetailEditorPanel("annotationDetailEditorPanel", getModel()) {
private static final long serialVersionUID = 2857345299480098279L;
@Override
protected void onChange(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
aTarget.addChildren(getPage(), IFeedback.class);
try {
annotationEditor.requestRender(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
return;
}
try {
SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
curationContainer = builder.buildCurationContainer(state);
setCurationSegmentBeginEnd(getEditorCas());
curationContainer.setBratAnnotatorModel(state);
suggestionView.updatePanel(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
update(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
@Override
public void onAnnotate(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
if (state.isForwardAnnotation()) {
return;
}
AnnotationLayer layer = state.getSelectedAnnotationLayer();
int address = state.getSelection().getAnnotation().getId();
try {
JCas jCas = getEditorCas();
AnnotationFS fs = selectByAddr(jCas, address);
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
Type type = CasUtil.getType(fs.getCAS(), layer.getName());
Feature feat = type.getFeatureByBaseName(f.getName());
if (!automationService.existsMiraTemplate(f)) {
continue;
}
if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
continue;
}
TagSet tagSet = f.getTagset();
boolean isRepeatable = false;
// repeat only if the value is in the tagset
for (Tag tag : annotationService.listTags(tagSet)) {
if (fs.getFeatureValueAsString(feat) == null) {
// this is new annotation without values
break;
}
if (fs.getFeatureValueAsString(feat).equals(tag.getName())) {
isRepeatable = true;
break;
}
}
if (automationService.getMiraTemplate(f) != null && isRepeatable) {
if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
AutomationUtil.repeateRelationAnnotation(state, documentService, correctionDocumentService, annotationService, fs, f, fs.getFeatureValueAsString(feat));
update(aTarget);
break;
} else if (layer.getType().endsWith(WebAnnoConst.SPAN_TYPE)) {
AutomationUtil.repeateSpanAnnotation(state, documentService, correctionDocumentService, annotationService, fs.getBegin(), fs.getEnd(), f, fs.getFeatureValueAsString(feat));
update(aTarget);
break;
}
}
}
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
@Override
protected void onAutoForward(AjaxRequestTarget aTarget) {
annotationEditor.requestRender(aTarget);
}
@Override
public void onDelete(AjaxRequestTarget aTarget, AnnotationFS aFS) {
AnnotatorState state = getModelObject();
AnnotationLayer layer = state.getSelectedAnnotationLayer();
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!automationService.existsMiraTemplate(f)) {
continue;
}
if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
continue;
}
try {
Type type = CasUtil.getType(aFS.getCAS(), layer.getName());
Feature feat = type.getFeatureByBaseName(f.getName());
if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
AutomationUtil.deleteRelationAnnotation(state, documentService, correctionDocumentService, annotationService, aFS, f, aFS.getFeatureValueAsString(feat));
} else {
AutomationUtil.deleteSpanAnnotation(state, documentService, correctionDocumentService, annotationService, aFS.getBegin(), aFS.getEnd(), f, aFS.getFeatureValueAsString(feat));
}
update(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.
the class AnnotationSchemaServiceImpl method createTagSet.
@Override
public TagSet createTagSet(String aDescription, String aTagSetName, String aLanguage, String[] aTags, String[] aTagDescription, Project aProject) throws IOException {
TagSet tagSet = new TagSet();
tagSet.setDescription(aDescription);
tagSet.setLanguage(aLanguage);
tagSet.setName(aTagSetName);
tagSet.setProject(aProject);
createTagSet(tagSet);
int i = 0;
for (String tagName : aTags) {
Tag tag = new Tag();
tag.setTagSet(tagSet);
tag.setDescription(aTagDescription[i]);
tag.setName(tagName);
createTag(tag);
i++;
}
return tagSet;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.
the class JsonImportUtil method createTagSet.
public static TagSet createTagSet(Project project, ExportedTagSet importedTagSet, AnnotationSchemaService aAnnotationService) throws IOException {
String importedTagSetName = importedTagSet.getName();
if (aAnnotationService.existsTagSet(importedTagSetName, project)) {
// aAnnotationService.removeTagSet(aAnnotationService.getTagSet(
// importedTagSet.getName(), project));
// Rename Imported TagSet instead of deleting the old one.
importedTagSetName = copyTagSetName(aAnnotationService, importedTagSetName, project);
}
TagSet newTagSet = new TagSet();
newTagSet.setDescription(importedTagSet.getDescription());
newTagSet.setName(importedTagSetName);
newTagSet.setLanguage(importedTagSet.getLanguage());
newTagSet.setProject(project);
newTagSet.setCreateTag(importedTagSet.isCreateTag());
aAnnotationService.createTagSet(newTagSet);
for (ExportedTag tag : importedTagSet.getTags()) {
Tag newTag = new Tag();
newTag.setDescription(tag.getDescription());
newTag.setName(tag.getName());
newTag.setTagSet(newTagSet);
aAnnotationService.createTag(newTag);
}
return newTagSet;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.
the class AnnotationDetailEditorPanel method compareSortAndAdd.
/*
* Compares existing tagset with possible values resulted from rule evaluation Adds only which
* exist in tagset and is suggested by rules. The remaining values from tagset are added
* afterwards.
*/
private static List<Tag> compareSortAndAdd(List<PossibleValue> possibleValues, List<Tag> valuesFromTagset, RulesIndicator rulesIndicator) {
// if no possible values, means didn't satisfy conditions
if (possibleValues.isEmpty()) {
rulesIndicator.didntMatchAnyRule();
}
List<Tag> returnList = new ArrayList<>();
// tagset and adding them first in list.
for (PossibleValue value : possibleValues) {
for (Tag tag : valuesFromTagset) {
if (value.getValue().equalsIgnoreCase(tag.getName())) {
// Matching values found in tagset and shown in dropdown
rulesIndicator.rulesApplied();
// HACK BEGIN
tag.setReordered(true);
// Avoid duplicate entries
if (!returnList.contains(tag)) {
returnList.add(tag);
}
}
}
}
// If no matching tags found
if (returnList.isEmpty()) {
rulesIndicator.didntMatchAnyTag();
}
return returnList;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Tag in project webanno by webanno.
the class TagSetEditorPanel method export.
private FileResourceStream export() {
File exportFile = null;
if (exportFormat.getObject().equals(ExportedTagSetConstant.JSON_FORMAT)) {
try {
exportFile = File.createTempFile("exportedtagsets", ".json");
} catch (IOException e1) {
error("Unable to create temporary File!!");
return null;
}
if (isNull(selectedTagSet.getObject().getId())) {
error("Project not yet created. Please save project details first!");
} else {
TagSet tagSet = selectedTagSet.getObject();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
ExportedTag exportedTag = new ExportedTag();
exportedTag.setDescription(tag.getDescription());
exportedTag.setName(tag.getName());
exportedTags.add(exportedTag);
}
exTagSet.setTags(exportedTags);
try {
JSONUtil.generatePrettyJson(exTagSet, exportFile);
} catch (IOException e) {
error("File Path not found or No permision to save the file!");
}
info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
}
} else if (exportFormat.getObject().equals(ExportedTagSetConstant.TAB_FORMAT)) {
TagSet tagSet = selectedTagSet.getObject();
try {
exportFile = File.createTempFile("exportedtagsets", ".txt");
} catch (IOException e1) {
error("Unable to create temporary File!!");
}
OutputStream os;
OutputStreamWriter osw;
BufferedWriter bw;
try {
String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
os = new FileOutputStream(exportFile);
osw = new OutputStreamWriter(os, "UTF-8");
bw = new BufferedWriter(osw);
bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
bw.write(tagSet.getLanguage() + "\t" + " \n");
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
} catch (UnsupportedEncodingException e) {
error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
} catch (IOException e) {
error(ExceptionUtils.getRootCause(e));
}
}
return new FileResourceStream(exportFile);
}
Aggregations