Search in sources :

Example 1 with GroupedQueryResult

use of de.catma.queryengine.result.GroupedQueryResult in project catma by forTEXT.

the class SimilQuery method searchTermsBySimilarity.

/**
 * Searches a list of terms that a similar to the given phrase by a certain degree
 *
 * @param phrase the phrase to compare with
 * @param similPercent the degree of similarity
 * @return the list of similar terms
 * @throws Exception
 * @see org.catma.queryengine.Simil
 */
private QueryResult searchTermsBySimilarity() throws Exception {
    QueryResultRowArray result = new QueryResultRowArray();
    Simil simil = new Simil(phrase);
    FreqQuery freqQuery = new FreqQuery(CompareOperator.GREATERTHAN.toString(), "0");
    freqQuery.setQueryOptions(getQueryOptions());
    QueryResult allTokens = freqQuery.getResult();
    Set<GroupedQueryResult> allTypes = allTokens.asGroupedSet();
    for (GroupedQueryResult groupedQueryResult : allTypes) {
        String type = groupedQueryResult.getGroup().toString();
        if (simil.getSimilarityInPercentFor(type) >= similPercent) {
            for (QueryResultRow row : groupedQueryResult) {
                result.add(row);
            }
        }
    }
    return result;
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult) 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 2 with GroupedQueryResult

use of de.catma.queryengine.result.GroupedQueryResult in project catma by forTEXT.

the class QueryResultPanel method addTagBasedRootItems.

void addTagBasedRootItems(QueryResult result) {
    tokenCount = 0;
    Set<GroupedQueryResult> groupedQueryResults = result.asGroupedSet(row -> {
        if (row instanceof TagQueryResultRow) {
            if (((TagQueryResultRow) row).getPropertyDefinitionId() != null) {
                resultContainsProperties = true;
            }
            return ((TagQueryResultRow) row).getTagDefinitionPath();
        }
        return TagQueryResultRowItem.getNoTagAvailableKey();
    });
    for (GroupedQueryResult groupedQueryResult : groupedQueryResults) {
        TagQueryResultRowItem tagQueryResultRowItem = new TagQueryResultRowItem(includeQueryId, groupedQueryResult, project);
        if (!tagBasedTreeData.contains(tagQueryResultRowItem)) {
            tokenCount += groupedQueryResult.getTotalFrequency();
            tagBasedTreeData.addItem(null, tagQueryResultRowItem);
            tagBasedTreeData.addItem(tagQueryResultRowItem, new DummyQueryResultRowItem());
        }
    }
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow)

Example 3 with GroupedQueryResult

use of de.catma.queryengine.result.GroupedQueryResult in project catma by forTEXT.

the class QueryRefinement method refineWithFreqQuery.

private QueryResult refineWithFreqQuery(QueryResult result) throws Exception {
    FreqQuery freqQuery = (FreqQuery) query;
    Set<GroupedQueryResult> groupedSet = result.asGroupedSet();
    Iterator<GroupedQueryResult> resultIterator = groupedSet.iterator();
    while (resultIterator.hasNext()) {
        GroupedQueryResult curGroupedResult = resultIterator.next();
        if (!freqQuery.matches(curGroupedResult.getTotalFrequency())) {
            resultIterator.remove();
        }
    }
    QueryResultRowArray refinedResult = new QueryResultRowArray();
    for (GroupedQueryResult groupedResult : groupedSet) {
        for (QueryResultRow row : groupedResult) {
            refinedResult.add(row);
        }
    }
    return refinedResult;
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult) QueryResultRow(de.catma.queryengine.result.QueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Example 4 with GroupedQueryResult

use of de.catma.queryengine.result.GroupedQueryResult in project catma by forTEXT.

the class QueryResultPanel method addPhraseBasedRootItems.

void addPhraseBasedRootItems(QueryResult result) {
    Set<GroupedQueryResult> groupedQueryResults = result.asGroupedSet();
    tokenCount = 0;
    for (GroupedQueryResult groupedQueryResult : groupedQueryResults) {
        PhraseQueryResultRowItem phraseQueryResultRowItem = new PhraseQueryResultRowItem(includeQueryId, groupedQueryResult);
        if (!phraseBasedTreeData.contains(phraseQueryResultRowItem)) {
            tokenCount += groupedQueryResult.getTotalFrequency();
            phraseBasedTreeData.addItem(null, phraseQueryResultRowItem);
            phraseBasedTreeData.addItem(phraseQueryResultRowItem, new DummyQueryResultRowItem());
        }
    }
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult)

Example 5 with GroupedQueryResult

use of de.catma.queryengine.result.GroupedQueryResult in project catma by forTEXT.

the class TagQueryResultRowItem method addChildRowItems.

@Override
public void addChildRowItems(TreeData<QueryResultRowItem> treeData, LoadingCache<String, KwicProvider> kwicProviderCache) {
    try {
        if (includeQueryId) {
            Set<GroupedQueryResult> groupedQueryResults = getRows().asGroupedSet(row -> {
                return row.getQueryId();
            });
            for (GroupedQueryResult groupedQueryResult : groupedQueryResults) {
                AnnotatedQueryIdQueryResultRowItem queryIdQueryResultRowItem = new AnnotatedQueryIdQueryResultRowItem(identity, groupedQueryResult, project);
                if (!treeData.contains(queryIdQueryResultRowItem)) {
                    treeData.addItem(this, queryIdQueryResultRowItem);
                    treeData.addItem(queryIdQueryResultRowItem, new DummyQueryResultRowItem());
                }
            }
        } else {
            for (String documentId : groupedQueryResult.getSourceDocumentIDs()) {
                String documentName = kwicProviderCache.get(documentId).getSourceDocumentName();
                AnnotatedDocumentQueryResultRowItem item = new AnnotatedDocumentQueryResultRowItem(identity, documentName, documentId, groupedQueryResult.getSubResult(documentId), project);
                if (!treeData.contains(item)) {
                    treeData.addItem(this, item);
                    treeData.addItem(item, new DummyQueryResultRowItem());
                }
            }
        }
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("error displaying annotated query results", e);
    }
}
Also used : GroupedQueryResult(de.catma.queryengine.result.GroupedQueryResult)

Aggregations

GroupedQueryResult (de.catma.queryengine.result.GroupedQueryResult)6 QueryResultRow (de.catma.queryengine.result.QueryResultRow)2 QueryResultRowArray (de.catma.queryengine.result.QueryResultRowArray)2 QueryResult (de.catma.queryengine.result.QueryResult)1 TagQueryResultRow (de.catma.queryengine.result.TagQueryResultRow)1