Search in sources :

Example 21 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class PropertyQuery method execute.

@Override
protected QueryResult execute() throws Exception {
    QueryOptions queryOptions = getQueryOptions();
    Project repository = queryOptions.getRepository();
    Indexer indexer = queryOptions.getIndexer();
    List<String> relevantUserMarkupCollIDs = queryOptions.getRelevantUserMarkupCollIDs();
    if (relevantUserMarkupCollIDs.isEmpty() && !queryOptions.getRelevantSourceDocumentIDs().isEmpty()) {
        relevantUserMarkupCollIDs = new ArrayList<String>();
        for (String sourceDocumentId : queryOptions.getRelevantSourceDocumentIDs()) {
            for (AnnotationCollectionReference umcRef : repository.getSourceDocument(sourceDocumentId).getUserMarkupCollectionRefs()) {
                relevantUserMarkupCollIDs.add(umcRef.getId());
            }
        }
        if (relevantUserMarkupCollIDs.isEmpty()) {
            return new QueryResultRowArray();
        }
    }
    QueryResult result = indexer.searchProperty(queryOptions.getQueryId(), relevantUserMarkupCollIDs, propertyName, propertyValue, tagPhrase);
    for (QueryResultRow row : result) {
        SourceDocument sd = repository.getSourceDocument(row.getSourceDocumentId());
        TagQueryResultRow tRow = (TagQueryResultRow) row;
        if (tRow.getRanges().size() > 1) {
            StringBuilder builder = new StringBuilder();
            String conc = "";
            for (Range range : tRow.getRanges()) {
                builder.append(conc);
                builder.append(sd.getContent(range));
                conc = "[...]";
            }
            row.setPhrase(builder.toString());
        } else {
            row.setPhrase(sd.getContent(row.getRange()));
        }
    }
    return result;
}
Also used : QueryResultRow(de.catma.queryengine.result.QueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Range(de.catma.document.Range) Project(de.catma.project.Project) QueryResult(de.catma.queryengine.result.QueryResult) Indexer(de.catma.indexer.Indexer) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Example 22 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class KwicPanel method annotateSelection.

@SuppressWarnings("unchecked")
private void annotateSelection(Set<QueryResultRow> selectedRows, WizardContext result) throws Exception {
    List<Property> properties = (List<Property>) result.get(AnnotationWizardContextKey.PROPERTIES);
    Map<String, AnnotationCollectionReference> collectionRefsByDocId = (Map<String, AnnotationCollectionReference>) result.get(AnnotationWizardContextKey.COLLECTIONREFS_BY_DOCID);
    TagDefinition tag = (TagDefinition) result.get(AnnotationWizardContextKey.TAG);
    AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
    for (AnnotationCollectionReference ref : collectionRefsByDocId.values()) {
        collectionManager.add(project.getUserMarkupCollection(ref));
    }
    for (QueryResultRow row : selectedRows) {
        AnnotationCollectionReference collectionRef = collectionRefsByDocId.get(row.getSourceDocumentId());
        TagInstance tagInstance = new TagInstance(idGenerator.generate(), tag.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tag.getUserDefinedPropertyDefinitions(), tag.getTagsetDefinitionUuid());
        List<TagReference> tagReferences = new ArrayList<TagReference>();
        for (Property protoProp : properties) {
            tagInstance.getUserDefinedPropetyByUuid(protoProp.getPropertyDefinitionId()).setPropertyValueList(protoProp.getPropertyValueList());
        }
        Set<Range> ranges = row.getRanges();
        for (Range range : ranges) {
            TagReference tagReference = new TagReference(tagInstance, row.getSourceDocumentId(), range, collectionRef.getId());
            tagReferences.add(tagReference);
        }
        collectionManager.addTagReferences(tagReferences, collectionRef.getId());
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) ArrayList(java.util.ArrayList) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Range(de.catma.document.Range) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) TagInstance(de.catma.tag.TagInstance) List(java.util.List) ArrayList(java.util.ArrayList) TagReference(de.catma.document.annotation.TagReference) Property(de.catma.tag.Property) Map(java.util.Map)

Example 23 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class KwicPanel method handleRemoveAnnotationsRequest.

private void handleRemoveAnnotationsRequest(EventBus eventBus) {
    final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
    if (selectedRows.isEmpty()) {
        Notification.show("Info", "Please select one or more Annotation rows!", Type.HUMANIZED_MESSAGE);
        return;
    }
    int annotationRows = 0;
    List<AnnotationCollectionReference> annotationCollectionReferences = new ArrayList<>();
    boolean resourcesMissing = false;
    boolean permissionsMissing = false;
    Set<String> tagInstanceIdsToBeRemoved = new HashSet<String>();
    Set<QueryResultRow> rowsToBeRemoved = new HashSet<>();
    try {
        LoadingCache<String, Boolean> collectionIdToHasWritePermission = CacheBuilder.newBuilder().build(new CacheLoader<String, Boolean>() {

            @Override
            public Boolean load(String collectionId) throws Exception {
                return project.hasPermission(project.getRoleForCollection(collectionId), RBACPermission.COLLECTION_WRITE);
            }
        });
        for (QueryResultRow row : selectedRows) {
            if (row instanceof TagQueryResultRow) {
                annotationRows++;
                if (project.hasDocument(row.getSourceDocumentId())) {
                    SourceDocument document = project.getSourceDocument(row.getSourceDocumentId());
                    AnnotationCollectionReference collRef = document.getUserMarkupCollectionReference(((TagQueryResultRow) row).getMarkupCollectionId());
                    if (collRef != null) {
                        if (collectionIdToHasWritePermission.get(collRef.getId())) {
                            annotationCollectionReferences.add(collRef);
                            tagInstanceIdsToBeRemoved.add(((TagQueryResultRow) row).getTagInstanceId());
                            rowsToBeRemoved.add(row);
                        } else {
                            permissionsMissing = true;
                        }
                    } else {
                        resourcesMissing = true;
                    }
                } else {
                    resourcesMissing = true;
                }
            }
        }
        if (permissionsMissing) {
            Notification.show("Info", "You do not have the write permission for one or more Collections referenced by your selection. Those Collections will be ignored!", Type.HUMANIZED_MESSAGE);
        }
        if (annotationRows == 0) {
            Notification.show("Info", "Your selection does not contain any Annotations! Please select Annotations only!", Type.HUMANIZED_MESSAGE);
            return;
        }
        if (annotationCollectionReferences.isEmpty()) {
            Notification.show("Info", "The Documents and/or Collections referenced by your selection are no longer part of the Project!", Type.HUMANIZED_MESSAGE);
            return;
        }
        if (resourcesMissing) {
            Notification.show("Info", "Some of the Documents and/or Collections referenced by your selection " + "are no longer part of the Project and will be ignored, " + "see columns 'Document' and 'Collection' for details!", Type.HUMANIZED_MESSAGE);
        }
        if (annotationRows != selectedRows.size()) {
            Notification.show("Info", "Some rows of your selection do not represent Annotations and will be ignored, see column 'Tag' for details!", Type.HUMANIZED_MESSAGE);
        }
        AnnotationCollectionManager collectionManager = new AnnotationCollectionManager(project);
        for (AnnotationCollectionReference ref : annotationCollectionReferences) {
            collectionManager.add(project.getUserMarkupCollection(ref));
        }
        collectionManager.removeTagInstance(tagInstanceIdsToBeRemoved, true);
        kwicDataProvider.getItems().removeAll(rowsToBeRemoved);
        kwicDataProvider.refreshAll();
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error deleting Annotations!", e);
    }
}
Also used : TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) ArrayList(java.util.ArrayList) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) HashSet(java.util.HashSet)

