Search in sources :

Example 1 with ANNOTATION

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

the class AnnotationPreferencesDialogContent method loadModel.

private Preferences loadModel(AnnotatorState state) {
    AnnotationPreference prefs = state.getPreferences();
    // Import current settings from the annotator
    Preferences model = new Preferences();
    model.windowSize = Math.max(prefs.getWindowSize(), 1);
    model.sidebarSize = prefs.getSidebarSize();
    model.fontZoom = prefs.getFontZoom();
    model.scrollPage = prefs.isScrollPage();
    model.colorPerLayer = prefs.getColorPerLayer();
    model.readonlyLayerColoringBehaviour = prefs.getReadonlyLayerColoringBehaviour();
    model.rememberLayer = prefs.isRememberLayer();
    model.collapseArcs = prefs.isCollapseArcs();
    AnnotationEditorFactory editorFactory = annotationEditorRegistry.getEditorFactory(state.getPreferences().getEditor());
    if (editorFactory == null) {
        editorFactory = annotationEditorRegistry.getDefaultEditorFactory();
    }
    model.editor = Pair.of(editorFactory.getBeanName(), editorFactory.getDisplayName());
    model.annotationLayers = annotationService.listAnnotationLayer(state.getProject()).stream().filter(layer -> layer.isEnabled()).filter(layer -> !Token.class.getName().equals(layer.getName())).filter(layer -> !(layer.getType().equals(CHAIN_TYPE) && (state.getMode().equals(CORRECTION) || // disable coreference annotation for correction/curation pages
    state.getMode().equals(CURATION)))).collect(Collectors.toList());
    return model;
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType) LoggerFactory(org.slf4j.LoggerFactory) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ANNOTATION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) LambdaBehavior.visibleWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen) Pair(org.apache.commons.lang3.tuple.Pair) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) Label(org.apache.wicket.markup.html.basic.Label) NumberTextField(org.apache.wicket.markup.html.form.NumberTextField) CURATION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.CURATION) Logger(org.slf4j.Logger) ListItem(org.apache.wicket.markup.html.list.ListItem) LambdaAjaxFormComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormComponentUpdatingBehavior) Model(org.apache.wicket.model.Model) UserDao(de.tudarmstadt.ukp.clarin.webanno.security.UserDao) Set(java.util.Set) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) ReadonlyColoringBehaviour(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ReadonlyColoringBehaviour) IOException(java.io.IOException) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) Serializable(java.io.Serializable) CORRECTION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.CORRECTION) Panel(org.apache.wicket.markup.html.panel.Panel) List(java.util.List) AnnotationEditorFactory(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory) PreferencesUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.PreferencesUtil) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) CHAIN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE) AnnotationEditorRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorRegistry) AnnotationEditorFactory(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference)

Example 2 with ANNOTATION

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

the class AnnotationDocumentExporter method exportAnnotationDocumentContents.

