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();
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations