use of de.catma.queryengine.result.QueryResult in project catma by forTEXT.
the class WildcardQuery method execute.
@Override
protected QueryResult execute() throws Exception {
QueryOptions queryOptions = getQueryOptions();
WildcardTermExtractor termExtractor = new WildcardTermExtractor(wildcardPhrase, queryOptions.getUnseparableCharacterSequences(), queryOptions.getUserDefinedSeparatingCharacters(), queryOptions.getLocale());
List<String> termList = termExtractor.getOrderedTerms();
Indexer indexer = queryOptions.getIndexer();
QueryResult result = indexer.searchWildcardPhrase(queryOptions.getQueryId(), queryOptions.getRelevantSourceDocumentIDs(), termList, queryOptions.getLimit());
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 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.queryengine.result.QueryResult in project catma by forTEXT.
the class QueryJob method call.
public QueryResult call() throws Exception {
try {
StopWatch stopWatch = new StopWatch();
// parse the query
CatmaQueryLexer lex = new CatmaQueryLexer(new ANTLRStringStream(inputQuery));
CommonTokenStream tokens = new CommonTokenStream(lex);
CatmaQueryParser parser = new CatmaQueryParser(tokens);
CatmaQueryParser.start_return result = parser.start();
Tree t = (Tree) result.getTree();
CommonTreeNodeStream nodes = new CommonTreeNodeStream(t);
nodes.setTokenStream(parser.getTokenStream());
CatmaQueryWalker walker = new CatmaQueryWalker(nodes);
Query query = walker.start();
query.setQueryOptions(queryOptions);
// execute the query and retrieve the execution result
QueryResult queryResult = query.getResult();
getProgressListener().setProgress("Query finished!");
logger.info("query finished " + inputQuery + " duration: " + stopWatch);
return queryResult;
} catch (Exception e) {
if (e instanceof RecognitionException) {
throw new QueryException(inputQuery, (RecognitionException) e);
} else if ((e.getCause() != null) && (e.getCause() instanceof RecognitionException)) {
throw new QueryException(inputQuery, (RecognitionException) e.getCause());
} else {
throw new Exception(e);
}
}
}
use of de.catma.queryengine.result.QueryResult in project catma by forTEXT.
the class QueryRefinement method refineWithNonFreqQuery.
private QueryResult refineWithNonFreqQuery(QueryResult result) throws Exception {
QueryResult refinementResult = query.getResult();
Comparator<QueryResultRow> comparator = matchMode.getComparator();
if (comparator == null) {
QueryResultRowArray refinedResult = result.asQueryResultRowArray();
refinedResult.retainAll(refinementResult.asQueryResultRowArray());
return refinedResult;
} else {
Iterator<QueryResultRow> resultIterator = result.iterator();
while (resultIterator.hasNext()) {
QueryResultRow curRow = resultIterator.next();
if (!curRow.existsIn(refinementResult, comparator)) {
resultIterator.remove();
}
}
}
return result;
}
use of de.catma.queryengine.result.QueryResult 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