Search in sources :

Example 6 with QueryResultRow

use of de.catma.queryengine.result.QueryResultRow 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 7 with QueryResultRow

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

the class TagDiffQuery 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.searchTagDiff(queryOptions.getQueryId(), relevantUserMarkupCollIDs, propertyName, 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 QueryResultRow

use of de.catma.queryengine.result.QueryResultRow 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 9 with QueryResultRow

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

the class KwicPanel method initComponents.

private void initComponents() {
    setSizeFull();
    setMargin(false);
    setSpacing(false);
    btExpandCompress = new IconButton(expandResource);
    btExpandCompress.setVisible(false);
    kwicDataProvider = new ListDataProvider<>(new HashSet<>());
    kwicGrid = new Grid<QueryResultRow>(kwicDataProvider);
    kwicGrid.setSizeFull();
    kwicGrid.addColumn(row -> kwicItemHandler.getDocumentName(row)).setCaption("Document").setWidth(200).setHidable(true);
    kwicGrid.addColumn(row -> kwicItemHandler.getCollectionName(row)).setCaption("Collection").setWidth(200).setId(ColumnId.COLLECION_NAME.name()).setHidable(true).setHidden(true);
    Column<QueryResultRow, ?> backwardCtxColumn = kwicGrid.addColumn(row -> kwicItemHandler.getBackwardContext(row)).setCaption("Left Context").setStyleGenerator(row -> kwicItemHandler.getBackwardContextStyle(row)).setWidth(200);
    Column<QueryResultRow, ?> keywordColumn = kwicGrid.addColumn(row -> kwicItemHandler.getKeyword(row)).setCaption("Keyword").setWidth(200).setRenderer(new HtmlRenderer()).setStyleGenerator(row -> kwicItemHandler.getKeywordStyle(row)).setDescriptionGenerator(row -> kwicItemHandler.getKeywordDescription(row), ContentMode.HTML);
    kwicGrid.addColumn(row -> kwicItemHandler.getForwardContext(row)).setCaption("Right Context").setStyleGenerator(row -> kwicItemHandler.getForwardContextStyle(row)).setWidth(200);
    kwicGrid.addColumn(row -> row.getRange().getStartPoint()).setCaption("Start Point").setWidth(100).setId(ColumnId.START_POS.name()).setHidable(true);
    kwicGrid.addColumn(row -> row.getRange().getEndPoint()).setCaption("End Point").setWidth(100).setHidable(true);
    kwicGrid.addColumn(row -> kwicItemHandler.getTagPath(row)).setCaption("Tag").setHidable(true).setHidden(true).setId(ColumnId.TAG.name()).setWidth(200);
    kwicGrid.addColumn(row -> kwicItemHandler.getPropertyName(row)).setCaption("Property").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_NAME.name()).setWidth(200);
    kwicGrid.addColumn(row -> kwicItemHandler.getPropertyValue(row)).setCaption("Value").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_VALUE.name()).setWidth(200);
    kwicGrid.sort(keywordColumn);
    kwicGrid.getDefaultHeaderRow().getCell(keywordColumn).setStyleName("kwic-panel-keyword-header");
    kwicGrid.getDefaultHeaderRow().getCell(backwardCtxColumn).setStyleName("kwic-panel-backwardctx-header");
    kwicGridComponent = new ActionGridComponent<>(new Label("Keyword in context"), kwicGrid);
    kwicGridComponent.getActionGridBar().setAddBtnVisible(false);
    kwicGridComponent.getActionGridBar().addButtonRight(btExpandCompress);
    kwicGridComponent.setMargin(new MarginInfo(false, false, false, true));
    addComponent(kwicGridComponent);
    setExpandRatio(kwicGridComponent, 1f);
    btnClearSelectedRows = new IconButton(VaadinIcons.ERASER);
    btnClearSelectedRows.setVisible(false);
    btnClearSelectedRows.setDescription("Remove the selected rows from this list");
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) DisplaySetting(de.catma.ui.module.analyze.queryresultpanel.DisplaySetting) MenuItem(com.vaadin.ui.MenuBar.MenuItem) LoadingCache(com.google.common.cache.LoadingCache) ZonedDateTime(java.time.ZonedDateTime) UI(com.vaadin.ui.UI) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) KwicProvider(de.catma.indexer.KwicProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Map(java.util.Map) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) AnnotationWizard(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizard) IconButton(de.catma.ui.component.IconButton) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) ItemClick(com.vaadin.ui.Grid.ItemClick) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) Type(com.vaadin.ui.Notification.Type) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) StreamResource(com.vaadin.server.StreamResource) Range(de.catma.document.Range) ClickListener(com.vaadin.ui.Button.ClickListener) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) LocalDateTime(java.time.LocalDateTime) Query(com.vaadin.data.provider.Query) WizardContext(de.catma.ui.dialog.wizard.WizardContext) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) ActionGridBar(de.catma.ui.component.actiongrid.ActionGridBar) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Registration(com.vaadin.shared.Registration) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) IDGenerator(de.catma.util.IDGenerator) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) CSVExportGroupedStreamSource(de.catma.ui.module.analyze.CSVExportGroupedStreamSource) ListDataProvider(com.vaadin.data.provider.ListDataProvider) ContentMode(com.vaadin.shared.ui.ContentMode) Property(de.catma.tag.Property) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) QueryResultRow(de.catma.queryengine.result.QueryResultRow) SourceDocument(de.catma.document.source.SourceDocument) Visualization(de.catma.ui.module.analyze.visualization.Visualization) ContextMenu(com.vaadin.contextmenu.ContextMenu) QueryResultRowInAnnotateEvent(de.catma.ui.events.QueryResultRowInAnnotateEvent) DateTimeFormatter(java.time.format.DateTimeFormatter) FileDownloader(com.vaadin.server.FileDownloader) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) CSVExportFlatStreamSource(de.catma.ui.module.analyze.CSVExportFlatStreamSource) AnnotationWizardContextKey(de.catma.ui.module.analyze.visualization.kwic.annotation.AnnotationWizardContextKey) Grid(com.vaadin.ui.Grid) IconButton(de.catma.ui.component.IconButton) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) MarginInfo(com.vaadin.shared.ui.MarginInfo) Label(com.vaadin.ui.Label) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) HashSet(java.util.HashSet)

