Search in sources :

Example 16 with AnnotationCollectionReference

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

the class TagDiffQuery 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.searchTagDiff(queryOptions.getQueryId(), relevantUserMarkupCollIDs, propertyName, 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 17 with AnnotationCollectionReference

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

the class TaggerView method initActions.

private void initActions() {
    btClearSearchHighlights.addClickListener(new ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            tagger.removeHighlights();
        }
    });
    cbTraceSelection.addClickListener(clickEvent -> {
        boolean traceSelection = (boolean) cbTraceSelection.getData();
        traceSelection = !traceSelection;
        cbTraceSelection.setData(traceSelection);
        tagger.setTraceSelection(traceSelection);
        if (traceSelection) {
            cbTraceSelection.addStyleName("tagger-trace-checkbox-selected");
        } else {
            cbTraceSelection.removeStyleName("tagger-trace-checkbox-selected");
        }
    });
    cbAutoShowComments.addClickListener(clickEvent -> {
        boolean autoShowComments = (boolean) cbAutoShowComments.getData();
        autoShowComments = !autoShowComments;
        cbAutoShowComments.setData(autoShowComments);
        if (autoShowComments) {
            cbAutoShowComments.setIcon(VaadinIcons.COMMENT);
            try {
                TaggerView.this.comments.clear();
                TaggerView.this.comments.addAll(TaggerView.this.project.getComments(sourceDocument.getUuid()));
                tagger.updateComments(comments);
            } catch (IOException e) {
                logger.log(Level.SEVERE, "unable to reload comments", e);
            }
        } else {
            cbAutoShowComments.setIcon(VaadinIcons.COMMENT_O);
        }
    });
    btAnalyze.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {
            analyzeDocument();
        }
    });
    linesPerPageSlider.addValueChangeListener(new ValueChangeListener<Double>() {

        public void valueChange(ValueChangeEvent<Double> event) {
            Double perCentValue = (Double) linesPerPageSlider.getValue();
            int lines = (int) ((totalLineCount / 100.0) * perCentValue);
            List<ClientTagInstance> absoluteTagInstances = pager.getAbsoluteTagInstances();
            Page currentPage = null;
            if (pager.hasPages()) {
                currentPage = pager.getCurrentPage();
            }
            pager.setMaxPageLengthInLines(lines);
            if (pager.hasPages()) {
                // recalculate pages
                try {
                    pager.setText(sourceDocument.getContent(), comments);
                    int previousPageNumber = pager.getPageNumberFor(currentPage.getPageStart());
                    tagger.setPage(previousPageNumber);
                    tagger.setTagInstancesVisible(absoluteTagInstances, true);
                    pagerComponent.setPage(previousPageNumber);
                } catch (IOException e) {
                    errorHandler.showAndLogError("Error showing the Document!", e);
                }
            }
        }
    });
    resourcePanel.setSelectionListener(new ResourceSelectionListener() {

        @Override
        public void resourcesChanged() {
            AnnotationCollection selectedEditableCollection = annotationPanel.getSelectedEditableCollection();
            List<AnnotationCollectionReference> selectedAnnotationCollectionRefs = resourcePanel.getSelectedAnnotationCollectionReferences();
            for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                userMarkupCollectionManager.remove(collection.getId());
                annotationPanel.removeCollection(collection.getId());
                tagger.setVisible(collection.getTagReferences(), false);
            }
            userMarkupCollectionManager.clear();
            for (AnnotationCollectionReference collectionReference : selectedAnnotationCollectionRefs) {
                try {
                    AnnotationCollection collection = project.getUserMarkupCollection(collectionReference);
                    setAnnotationCollectionSelected(new AnnotationCollectionReference(collection), true);
                } catch (IOException e) {
                    ((ErrorHandler) UI.getCurrent()).showAndLogError("error refreshing Annotation Collection!", e);
                }
            }
            if ((selectedEditableCollection != null) && (userMarkupCollectionManager.contains(selectedEditableCollection.getId()))) {
                annotationPanel.setSelectedEditableCollection(userMarkupCollectionManager.getUserMarkupCollection(selectedEditableCollection.getId()));
            }
            annotationPanel.clearTagsets();
            tagsetsSelected(resourcePanel.getSelectedTagsets());
        }

        @Override
        public void documentSelected(SourceDocument sourceDocument) {
            setSourceDocument(sourceDocument, null);
        }

        @Override
        public void annotationCollectionSelected(AnnotationCollectionReference collectionReference, boolean selected) {
            setAnnotationCollectionSelected(collectionReference, selected);
        }

        @Override
        public void tagsetsSelected(Collection<TagsetDefinition> tagsets) {
            try {
                annotationPanel.setTagsets(tagsets);
                if (taggerContextMenu != null) {
                    taggerContextMenu.setTagsets(tagsets);
                }
                for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                    tagger.setVisible(collection.getTagReferences(), false);
                    List<TagReference> visibleRefs = annotationPanel.getVisibleTagReferences(collection.getTagReferences());
                    if (!visibleRefs.isEmpty()) {
                        tagger.setVisible(visibleRefs, true);
                    }
                }
            } catch (Exception e) {
                errorHandler.showAndLogError("Error handling Tagset!", e);
            }
        }
    });
    annotationPanel.setTagReferenceSelectionChangeListener((tagReferences, selected) -> {
        if (!tagReferences.isEmpty()) {
            tagger.setVisible(tagReferences, selected);
        }
    });
    kwicPanel.setExpansionListener(new ExpansionListener() {

        @Override
        public void expand() {
            // we hide on expand and on compress since both is considered a "close"
            hideKwicPanel();
        }

        @Override
        public void compress() {
            // we hide on expand and on compress since both is considered a "close"
            hideKwicPanel();
        }
    });
    kwicPanel.addItemClickListener(itemClick -> {
        if (itemClick.getMouseEventDetails().isDoubleClick()) {
            show(itemClick.getItem().getRange());
        }
    });
}
Also used : ErrorHandler(de.catma.ui.module.main.ErrorHandler) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ClickEvent(com.vaadin.ui.Button.ClickEvent) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Page(de.catma.ui.module.annotate.pager.Page) IOException(java.io.IOException) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TagsetDefinition(de.catma.tag.TagsetDefinition) ResourceSelectionListener(de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener) ArrayList(java.util.ArrayList) List(java.util.List) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) ClickListener(com.vaadin.ui.Button.ClickListener)

