@Override public DocumentMetadataLayerAdapter createAdapter(AnnotationLayer aLayer) { DocumentMetadataLayerAdapter adapter = new DocumentMetadataLayerAdapter( featureSupportRegistry, eventPublisher, aLayer, schemaService.listAnnotationFeature(aLayer)); return adapter; }
@EventListener public void beforeProjectRemove(BeforeProjectRemovedEvent aEvent) throws Exception { Project project = aEvent.getProject(); for (AnnotationFeature feature : service.listAnnotationFeature(project)) { service.removeAnnotationFeature(feature); } // remove the layers too for (AnnotationLayer layer : service.listAnnotationLayer(project)) { service.removeAnnotationLayer(layer); } for (TagSet tagSet : service.listTagSets(project)) { service.removeTagSet(tagSet); } } }
public static List<Type> getEntryTypes(JCas mergeJCas, List<AnnotationLayer> aLayers, AnnotationSchemaService aAnnotationService) { List<Type> entryTypes = new LinkedList<>(); for (AnnotationLayer layer : aLayers) { if (layer.getName().equals(Token.class.getName())) { continue; } if (layer.getType().equals(WebAnnoConst.CHAIN_TYPE)) { continue; } entryTypes.add( aAnnotationService.getAdapter(layer).getAnnotationType(mergeJCas.getCas())); } return entryTypes; }
@Override public void configure(Project aProject) throws IOException { AnnotationLayer neLayer = annotationSchemaService.getLayer(NamedEntity.class.getName(), aProject); annotationSchemaService.createFeature(new AnnotationFeature(aProject, neLayer, "identifier", "identifier", ConceptFeatureSupport.TYPE_ANY_OBJECT, "Linked entity", null)); } }
@Override public ConceptFeatureTraits getFeatureTraits(Project aProject) { AnnotationLayer linkedLayer = annotationService .getLayer(NamedEntity.class.getName(), aProject); AnnotationFeature linkedFeature = annotationService .getFeature(FactLinkingConstants.LINKED_LAYER_FEATURE, linkedLayer); FeatureSupport<ConceptFeatureTraits> fs = featureSupportRegistry .getFeatureSupport(linkedFeature); ConceptFeatureTraits traits = fs.readTraits(linkedFeature); return traits; }
return emptyList(); AnnotationLayer layer = annotationService.getLayer(proj, fs); TypeAdapter adapter = annotationService.getAdapter(layer); for (AnnotationFeature feature : annotationService.listAnnotationFeature(layer)) { if (!feature.isEnabled()) { continue; featureState.tagset = annotationService.listTags(featureState.feature.getTagset());
private void createPOSLayer(Project aProject, TagSet aPosTagset) throws IOException { AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), aProject); AnnotationLayer posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, aProject, true, AnchoringMode.SINGLE_TOKEN); AnnotationFeature tokenPosFeature = new AnnotationFeature(aProject, tokenLayer, "pos", "pos", POS.class.getName()); annotationSchemaService.createFeature(tokenPosFeature); posLayer.setAttachType(tokenLayer); posLayer.setAttachFeature(tokenPosFeature); annotationSchemaService.createLayer(posLayer); annotationSchemaService.createFeature(new AnnotationFeature(aProject, posLayer, "PosValue", "PosValue", CAS.TYPE_NAME_STRING, "Part-of-speech tag", aPosTagset)); }
private List<AnnotationLayer> listMetadataLayers() { return annotationService.listAnnotationLayer(getModelObject()).stream() .filter(layer -> DocumentMetadataLayerSupport.TYPE.equals(layer.getType())). collect(Collectors.toList()); }
private void initLayerAndFeatureCache() { // Initialize and populate the hash maps for the layers and features layers = new HashMap<String, AnnotationLayer>(); layerFeatures = new HashMap<String, List<AnnotationFeature>>(); for (AnnotationLayer layer : annotationSchemaService.listAnnotationLayer(project)) { if (layer.isEnabled()) { layers.put(layer.getName(), layer); List<AnnotationFeature> features = new ArrayList<AnnotationFeature>(); for (AnnotationFeature feature : annotationSchemaService .listAnnotationFeature(layer)) { features.add(feature); } layerFeatures.put(layer.getName(), features); } } }
private void actionDelete(AjaxRequestTarget aTarget) { try { // Load the boiler-plate JCas jCas = jcasProvider.get(); AnnotationBaseFS fs = selectByAddr(jCas, AnnotationBaseFS.class, getModelObject().getId()); AnnotationLayer layer = annotationService.getLayer(project.getObject(), fs); TypeAdapter adapter = annotationService.getAdapter(layer); // Perform actual actions adapter.delete(sourceDocument.getObject(), username.getObject(), jCas, new VID(fs)); // persist changes annotationPage.writeEditorCas(jCas); setModelObject(null); aTarget.add(getParent()); } catch (Exception e) { handleException(DocumentMetadataAnnotationDetailPanel.this, aTarget, e); } }
/** * Copy this same annotation from the user annotation to the mergeview */ private static void copySpanAnnotation(AnnotatorState aState, AnnotationSchemaService aAnnotationService, AnnotationLayer aAnnotationLayer, AnnotationFS aOldFs, JCas aJCas) throws AnnotationException { SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aAnnotationLayer); // Create the annotation - this also takes care of attaching to an annotation if necessary int id = getAddr(adapter.add(aState.getDocument(), aState.getUser().getUsername(), aJCas, aOldFs.getBegin(), aOldFs.getEnd())); List<AnnotationFeature> features = aAnnotationService .listAnnotationFeature(adapter.getLayer()); // Copy the features for (AnnotationFeature feature : features) { Type oldType = adapter.getAnnotationType(aOldFs.getCAS()); Feature oldFeature = oldType.getFeatureByBaseName(feature.getName()); if (isLinkOrBasicFeatures(aOldFs, oldFeature)) { continue; } Object value = adapter.getFeatureValue(feature, aOldFs); adapter.setFeatureValue(aState.getDocument(), aState.getUser().getUsername(), aJCas, id, feature, value); } }
@Override protected List<AnnotationLayer> load() { Project project = ProjectLayersPanel.this.getModelObject(); if (project.getId() != null) { List<AnnotationLayer> _layers = annotationService .listAnnotationLayer(project); AnnotationLayer tokenLayer = annotationService .getLayer(Token.class.getName(), project); _layers.remove(tokenLayer); for (AnnotationLayer layer : _layers) { if (layer.isBuiltIn() && layer.isEnabled()) { colors.put(layer, "green"); } else if (layer.isEnabled()) { colors.put(layer, "blue"); } else { colors.put(layer, "red"); } } return _layers; } return new ArrayList<>(); } })
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; }
private void createNeLayer(Project aProject, TagSet aTagSet) throws IOException { AnnotationLayer neLayer = new AnnotationLayer(NamedEntity.class.getName(), "Named entity", SPAN_TYPE, aProject, true, AnchoringMode.TOKENS); neLayer.setAllowStacking(true); annotationSchemaService.createLayer(neLayer); annotationSchemaService.createFeature(new AnnotationFeature(aProject, neLayer, "value", "value", CAS.TYPE_NAME_STRING, "Named entity type", aTagSet)); }
@Override public void upgradeCorrectionCas(CAS aCas, SourceDocument aDocument) throws UIMAException, IOException { annotationService.upgradeCas(aCas, aDocument, CORRECTION_USER); }
private void fix(Project aProject, Class<? extends TOP> aLayer, String aLayerType, AnnotationLayer aTokenLayer, String aFeature) { if (annotationSchemaService.existsLayer(aLayer.getName(), aLayerType, aProject)) { AnnotationLayer layer = annotationSchemaService.getLayer(aLayer.getName(), aProject); if (layer.getAttachFeature() == null) { layer.setAttachFeature(annotationSchemaService.getFeature(aFeature, aTokenLayer)); log.info("DATABASE UPGRADE PERFORMED: Fixed attach-feature of layer " + "[{}] ({}) in project [{}] ({})", layer.getUiName(), layer.getId(), aProject.getName(), aProject.getId()); } } } }
@Before public void setup() throws Exception { initMocks(this); schemaService = mock(AnnotationSchemaServiceImpl.class); backupProperties = new BackupProperties(); repositoryProperties = new RepositoryProperties(); repositoryProperties.setPath(testFolder.newFolder()); storageService = new CasStorageServiceImpl(null, repositoryProperties, backupProperties); sut = new ImportExportServiceImpl(repositoryProperties, asList(new XmiFormatSupport()), storageService, schemaService); sut.onContextRefreshedEvent(); when(schemaService.listAnnotationLayer(any(Project.class))).thenReturn(emptyList()); // We don't want to re-write the prepareCasForExport method - call the original when(schemaService.prepareCasForExport(any(), any())).thenCallRealMethod(); // The prepareCasForExport method internally calls getFullProjectTypeSystem, so we need to // ensure this is actually callable and doesn't run into a mocked version which simply // returns null. when(schemaService.getFullProjectTypeSystem(any(), anyBoolean())).thenCallRealMethod(); }
private List<Tag> listTags() { if (selectedTagSet.getObject() != null) { return annotationSchemaService.listTags(selectedTagSet.getObject()); } else { return Collections.emptyList(); } } }
AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alState.getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); List<Tag> tagList = annotationService.listTags(feat.getTagset()); List<Tag> reorderedTagList = new ArrayList<>(); if (tagList.size() > 0) {
@Override public void exportData(ProjectExportRequest aRequest, ExportedProject aExProject, File aStage) throws Exception { List<ExportedTagSet> extTagSets = new ArrayList<>(); for (TagSet tagSet : annotationService.listTagSets(aRequest.getProject())) { ExportedTagSet exTagSet = new ExportedTagSet(); exTagSet.setCreateTag(tagSet.isCreateTag()); exTagSet.setDescription(tagSet.getDescription()); exTagSet.setLanguage(tagSet.getLanguage()); exTagSet.setName(tagSet.getName()); List<ExportedTag> exTags = new ArrayList<>(); for (Tag tag : annotationService.listTags(tagSet)) { ExportedTag exTag = new ExportedTag(); exTag.setDescription(tag.getDescription()); exTag.setName(tag.getName()); exTags.add(exTag); } exTagSet.setTags(exTags); extTagSets.add(exTagSet); } aExProject.setTagSets(extTagSets); }