Example 10 with QueryResultRow

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

the class KwicPanel method getFilteredQueryResult.

public QueryResultRowArray getFilteredQueryResult() {
    QueryResultRowArray result = new QueryResultRowArray();
    kwicDataProvider.fetch(new Query<QueryResultRow, SerializablePredicate<QueryResultRow>>()).forEach(row -> result.add(row));
    return result;
}
Also used : Query(com.vaadin.data.provider.Query) TagQueryResultRow(de.catma.queryengine.result.TagQueryResultRow) QueryResultRow(de.catma.queryengine.result.QueryResultRow) QueryResultRowArray(de.catma.queryengine.result.QueryResultRowArray)

Aggregations

QueryResultRow (de.catma.queryengine.result.QueryResultRow)29 TagQueryResultRow (de.catma.queryengine.result.TagQueryResultRow)22 QueryResultRowArray (de.catma.queryengine.result.QueryResultRowArray)18 SourceDocument (de.catma.document.source.SourceDocument)13 Range (de.catma.document.Range)12 KwicProvider (de.catma.indexer.KwicProvider)10 Project (de.catma.project.Project)10 QueryResult (de.catma.queryengine.result.QueryResult)10 ArrayList (java.util.ArrayList)10 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)8 TagDefinition (de.catma.tag.TagDefinition)8 UI (com.vaadin.ui.UI)6 HashSet (java.util.HashSet)6 CacheLoader (com.google.common.cache.CacheLoader)5 LoadingCache (com.google.common.cache.LoadingCache)5 Query (com.vaadin.data.provider.Query)5 AnnotationCollectionManager (de.catma.document.annotation.AnnotationCollectionManager)5 List (java.util.List)5 Map (java.util.Map)5 CacheBuilder (com.google.common.cache.CacheBuilder)4