use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationPreferencesDialogContent method createLayerContainer.
private ListView<AnnotationLayer> createLayerContainer() {
return new ListView<AnnotationLayer>("annotationLayers") {
private static final long serialVersionUID = -4040731191748923013L;
@Override
protected void populateItem(ListItem<AnnotationLayer> item) {
// add checkbox
// get initial state
AnnotationPreference pref = stateModel.getObject().getPreferences();
List<Long> hiddenLayerIds = pref.getHiddenAnnotationLayerIds();
boolean isPreferredToShow = !hiddenLayerIds.contains(item.getModelObject().getId());
CheckBox layer_cb = new CheckBox("annotationLayerActive", Model.of(isPreferredToShow));
layer_cb.add(new AjaxEventBehavior("change") {
private static final long serialVersionUID = 8378489004897115519L;
@Override
protected void onEvent(AjaxRequestTarget target) {
// check state & live update preferences
List<Long> hiddenLayerIds = stateModel.getObject().getPreferences().getHiddenAnnotationLayerIds();
// get and switch state of checkbox
boolean isPreferredToShow = layer_cb.getModelObject();
layer_cb.setModelObject(!isPreferredToShow);
// live update preferences
if (isPreferredToShow) {
// prefer to deactivate layer
hiddenLayerIds.add(item.getModelObject().getId());
} else {
// prefer to activate layer
hiddenLayerIds.remove(item.getModelObject().getId());
}
}
});
item.add(layer_cb);
// add coloring strategy combobox
ChoiceRenderer<ColoringStrategyType> choiceRenderer = new ChoiceRenderer<>("descriptiveName");
List<ColoringStrategyType> choices = new ArrayList<ColoringStrategyType>(EnumSet.allOf(ColoringStrategyType.class));
Model<ColoringStrategyType> initialSelected = Model.of(form.getModelObject().colorPerLayer.get(item.getModelObject().getId()));
DropDownChoice<ColoringStrategyType> layer_color = new DropDownChoice<ColoringStrategyType>("layercoloring", initialSelected, choices, choiceRenderer);
layer_color.add(new AjaxFormComponentUpdatingBehavior("change") {
private static final long serialVersionUID = 1060397773470276585L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
AnnotationLayer current_layer = item.getModelObject();
ColoringStrategyType selectedColor = layer_color.getModelObject();
form.getModelObject().colorPerLayer.put(current_layer.getId(), selectedColor);
}
});
item.add(layer_color);
// add label
Label lbl = new Label("annotationLayerDesc", item.getModelObject().getUiName());
item.add(lbl);
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class CopyAnnotationTest method setup.
@Before
public void setup() {
project = new Project();
tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
tokenPosFeature = new AnnotationFeature();
tokenPosFeature.setName("pos");
tokenPosFeature.setEnabled(true);
tokenPosFeature.setType(POS.class.getName());
tokenPosFeature.setUiName("pos");
tokenPosFeature.setLayer(tokenLayer);
tokenPosFeature.setProject(project);
tokenPosFeature.setVisible(true);
posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
posLayer.setAttachType(tokenLayer);
posLayer.setAttachFeature(tokenPosFeature);
posFeature = new AnnotationFeature();
posFeature.setName("PosValue");
posFeature.setEnabled(true);
posFeature.setType(CAS.TYPE_NAME_STRING);
posFeature.setUiName("PosValue");
posFeature.setLayer(posLayer);
posFeature.setProject(project);
posFeature.setVisible(true);
slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
slotFeature = new AnnotationFeature();
slotFeature.setName("links");
slotFeature.setEnabled(true);
slotFeature.setType(Token.class.getName());
slotFeature.setLinkMode(LinkMode.WITH_ROLE);
slotFeature.setUiName("f1");
slotFeature.setLayer(slotLayer);
slotFeature.setProject(project);
slotFeature.setVisible(true);
stringFeature = new AnnotationFeature();
stringFeature.setName("f1");
stringFeature.setEnabled(true);
stringFeature.setType(CAS.TYPE_NAME_STRING);
stringFeature.setUiName("f1");
stringFeature.setLayer(slotLayer);
stringFeature.setProject(project);
stringFeature.setVisible(true);
annotationSchemaService = new MockUp<AnnotationSchemaService>() {
@Mock
List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
if (type.getName().equals(POS.class.getName())) {
return asList(posFeature);
}
if (type.getName().equals(DiffUtils.HOST_TYPE)) {
return asList(slotFeature, stringFeature);
}
throw new IllegalStateException("Unknown layer type: " + type.getName());
}
@Mock
TypeAdapter getAdapter(AnnotationLayer aLayer) {
return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
}
}.getMockInstance();
featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
featureSupportRegistry.init();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class SuggestionViewPanel method render.
private String render(JCas aJcas, AnnotatorState aBratAnnotatorModel, ColoringStrategy aCurationColoringStrategy) throws IOException {
List<AnnotationLayer> layersToRender = new ArrayList<>();
for (AnnotationLayer layer : aBratAnnotatorModel.getAnnotationLayers()) {
boolean isSegmentationLayer = layer.getName().equals(Token.class.getName()) || layer.getName().equals(Sentence.class.getName());
boolean isUnsupportedLayer = layer.getType().equals(CHAIN_TYPE);
if (layer.isEnabled() && !isSegmentationLayer && !isUnsupportedLayer) {
layersToRender.add(layer);
}
}
VDocument vdoc = new VDocument();
preRenderer.render(vdoc, aBratAnnotatorModel, aJcas, layersToRender);
GetDocumentResponse response = new GetDocumentResponse();
BratRenderer.render(response, aBratAnnotatorModel, vdoc, aJcas, annotationService, aCurationColoringStrategy);
return JSONUtil.toInterpretableJsonString(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class ProjectLayersPanel method onModelChanged.
@Override
protected void onModelChanged() {
super.onModelChanged();
layerSelectionForm.getModelObject().layerSelection = null;
featureSelectionForm.getModelObject().feature = null;
layerDetailForm.setModelObject(new AnnotationLayer());
layerDetailForm.setVisible(false);
featureSelectionForm.setVisible(false);
featureDetailForm.setModelObject(new AnnotationFeature());
featureDetailForm.setVisible(false);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class CasDiff2 method getAdapters.
public static List<DiffAdapter> getAdapters(AnnotationSchemaService annotationService, Project project) {
List<DiffAdapter> adapters = new ArrayList<>();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(project)) {
Set<String> labelFeatures = new LinkedHashSet<>();
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!f.isEnabled()) {
continue;
}
// Link features are treated separately from primitive label features
if (!LinkMode.NONE.equals(f.getLinkMode())) {
continue;
}
labelFeatures.add(f.getName());
}
DiffAdapter_ImplBase adpt;
switch(layer.getType()) {
case SPAN_TYPE:
{
adpt = new SpanDiffAdapter(layer.getName(), labelFeatures);
break;
}
case RELATION_TYPE:
{
ArcAdapter typeAdpt = (ArcAdapter) annotationService.getAdapter(layer);
adpt = new ArcDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
break;
}
case CHAIN_TYPE:
// FIXME Currently, these are ignored.
continue;
default:
throw new IllegalStateException("Unknown layer type [" + layer.getType() + "]");
}
adapters.add(adpt);
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!f.isEnabled()) {
continue;
}
switch(f.getLinkMode()) {
case NONE:
// Nothing to do here
break;
case SIMPLE:
adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
break;
case WITH_ROLE:
adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
break;
default:
throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
}
labelFeatures.add(f.getName());
}
}
return adapters;
}
Aggregations