Example 24 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class AnalyzeResourcePanel method initData.

private void initData() {
    documentData = new TreeData<>();
    try {
        Collection<SourceDocument> documents = project.getSourceDocuments();
        documentData.addRootItems(documents.stream().map(document -> new DocumentDataItem(document)));
        for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
            for (AnnotationCollectionReference umcRef : ((DocumentDataItem) documentDataItem).getDocument().getUserMarkupCollectionRefs()) {
                documentData.addItem(documentDataItem, new CollectionDataItem(umcRef, project.hasPermission(project.getRoleForCollection(umcRef.getId()), RBACPermission.COLLECTION_WRITE)));
            }
        }
        documentTree.setDataProvider(new TreeDataProvider<>(documentData));
        Collection<SourceDocument> selectedDocuments = corpus.getSourceDocuments();
        Collection<AnnotationCollectionReference> selectedCollections = corpus.getUserMarkupCollectionRefs();
        documentData.getRootItems().stream().filter(documentItem -> selectedDocuments.contains(((DocumentDataItem) documentItem).getDocument())).forEach(documentTree::select);
        for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
            List<DocumentTreeItem> collectionItems = documentData.getChildren(documentDataItem);
            for (DocumentTreeItem oneCollection : collectionItems) {
                if (selectedCollections.contains(((CollectionDataItem) oneCollection).getCollectionRef())) {
                    documentTree.getSelectionModel().select(oneCollection);
                }
            }
        }
        documentTree.expand(documentData.getRootItems());
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error loading Project data", e);
    }
}
Also used : SelectionListener(com.vaadin.event.selection.SelectionListener) VerticalLayout(com.vaadin.ui.VerticalLayout) SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Notification(com.vaadin.ui.Notification) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Label(com.vaadin.ui.Label) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) TreeGridFactory(de.catma.ui.component.TreeGridFactory) Subscribe(com.google.common.eventbus.Subscribe) SelectionModel(com.vaadin.data.SelectionModel) TreeData(com.vaadin.data.TreeData) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) ItemClick(com.vaadin.ui.Grid.ItemClick) List(java.util.List) Type(com.vaadin.ui.Notification.Type) ChangeType(de.catma.project.event.ChangeType) Corpus(de.catma.document.corpus.Corpus) Optional(java.util.Optional) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) Collections(java.util.Collections) RBACPermission(de.catma.rbac.RBACPermission) Grid(com.vaadin.ui.Grid) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Example 25 with AnnotationCollectionReference