private void exportAnnotationDocumentContents(ProjectExportRequest aRequest, ProjectExportTaskMonitor aMonitor, ExportedProject aExProject, File aStage) throws UIMAException, ClassNotFoundException, IOException {
    Project project = aRequest.getProject();
    // The export process may store project-related information in this context to ensure it
    // is looked up only once during the bulk operation and the DB is not hit too often.
    Map<Pair<Project, String>, Object> bulkOperationContext = new HashMap<>();
    List<SourceDocument> documents = documentService.listSourceDocuments(project);
    int i = 1;
    int initProgress = aMonitor.getProgress();
    // Create a map containing the annotation documents for each source document. Doing this
    // as one DB access before the main processing to avoid hammering the DB in the loops
    // below.
    Map<SourceDocument, List<AnnotationDocument>> srcToAnnIdx = documentService.listAnnotationDocuments(project).stream().collect(groupingBy(doc -> doc.getDocument(), toList()));
    // Cache user lookups to avoid constantly hitting the database
    LoadingCache<String, User> usersCache = Caffeine.newBuilder().build(key -> userRepository.get(key));
    for (SourceDocument srcDoc : documents) {
        try (CasStorageSession session = CasStorageSession.openNested()) {
            // If the initial CAS does not exist yet, it must be created before export.
            if (!documentService.existsInitialCas(srcDoc)) {
                documentService.createOrReadInitialCas(srcDoc);
            }
            File targetDir = new File(aStage, ANNOTATION_CAS_FOLDER + srcDoc.getName());
            forceMkdir(targetDir);
            File initialCasFile = documentService.getCasFile(srcDoc, INITIAL_CAS_PSEUDO_USER);
            copyFileToDirectory(initialCasFile, targetDir);
            log.info("Exported annotation document content for user [" + INITIAL_CAS_PSEUDO_USER + "] for source document [" + srcDoc.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
            // 
            // Export per-user annotation document
            // 
            // Determine which format to use for export
            String formatId = FORMAT_AUTO.equals(aRequest.getFormat()) ? srcDoc.getFormat() : aRequest.getFormat();
            FormatSupport format = importExportService.getWritableFormatById(formatId).orElseGet(() -> {
                FormatSupport fallbackFormat = new WebAnnoTsv3FormatSupport();
                aMonitor.addMessage(LogMessage.warn(this, "Annotation: [%s] No writer " + "found for original format [%s] - exporting as [%s] " + "instead.", srcDoc.getName(), formatId, fallbackFormat.getName()));
                return fallbackFormat;
            });
            // Export annotations from regular users
            for (AnnotationDocument annDoc : srcToAnnIdx.computeIfAbsent(srcDoc, key -> emptyList())) {
                // annotation document is not NEW/IGNORE
                if (usersCache.get(annDoc.getUser()) != null && !annDoc.getState().equals(AnnotationDocumentState.NEW) && !annDoc.getState().equals(AnnotationDocumentState.IGNORE)) {
                    File annSerDir = new File(aStage.getAbsolutePath() + ANNOTATION_CAS_FOLDER + srcDoc.getName());
                    File annDocDir = new File(aStage.getAbsolutePath() + ANNOTATION_ORIGINAL_FOLDER + srcDoc.getName());
                    forceMkdir(annSerDir);
                    forceMkdir(annDocDir);
                    File annSerFile = documentService.getCasFile(srcDoc, annDoc.getUser());
                    File annFile = null;
                    if (annSerFile.exists()) {
                        annFile = importExportService.exportAnnotationDocument(srcDoc, annDoc.getUser(), format, annDoc.getUser(), ANNOTATION, false, bulkOperationContext);
                    }
                    if (annSerFile.exists()) {
                        copyFileToDirectory(annSerFile, annSerDir);
                        copyFileToDirectory(annFile, annDocDir);
                        forceDelete(annFile);
                    }
                    log.info("Exported annotation document content for user [" + annDoc.getUser() + "] for source document [" + srcDoc.getId() + "] in project [" + project.getName() + "] with id [" + project.getId() + "]");
                }
            }
            // correction type projects.
            if (PROJECT_TYPE_AUTOMATION.equals(project.getMode()) || PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
                File corrSerFile = documentService.getCasFile(srcDoc, CORRECTION_USER);
                if (corrSerFile.exists()) {
                    // Copy CAS - this is used when importing the project again
                    // Util WebAnno 3.4.x, the CORRECTION_USER CAS was exported to 'curation'
                    // and 'curation_ser'.
                    // Since WebAnno 3.5.x, the CORRECTION_USER CAS is exported to 'annotation'
                    // and 'annotation_ser'.
                    File curationSerDir = new File(aStage + ANNOTATION_AS_SERIALISED_CAS + srcDoc.getName());
                    forceMkdir(curationSerDir);
                    copyFileToDirectory(corrSerFile, curationSerDir);
                    // Copy secondary export format for convenience - not used during import
                    File curationDir = new File(aStage + ANNOTATION_ORIGINAL_FOLDER + srcDoc.getName());
                    forceMkdir(curationDir);
                    File corrFile = importExportService.exportAnnotationDocument(srcDoc, CORRECTION_USER, format, CORRECTION_USER, CORRECTION);
                    copyFileToDirectory(corrFile, curationDir);
                    forceDelete(corrFile);
                }
            }
        }
        aMonitor.setProgress(initProgress + (int) ceil(((double) i) / documents.size() * 80.0));
        i++;
    }
}
Also used : Enumeration(java.util.Enumeration) PROJECT_TYPE_AUTOMATION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_AUTOMATION) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectExportTaskMonitor(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportTaskMonitor) ANNOTATION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION) RepositoryProperties(de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties) FastIOUtils.copy(de.tudarmstadt.ukp.clarin.webanno.support.io.FastIOUtils.copy) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FileUtils.forceMkdir(org.apache.commons.io.FileUtils.forceMkdir) ZipFile(java.util.zip.ZipFile) WebAnnoTsv3FormatSupport(de.tudarmstadt.ukp.clarin.webanno.tsv.WebAnnoTsv3FormatSupport) FORMAT_AUTO(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportRequest.FORMAT_AUTO) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) UIMAException(org.apache.uima.UIMAException) CasStorageSession(de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession) PROJECT_TYPE_CORRECTION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Collections.emptyList(java.util.Collections.emptyList) PROJECT_FOLDER(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.PROJECT_FOLDER) UserDao(de.tudarmstadt.ukp.clarin.webanno.security.UserDao) Set(java.util.Set) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) Math.ceil(java.lang.Math.ceil) AnnotationDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState) FileUtils.copyFileToDirectory(org.apache.commons.io.FileUtils.copyFileToDirectory) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) CORRECTION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.CORRECTION) List(java.util.List) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) Function.identity(java.util.function.Function.identity) FilenameUtils(org.apache.commons.io.FilenameUtils) CORRECTION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER) System.currentTimeMillis(java.lang.System.currentTimeMillis) FormatSupport(de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) FileUtils.forceDelete(org.apache.commons.io.FileUtils.forceDelete) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ProjectExporter(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExporter) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) INITIAL_CAS_PSEUDO_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER) ProjectExportRequest(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectExportRequest) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) Logger(org.slf4j.Logger) Files(java.nio.file.Files) IOException(java.io.IOException) ANNOTATION_FOLDER(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.ANNOTATION_FOLDER) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) ExportedAnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationDocument) DurationFormatUtils(org.apache.commons.lang3.time.DurationFormatUtils) DOCUMENT_FOLDER(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.DOCUMENT_FOLDER) ProjectImportRequest(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest) ImportExportService(de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService) WebAnnoTsv3FormatSupport(de.tudarmstadt.ukp.clarin.webanno.tsv.WebAnnoTsv3FormatSupport) FormatSupport(de.tudarmstadt.ukp.clarin.webanno.api.format.FormatSupport) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) HashMap(java.util.HashMap) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) WebAnnoTsv3FormatSupport(de.tudarmstadt.ukp.clarin.webanno.tsv.WebAnnoTsv3FormatSupport) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) ExportedAnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedAnnotationDocument) ExportedProject(de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) CasStorageSession(de.tudarmstadt.ukp.clarin.webanno.api.dao.casstorage.CasStorageSession) ZipFile(java.util.zip.ZipFile) File(java.io.File) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ANNOTATION (de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION)2 CORRECTION (de.tudarmstadt.ukp.clarin.webanno.model.Mode.CORRECTION)2 UserDao (de.tudarmstadt.ukp.clarin.webanno.security.UserDao)2 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 BootstrapSelect (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect)1 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)1 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)1 ImportExportService (de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService)1 ProjectService (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService)1 ANNOTATION_FOLDER (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.ANNOTATION_FOLDER)1 DOCUMENT_FOLDER (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService.DOCUMENT_FOLDER)1