Search in sources :

Example 6 with QueryResult

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;
}
Also used : Project(de.catma.project.Project) QueryResult(de.catma.queryengine.result.QueryResult) Indexer(de.catma.indexer.Indexer) QueryResultRow(de.catma.queryengine.result.QueryResultRow) WildcardTermExtractor(de.catma.indexer.WildcardTermExtractor) SourceDocument(de.catma.document.source.SourceDocument)

Example 7 with QueryResult

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;
}
Also used : QueryResultRow(de.catma.queryengine.result.QueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Range(de.catma.document.Range) Project(de.catma.project.Project) QueryResult(de.catma.queryengine.result.QueryResult) Indexer(de.catma.indexer.Indexer) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Example 8 with QueryResult

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);
        }
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) CatmaQueryParser(de.catma.queryengine.parser.CatmaQueryParser) RecognitionException(org.antlr.runtime.RecognitionException) StopWatch(de.catma.util.StopWatch) QueryResult(de.catma.queryengine.result.QueryResult) CatmaQueryLexer(de.catma.queryengine.parser.CatmaQueryLexer) Tree(org.antlr.runtime.tree.Tree) CatmaQueryWalker(de.catma.queryengine.parser.CatmaQueryWalker) RecognitionException(org.antlr.runtime.RecognitionException) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 9 with QueryResult

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;
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult) QueryResult(de.catma.queryengine.result.QueryResult) QueryResultRow(de.catma.queryengine.result.QueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Example 10 with QueryResult

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;
}
Also used : Project(de.catma.project.Project) QueryResult(de.catma.queryengine.result.QueryResult) Indexer(de.catma.indexer.Indexer) QueryResultRow(de.catma.queryengine.result.QueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray) Range(de.catma.document.Range)

Aggregations

QueryResult (de.catma.queryengine.result.QueryResult)14 QueryResultRow (de.catma.queryengine.result.QueryResultRow)10 Indexer (de.catma.indexer.Indexer)6 QueryResultRowArray (de.catma.queryengine.result.QueryResultRowArray)6 TagQueryResultRow (de.catma.queryengine.result.TagQueryResultRow)6 SourceDocument (de.catma.document.source.SourceDocument)5 Project (de.catma.project.Project)5 Range (de.catma.document.Range)4 UI (com.vaadin.ui.UI)3 KwicProvider (de.catma.indexer.KwicProvider)3 LoadingCache (com.google.common.cache.LoadingCache)2 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)2 List (java.util.List)2 RecognitionException (org.antlr.runtime.RecognitionException)2 MaterialTheme (com.github.appreciated.material.MaterialTheme)1 CacheLoader (com.google.common.cache.CacheLoader)1 EventBus (com.google.common.eventbus.EventBus)1 ListDataProvider (com.vaadin.data.provider.ListDataProvider)1 VaadinIcons (com.vaadin.icons.VaadinIcons)1 ClassResource (com.vaadin.server.ClassResource)1