Example 18 with AnnotationCollectionReference

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

the class TaggerView method analyzeDocument.

public void analyzeDocument() {
    Corpus corpus = new Corpus();
    corpus.addSourceDocument(sourceDocument);
    for (AnnotationCollection umc : userMarkupCollectionManager.getUserMarkupCollections()) {
        AnnotationCollectionReference userMarkupCollRef = sourceDocument.getUserMarkupCollectionReference(umc.getId());
        if (userMarkupCollRef != null) {
            corpus.addUserMarkupCollectionReference(userMarkupCollRef);
        }
    }
    if (project instanceof IndexedProject) {
        eventBus.post(new RouteToAnalyzeEvent((IndexedProject) project, corpus));
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) IndexedProject(de.catma.indexer.IndexedProject) Corpus(de.catma.document.corpus.Corpus) RouteToAnalyzeEvent(de.catma.ui.events.routing.RouteToAnalyzeEvent)

Example 19 with AnnotationCollectionReference

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

the class TaggerView method initData.

private void initData(final AfterDocumentLoadedOperation afterDocumentLoadedOperation) {
    if (sourceDocument != null) {
        // loading of the Document is done in an extra step,
        // because of a client side rendering racing condition which prevents the first page to be displayed
        final UI ui = UI.getCurrent();
        ((CatmaApplication) ui).submit("Load Document", new DefaultProgressCallable<Void>() {

            @Override
            public Void call() throws Exception {
                ui.accessSynchronously(() -> {
                    try {
                        linesPerPageSlider.setEnabled(true);
                        btAnalyze.setEnabled(project instanceof IndexedProject);
                        pagerComponent.setEnabled(true);
                        TaggerView.this.comments.clear();
                        TaggerView.this.comments.addAll(TaggerView.this.project.getComments(sourceDocument.getUuid()));
                        tagger.setText(sourceDocument.getContent(), TaggerView.this.comments);
                        totalLineCount = pager.getTotalLineCount();
                        try {
                            linesPerPageSlider.setValue((100.0 / totalLineCount) * maxPageLengthInLines);
                        } catch (ValueOutOfBoundsException toBeIgnored) {
                        }
                        List<AnnotationCollectionReference> collectionReferences = resourcePanel.getSelectedAnnotationCollectionReferences();
                        userMarkupCollectionManager.clear();
                        for (AnnotationCollectionReference collectionRef : collectionReferences) {
                            AnnotationCollection collection = project.getUserMarkupCollection(collectionRef);
                            userMarkupCollectionManager.add(collection);
                        }
                        Collection<TagsetDefinition> tagsets = new HashSet<>(resourcePanel.getSelectedTagsets());
                        annotationPanel.setData(sourceDocument, tagsets, new ArrayList<>(userMarkupCollectionManager.getUserMarkupCollections()));
                        if (taggerContextMenu != null) {
                            taggerContextMenu.setTagsets(tagsets);
                        }
                        if (afterDocumentLoadedOperation != null) {
                            afterDocumentLoadedOperation.afterDocumentLoaded(TaggerView.this);
                        }
                        ui.push();
                    } catch (IOException e) {
                        errorHandler.showAndLogError("Error showing the Document!", e);
                    }
                });
                return null;
            }
        }, new ExecutionListener<Void>() {

            @Override
            public void done(Void result) {
            /*noop*/
            }

            @Override
            public void error(Throwable t) {
                errorHandler.showAndLogError("Error showing the Document!", t);
            }
        });
    } else {
        linesPerPageSlider.setEnabled(false);
        btAnalyze.setEnabled(false);
        pagerComponent.setEnabled(false);
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ArrayList(java.util.ArrayList) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) IOException(java.io.IOException) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CatmaApplication(de.catma.ui.CatmaApplication) UI(com.vaadin.ui.UI) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) IndexedProject(de.catma.indexer.IndexedProject)

Example 20 with AnnotationCollectionReference

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

the class KwicItemHandler method getCollectionName.

public String getCollectionName(QueryResultRow row) {
    if (row instanceof TagQueryResultRow) {
        try {
            String documentId = row.getSourceDocumentId();
            String collectionId = ((TagQueryResultRow) row).getMarkupCollectionId();
            AnnotationCollectionReference colRef = kwicProviderCache.get(documentId).getSourceDocument().getUserMarkupCollectionReference(collectionId);
            String collectionName = colRef.getName();
            return collectionName;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "error retrieving Collection name for " + row, e);
            return "N/A";
        }
    }
    return null;
}
Also used : TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) ExecutionException(java.util.concurrent.ExecutionException)

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