use of de.catma.queryengine.result.QueryResult in project catma by forTEXT.
the class CommentQuery method execute.
@Override
protected QueryResult execute() throws Exception {
QueryOptions queryOptions = getQueryOptions();
WildcardTermExtractor termExtractor = new WildcardTermExtractor(commentPhrase, queryOptions.getUnseparableCharacterSequences(), queryOptions.getUserDefinedSeparatingCharacters(), queryOptions.getLocale());
List<String> termList = termExtractor.getOrderedTerms();
Indexer indexer = queryOptions.getIndexer();
QueryResult result = indexer.searchCommentPhrase(queryOptions.getQueryId(), queryOptions.getRelevantSourceDocumentIDs(), termList, queryOptions.getLimit(), queryOptions.getUnseparableCharacterSequences(), queryOptions.getUserDefinedSeparatingCharacters(), queryOptions.getLocale());
Project repository = queryOptions.getRepository();
for (QueryResultRow row : result) {
SourceDocument sd = repository.getSourceDocument(row.getSourceDocumentId());
row.setPhrase(sd.getContent(row.getRange()));
}
return result;
}
use of de.catma.queryengine.result.QueryResult in project catma by forTEXT.
the class AnalyzeView method executeSearch.
private void executeSearch(String searchInput, Consumer<QueryResultPanel> addToLayoutFunction) {
QueryOptions queryOptions = new QueryOptions(new QueryId(searchInput), currentCorpus.getDocumentIds(), currentCorpus.getCollectionIds(), indexInfoSet.getUnseparableCharacterSequences(), indexInfoSet.getUserDefinedSeparatingCharacters(), indexInfoSet.getLocale(), project);
QueryJob job = new QueryJob(searchInput, queryOptions);
showProgress(true);
((BackgroundServiceProvider) UI.getCurrent()).submit("Searching...", job, new ExecutionListener<QueryResult>() {
public void done(QueryResult result) {
try {
QueryResultPanel queryResultPanel = new QueryResultPanel(project, result, new QueryId(searchInput.toString()), kwicProviderCache, closingPanel -> handleRemoveQueryResultPanel(closingPanel));
addToLayoutFunction.accept(queryResultPanel);
addQueryResultPanelSetting(queryResultPanel.getQueryResultPanelSetting());
} finally {
showProgress(false);
}
}
public void error(Throwable t) {
showProgress(false);
if (t instanceof QueryException) {
QueryJob.QueryException qe = (QueryJob.QueryException) t;
String input = qe.getInput();
int idx = ((RecognitionException) qe.getCause()).charPositionInLine;
if ((idx >= 0) && (input.length() > idx)) {
char character = input.charAt(idx);
String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b> approximately at positon {1} character <b>{2}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input, idx + 1, character);
HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
} else {
String message = MessageFormat.format("<html><p>There is something wrong with your query <b>{0}</b>.</p> <p>If you are unsure about how to construct a query try the Query Builder!</p></html>", input);
HTMLNotification.show("Info", message, Type.TRAY_NOTIFICATION);
}
} else {
((ErrorHandler) UI.getCurrent()).showAndLogError("Error during search!", t);
}
}
});
}
use of de.catma.queryengine.result.QueryResult 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;
}
use of de.catma.queryengine.result.QueryResult in project catma by forTEXT.
the class TPGraphProjectIndexer method searchCollocation.
@Override
public QueryResult searchCollocation(QueryId queryId, QueryResult baseResult, QueryResult collocationConditionResult, int spanContextSize, SpanDirection direction) throws IOException {
int baseResultSize = baseResult.size();
int collocConditionResultSize = collocationConditionResult.size();
boolean swapCollocationDirection = baseResultSize > collocConditionResultSize;
// swap to reduce the amount of span context computation
if (swapCollocationDirection) {
QueryResult bufferResult = baseResult;
baseResult = collocationConditionResult;
collocationConditionResult = bufferResult;
}
Multimap<String, QueryResultRow> collocConditionResultBySourceDocumentId = ArrayListMultimap.create();
collocationConditionResult.forEach(row -> collocConditionResultBySourceDocumentId.put(row.getSourceDocumentId(), row));
QueryResultRowArray matchingBaseRows = new QueryResultRowArray();
QueryResultRowArray matchingCollocConditionRows = new QueryResultRowArray();
for (QueryResultRow row : baseResult) {
if (collocConditionResultBySourceDocumentId.containsKey(row.getSourceDocumentId())) {
SpanContext spanContext = getSpanContextFor(row.getSourceDocumentId(), row.getRange(), spanContextSize, direction);
boolean baseMatch = matchingBaseRows.contains(row);
for (QueryResultRow collocConditionRow : collocConditionResultBySourceDocumentId.get(row.getSourceDocumentId())) {
boolean collocMatch = matchingCollocConditionRows.contains(collocConditionRow);
if (!baseMatch || !collocMatch) {
if (spanContext.hasOverlappingRange(collocConditionRow.getRanges(), direction)) {
if (!baseMatch) {
matchingBaseRows.add(row);
baseMatch = true;
}
if (!collocMatch) {
matchingCollocConditionRows.add(collocConditionRow);
collocMatch = true;
}
}
}
}
}
}
// swap back
if (swapCollocationDirection) {
QueryResultRowArray bufferResult = matchingBaseRows;
matchingBaseRows = matchingCollocConditionRows;
matchingCollocConditionRows = bufferResult;
}
return matchingBaseRows;
}
Aggregations