use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class CSVExportGroupedStreamSource method getStream.
@Override
public InputStream getStream() {
final QueryResult queryResult = queryResultSupplier.get();
final Set<String> documentIds = new TreeSet<String>();
final Multimap<String, String> collectionIdByDocumentId = ArrayListMultimap.create();
final Table<String, String, Integer> groupings = HashBasedTable.create();
for (QueryResultRow row : queryResult) {
String group = row.getPhrase();
if (groupByTagSupplier.get()) {
if (row instanceof TagQueryResultRow) {
group = ((TagQueryResultRow) row).getTagDefinitionPath();
} else {
group = TagQueryResultRowItem.getNoTagAvailableKey();
}
}
groupings.put(group, "Total", getValue(groupings, group, "Total") + 1);
groupings.put(group, row.getSourceDocumentId(), getValue(groupings, group, row.getSourceDocumentId()) + 1);
documentIds.add(row.getSourceDocumentId());
if (row instanceof TagQueryResultRow) {
collectionIdByDocumentId.put(row.getSourceDocumentId(), ((TagQueryResultRow) row).getMarkupCollectionId());
groupings.put(group, ((TagQueryResultRow) row).getMarkupCollectionId(), getValue(groupings, group, ((TagQueryResultRow) row).getMarkupCollectionId()) + 1);
}
}
final PipedInputStream in = new PipedInputStream();
final UI ui = UI.getCurrent();
backgroundServiceProvider.submit("csv-export", new DefaultProgressCallable<Void>() {
@Override
public Void call() throws Exception {
PipedOutputStream out = new PipedOutputStream(in);
OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
ArrayList<String> header = new ArrayList<>();
header.add("Group");
header.add("Total");
for (String documentId : documentIds) {
KwicProvider kwicProvider = kwicProviderCache.get(documentId);
header.add(kwicProvider.getSourceDocumentName() + " (" + documentId + ")");
for (String collectionId : new TreeSet<String>(collectionIdByDocumentId.get(documentId))) {
header.add(kwicProvider.getSourceDocument().getUserMarkupCollectionReference(collectionId).toString() + " (" + collectionId + ")");
}
}
try (CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL.withDelimiter(';').withHeader(header.toArray(new String[] {})))) {
for (String group : new TreeSet<String>(groupings.rowKeySet())) {
csvPrinter.print(group);
csvPrinter.print(groupings.get(group, "Total"));
for (String documentId : documentIds) {
csvPrinter.print(groupings.get(group, documentId));
for (String collectionId : new TreeSet<String>(collectionIdByDocumentId.get(documentId))) {
csvPrinter.print(groupings.get(group, collectionId));
}
}
csvPrinter.println();
}
csvPrinter.flush();
}
// intended
return null;
}
}, new ExecutionListener<Void>() {
@Override
public void done(Void result) {
// noop
}
@Override
public void error(Throwable t) {
((ErrorHandler) ui).showAndLogError("Error export data to CSV!", t);
}
});
// waiting on the background thread to send data to the pipe
int tries = 100;
try {
while (!(in.available() > 0) && tries > 0) {
Thread.sleep(10);
tries--;
}
} catch (IOException | InterruptedException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error while waiting on CSV export!", e);
}
return in;
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class CollectionQueryResultRowItem method addChildRowItems.
@Override
public void addChildRowItems(TreeData<QueryResultRowItem> treeData, LoadingCache<String, KwicProvider> kwicProviderCache) {
try {
for (QueryResultRow row : getRows()) {
if (row instanceof TagQueryResultRow) {
TagQueryResultRow tRow = (TagQueryResultRow) row;
KwicProvider kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
TagDefinition tagDefinition = project.getTagManager().getTagLibrary().getTagDefinition(tRow.getTagDefinitionId());
KwicQueryResultRowItem item = new KwicQueryResultRowItem(tRow, AnnotatedTextProvider.buildAnnotatedText(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition), AnnotatedTextProvider.buildAnnotatedKeywordInContext(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition, tRow.getTagDefinitionPath()), true);
if (!treeData.contains(item)) {
treeData.addItem(this, item);
}
}
}
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error displaying annotated kwic query results", e);
}
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class ConflictedProjectView method showNextAnnotationConflict.
private void showNextAnnotationConflict() throws IOException {
if (annotationConflictIterator.hasNext()) {
SourceDocument document = documents.stream().filter(doc -> doc.getUuid().equals(currentCollectionConflict.getDocumentId())).findFirst().get();
KwicProvider kwicProvider = new KwicProvider(document);
AnnotationConflict annotationConflict = annotationConflictIterator.next();
AnnotationConflictView annotationConflictView = new AnnotationConflictView(annotationConflict, currentCollectionConflict, tagManager, kwicProvider, () -> showNextConflict());
mainPanel.removeAllComponents();
mainPanel.addComponent(annotationConflictView);
} else {
showNextConflict();
}
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class AnnotationDetailsPanel method setDocument.
public void setDocument(SourceDocument document) throws IOException {
this.kwicProvider = new KwicProvider(document);
handleClearSelected();
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class QueryResultPanel method addFlatTagBasedRootItems.
void addFlatTagBasedRootItems(QueryResult result) {
try {
for (QueryResultRow row : result) {
if (row instanceof TagQueryResultRow) {
if (((TagQueryResultRow) row).getPropertyDefinitionId() != null) {
resultContainsProperties = true;
}
TagQueryResultRow tRow = (TagQueryResultRow) row;
KwicProvider kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
TagDefinition tagDefinition = project.getTagManager().getTagLibrary().getTagDefinition(tRow.getTagDefinitionId());
KwicQueryResultRowItem item = new KwicQueryResultRowItem(tRow, AnnotatedTextProvider.buildAnnotatedText(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition), AnnotatedTextProvider.buildAnnotatedKeywordInContext(new ArrayList<>(tRow.getRanges()), kwicProvider, tagDefinition, tRow.getTagDefinitionPath()), kwicProvider.getSourceDocumentName(), kwicProvider.getSourceDocument().getUserMarkupCollectionReference(tRow.getMarkupCollectionId()).getName(), true);
if (!flatTagBasedTreeData.contains(item)) {
flatTagBasedTreeData.addItem(null, item);
}
}
}
tokenCount = flatTagBasedTreeData.getRootItems().size();
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error adding query result", e);
}
}
Aggregations