Search in sources :

Example 26 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class AnalyzeResourcePanel method handleDocumentChanged.

@SuppressWarnings("unchecked")
@Subscribe
public void handleDocumentChanged(DocumentChangeEvent documentChangeEvent) {
    if (documentChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
        SourceDocument document = documentChangeEvent.getDocument();
        documentData.addItem(null, new DocumentDataItem(document));
    } else if (documentChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
        Optional<DocumentTreeItem> optionalDocItem = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(documentChangeEvent.getDocument())).findAny();
        if (optionalDocItem.isPresent()) {
            DocumentTreeItem docItem = optionalDocItem.get();
            List<DocumentTreeItem> children = documentData.getChildren(docItem);
            documentData.removeItem(docItem);
            Set<DocumentTreeItem> updated = new HashSet<>(children);
            updated.add(docItem);
            // selections needs manual update...
            ((SelectionModel.Multi<DocumentTreeItem>) documentTree.getSelectionModel()).updateSelection(Collections.emptySet(), updated);
            corpusChangedListener.corpusChanged();
        }
    } else {
        documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(documentChangeEvent.getDocument())).findAny().ifPresent(item -> documentTree.getDataProvider().refreshItem(item));
        corpusChangedListener.corpusChanged();
    }
}
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) HashSet(java.util.HashSet) Set(java.util.Set) Optional(java.util.Optional) SourceDocument(de.catma.document.source.SourceDocument) SelectionModel(com.vaadin.data.SelectionModel) List(java.util.List) Subscribe(com.google.common.eventbus.Subscribe)

Example 27 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class CollectionSelectionStep method handleAddCollectionRequest.

private void handleAddCollectionRequest() {
    try {
        if (!project.hasPermission(project.getRoleOnProject(), RBACPermission.COLLECTION_CREATE)) {
            Notification.show("Info", "You do not have the permission to create Collections, please contact a Project maintainer!", Type.HUMANIZED_MESSAGE);
            return;
        }
        @SuppressWarnings("unchecked") TreeDataProvider<Resource> resourceDataProvider = (TreeDataProvider<Resource>) documentGrid.getDataProvider();
        Set<Resource> selectedResources = documentGrid.getSelectedItems();
        Set<SourceDocument> selectedDocuments = new HashSet<>();
        for (Resource resource : selectedResources) {
            Resource root = resourceDataProvider.getTreeData().getParent(resource);
            if (root == null) {
                root = resource;
            }
            DocumentResource documentResource = (DocumentResource) root;
            selectedDocuments.add(documentResource.getDocument());
        }
        if (!selectedDocuments.isEmpty()) {
            SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Add Annotation Collection(s)", "Please enter the Collection name:", new SaveCancelListener<String>() {

                @Override
                public void savePressed(String result) {
                    for (SourceDocument document : selectedDocuments) {
                        project.createUserMarkupCollection(result, document);
                    }
                }
            });
            collectionNameDlg.show();
        } else {
            Notification.show("Info", "Please select one or more Documents first!", Type.HUMANIZED_MESSAGE);
        }
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error adding a Collection", e);
    }
}
Also used : Resource(de.catma.ui.module.project.Resource) CollectionResource(de.catma.ui.module.project.CollectionResource) DocumentResource(de.catma.ui.module.project.DocumentResource) SourceDocument(de.catma.document.source.SourceDocument) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) DocumentResource(de.catma.ui.module.project.DocumentResource) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) HashSet(java.util.HashSet)

Example 28 with SourceDocument

use of de.catma.document.source.SourceDocument 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 29 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class RegQuery method execute.

@Override
protected QueryResult execute() throws Exception {
    QueryResultRowArray result = new QueryResultRowArray();
    QueryOptions queryOptions = getQueryOptions();
    Project repository = queryOptions.getRepository();
    List<String> relevantSourceDocIDs = queryOptions.getRelevantSourceDocumentIDs();
    Collection<SourceDocument> relevantSourceDocuments = null;
    if ((relevantSourceDocIDs != null) && !relevantSourceDocIDs.isEmpty()) {
        relevantSourceDocuments = new ArrayList<SourceDocument>();
        for (String sourceDocumentID : relevantSourceDocIDs) {
            relevantSourceDocuments.add(repository.getSourceDocument(sourceDocumentID));
        }
    } else {
        relevantSourceDocuments = repository.getSourceDocuments();
    }
    for (SourceDocument sourceDoc : relevantSourceDocuments) {
        boolean sourceDocWasLoaded = sourceDoc.isLoaded();
        int flags = Pattern.DOTALL;
        if (caseInsensitive) {
            flags |= Pattern.CASE_INSENSITIVE;
        }
        Pattern pattern = Pattern.compile(phrase.getPhrase(), flags);
        Matcher matcher = pattern.matcher(sourceDoc.getContent());
        while (matcher.find()) {
            result.add(new QueryResultRow(queryOptions.getQueryId(), sourceDoc.getUuid(), new Range(matcher.start(), matcher.end()), matcher.group()));
        }
        if (!sourceDocWasLoaded) {
            sourceDoc.unload();
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) QueryResultRow(de.catma.queryengine.result.QueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) Range(de.catma.document.Range) Project(de.catma.project.Project) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Example 30 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class TagQuery 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()) {
        return new QueryResultRowArray();
    }
    QueryResult result = indexer.searchTagDefinitionPath(queryOptions.getQueryId(), relevantUserMarkupCollIDs, 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 : Project(de.catma.project.Project) QueryResult(de.catma.queryengine.result.QueryResult) Indexer(de.catma.indexer.Indexer) QueryResultRow(de.catma.queryengine.result.QueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray) Range(de.catma.document.Range)

Aggregations

SourceDocument (de.catma.document.source.SourceDocument)48 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)23 Project (de.catma.project.Project)17 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)15 List (java.util.List)15 TagsetDefinition (de.catma.tag.TagsetDefinition)13 IOException (java.io.IOException)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 IDGenerator (de.catma.util.IDGenerator)12 HashSet (java.util.HashSet)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 EventBus (com.google.common.eventbus.EventBus)10 Subscribe (com.google.common.eventbus.Subscribe)10 CollectionChangeEvent (de.catma.project.event.CollectionChangeEvent)10 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)9 ChangeType (de.catma.project.event.ChangeType)9 RBACPermission (de.catma.rbac.RBACPermission)9 Pair (de.catma.util.Pair)9 Indexer (de.catma.indexer.Indexer)8