use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.

the class CollectionSelectionStep method getCollectionRefsByDocumentId.

private Map<String, AnnotationCollectionReference> getCollectionRefsByDocumentId() {
    Set<Resource> selectedItems = documentGrid.getSelectedItems();
    Map<String, AnnotationCollectionReference> collectionsByDocumentId = new HashMap<>();
    for (Resource resource : selectedItems) {
        if (resource instanceof CollectionResource) {
            collectionsByDocumentId.put(((CollectionResource) resource).getCollectionReference().getSourceDocumentId(), ((CollectionResource) resource).getCollectionReference());
        }
    }
    return collectionsByDocumentId;
}
Also used : CollectionResource(de.catma.ui.module.project.CollectionResource) HashMap(java.util.HashMap) Resource(de.catma.ui.module.project.Resource) CollectionResource(de.catma.ui.module.project.CollectionResource) DocumentResource(de.catma.ui.module.project.DocumentResource) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference)

Aggregations

AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)34 SourceDocument (de.catma.document.source.SourceDocument)23 List (java.util.List)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)12 HashSet (java.util.HashSet)12 IDGenerator (de.catma.util.IDGenerator)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Collection (java.util.Collection)11 Set (java.util.Set)11 EventBus (com.google.common.eventbus.EventBus)10 Project (de.catma.project.Project)10 ChangeType (de.catma.project.event.ChangeType)10 RBACPermission (de.catma.rbac.RBACPermission)10 TagsetDefinition (de.catma.tag.TagsetDefinition)10 Subscribe (com.google.common.eventbus.Subscribe)9 TagReference (de.catma.document.annotation.TagReference)9