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