use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class QueryResultPanel method addPropertiesAsColumnsTagBasedRootItems.
void addPropertiesAsColumnsTagBasedRootItems(QueryResult result) {
try {
HashMap<String, QueryResultRowArray> rowsGroupedByTagInstance = new HashMap<String, QueryResultRowArray>();
for (QueryResultRow row : result) {
if (row instanceof TagQueryResultRow) {
TagQueryResultRow tRow = (TagQueryResultRow) row;
QueryResultRowArray rows = rowsGroupedByTagInstance.get(tRow.getTagInstanceId());
if (rows == null) {
rows = new QueryResultRowArray();
rowsGroupedByTagInstance.put(tRow.getTagInstanceId(), rows);
}
rows.add(tRow);
if (tRow.getPropertyName() != null) {
propertyNames.add(tRow.getPropertyName());
}
}
}
for (Map.Entry<String, QueryResultRowArray> entry : rowsGroupedByTagInstance.entrySet()) {
QueryResultRowArray rows = entry.getValue();
TagQueryResultRow masterRow = (TagQueryResultRow) rows.get(0);
KwicProvider kwicProvider = kwicProviderCache.get(masterRow.getSourceDocumentId());
TagDefinition tagDefinition = project.getTagManager().getTagLibrary().getTagDefinition(masterRow.getTagDefinitionId());
KwicPropertiesAsColumnsQueryResultRowItem item = new KwicPropertiesAsColumnsQueryResultRowItem(rows, AnnotatedTextProvider.buildAnnotatedText(new ArrayList<>(masterRow.getRanges()), kwicProvider, tagDefinition), AnnotatedTextProvider.buildAnnotatedKeywordInContext(new ArrayList<>(masterRow.getRanges()), kwicProvider, tagDefinition, masterRow.getTagDefinitionPath()), kwicProvider.getSourceDocumentName(), kwicProvider.getSourceDocument().getUserMarkupCollectionReference(masterRow.getMarkupCollectionId()).getName());
if (!propertiesAsColumnsTagBasedTreeData.contains(item)) {
propertiesAsColumnsTagBasedTreeData.addItem(null, item);
}
}
tokenCount = propertiesAsColumnsTagBasedTreeData.getRootItems().size();
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error adding query result", e);
}
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class DoubleTreePanel method setSelectedQueryResultRows.
@Override
public void setSelectedQueryResultRows(Iterable<QueryResultRow> selectedRows) {
kwics.clear();
if ((selectedRows.iterator().next() instanceof TagQueryResultRow) && displaySettings.equals(DisplaySetting.GROUPED_BY_TAG)) {
for (QueryResultRow row : selectedRows) {
TagQueryResultRow tqrr = (TagQueryResultRow) row;
String tagPath = tqrr.getTagDefinitionPath().replace("/", "");
KwicProvider kwicProvider = null;
try {
kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
} catch (ExecutionException e1) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error visualizing group by tag", e1);
}
KeywordInSpanContext kwic = null;
try {
kwic = kwicProvider.getKwic(row.getRange(), contextSize);
KeywordInSpanContext newKwic = new KeywordInSpanContext(tagPath, kwic.getKwic(), kwic.getKwicSourceRange(), kwic.getRelativeKeywordStartPos(), kwic.isRightToLeft(), kwic.getSpanContext());
kwics.add(newKwic);
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error visualizing group by tag", e);
}
}
doubleTree.setupFromArrays(kwics, true);
} else {
for (QueryResultRow row : selectedRows) {
KwicProvider kwicProvider = null;
try {
kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
} catch (ExecutionException e1) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error visualizing selected data", e1);
}
KeywordInSpanContext kwic = null;
try {
kwic = kwicProvider.getKwic(row.getRange(), contextSize);
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error visualizing selected data", e);
}
kwics.add(kwic);
}
doubleTree.setupFromArrays(kwics, true);
}
}
use of de.catma.indexer.KwicProvider in project catma by forTEXT.
the class CSVExportFlatStreamSource method getStream.
@Override
public InputStream getStream() {
final QueryResult queryResult = queryResultSupplier.get();
final PipedInputStream in = new PipedInputStream();
final UI ui = UI.getCurrent();
final Lock lock = new ReentrantLock();
final Condition sending = lock.newCondition();
lock.lock();
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");
LoadingCache<String, String> colorCache = CacheBuilder.newBuilder().build(new CacheLoader<String, String>() {
@Override
public String load(String tagDefinitionId) throws Exception {
return "#" + ColorConverter.toHex(project.getTagManager().getTagLibrary().getTagDefinition(tagDefinitionId).getColor());
}
});
try (CSVPrinter csvPrinter = new CSVPrinter(writer, CSVFormat.EXCEL.withDelimiter(';'))) {
for (QueryResultRow row : queryResult) {
KwicProvider kwicProvider = kwicProviderCache.get(row.getSourceDocumentId());
if (row instanceof TagQueryResultRow) {
TagQueryResultRow tRow = (TagQueryResultRow) row;
List<Range> mergedRanges = Range.mergeRanges(new TreeSet<>((tRow).getRanges()));
for (Range range : mergedRanges) {
KeywordInSpanContext kwic = kwicProvider.getKwic(range, 5);
csvPrinter.printRecord(row.getQueryId().toSerializedString(), row.getSourceDocumentId(), kwicProvider.getSourceDocumentName(), kwicProvider.getDocumentLength(), kwic.getKeyword(), kwic.toString(), range.getStartPoint(), range.getEndPoint(), tRow.getMarkupCollectionId(), kwicProvider.getSourceDocument().getUserMarkupCollectionReference(tRow.getMarkupCollectionId()).toString(), tRow.getTagDefinitionPath(), tRow.getTagDefinitionVersion(), colorCache.get(tRow.getTagDefinitionId()), tRow.getTagInstanceId(), tRow.getPropertyDefinitionId(), tRow.getPropertyName(), tRow.getPropertyValue());
}
} else {
KeywordInSpanContext kwic = kwicProvider.getKwic(row.getRange(), 5);
csvPrinter.printRecord(row.getQueryId().toSerializedString(), row.getSourceDocumentId(), kwicProvider.getSourceDocumentName(), kwicProvider.getDocumentLength(), kwic.getKeyword(), kwic.toString(), row.getRange().getStartPoint(), row.getRange().getEndPoint());
}
csvPrinter.flush();
lock.lock();
try {
sending.signal();
} finally {
lock.unlock();
}
}
}
// 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
try {
try {
sending.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e1) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Error while waiting on CSV export!", e1);
}
} finally {
lock.unlock();
}
return in;
}
Aggregations