Search in sources :

Example 6 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class QueryController method executeSearch.

/**
 * Executes a query.
 * @param replaceOldTab
 * @param freshQuery If true the offset and the selected matches are reset before executing the query.
 */
public void executeSearch(boolean replaceOldTab, boolean freshQuery) {
    if (freshQuery) {
        getState().getOffset().setValue(0l);
        getState().getSelectedMatches().setValue(new TreeSet<Long>());
        // get the value for the visible segmentation from the configured context
        Set<String> selectedCorpora = getState().getSelectedCorpora().getValue();
        CorpusConfig config = new CorpusConfig();
        if (selectedCorpora != null && !selectedCorpora.isEmpty()) {
            config = ui.getCorpusConfigWithCache(selectedCorpora.iterator().next());
        }
        if (config.containsKey(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION)) {
            String configVal = config.getConfig(SearchOptionsPanel.KEY_DEFAULT_BASE_TEXT_SEGMENTATION);
            if ("".equals(configVal) || "tok".equals(configVal)) {
                configVal = null;
            }
            getState().getVisibleBaseText().setValue(configVal);
        } else {
            getState().getVisibleBaseText().setValue(getState().getContextSegmentation().getValue());
        }
    }
    // construct a query from the current properties
    DisplayedResultQuery displayedQuery = getSearchQuery();
    searchView.getControlPanel().getQueryPanel().setStatus("Searching...");
    cancelSearch();
    // cleanup resources
    VaadinSession session = VaadinSession.getCurrent();
    session.setAttribute(IFrameResourceMap.class, new IFrameResourceMap());
    if (session.getAttribute(MediaController.class) != null) {
        session.getAttribute(MediaController.class).clearMediaPlayers();
    }
    searchView.updateFragment(displayedQuery);
    if (displayedQuery.getCorpora() == null || displayedQuery.getCorpora().isEmpty()) {
        Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE);
        return;
    }
    if ("".equals(displayedQuery.getQuery())) {
        Notification.show("Empty query", Notification.Type.WARNING_MESSAGE);
        return;
    }
    addHistoryEntry(displayedQuery);
    AsyncWebResource res = Helper.getAnnisAsyncWebResource();
    // 
    // begin execute match fetching
    // 
    ResultViewPanel oldPanel = searchView.getLastSelectedResultView();
    if (replaceOldTab) {
        // remove old panel from view
        searchView.closeTab(oldPanel);
    }
    ResultViewPanel newResultView = new ResultViewPanel(ui, ui, ui.getInstanceConfig(), displayedQuery);
    newResultView.getPaging().addCallback(new SpecificPagingCallback(ui, searchView, newResultView, displayedQuery));
    TabSheet.Tab newTab;
    List<ResultViewPanel> existingResultPanels = getResultPanels();
    String caption = existingResultPanels.isEmpty() ? "Query Result" : "Query Result #" + (existingResultPanels.size() + 1);
    newTab = searchView.getMainTab().addTab(newResultView, caption);
    newTab.setClosable(true);
    newTab.setIcon(FontAwesome.SEARCH);
    searchView.getMainTab().setSelectedTab(newResultView);
    searchView.notifiyQueryStarted();
    Background.run(new ResultFetchJob(displayedQuery, newResultView, ui));
    // 
    // end execute match fetching
    // 
    // 
    // begin execute count
    // 
    // start count query
    searchView.getControlPanel().getQueryPanel().setCountIndicatorEnabled(true);
    AsyncWebResource countRes = res.path("query").path("search").path("count").queryParam("q", Helper.encodeJersey(displayedQuery.getQuery())).queryParam("corpora", Helper.encodeJersey(StringUtils.join(displayedQuery.getCorpora(), ",")));
    Future<MatchAndDocumentCount> futureCount = countRes.get(MatchAndDocumentCount.class);
    state.getExecutedTasks().put(QueryUIState.QueryType.COUNT, futureCount);
    Background.run(new CountCallback(newResultView, displayedQuery.getLimit(), ui));
// 
// end execute count
// 
}
Also used : MediaController(annis.libgui.media.MediaController) VaadinSession(com.vaadin.server.VaadinSession) ResultViewPanel(annis.gui.resultview.ResultViewPanel) SingleResultFetchJob(annis.gui.resultfetch.SingleResultFetchJob) ResultFetchJob(annis.gui.resultfetch.ResultFetchJob) CountCallback(annis.gui.controller.CountCallback) CorpusConfig(annis.service.objects.CorpusConfig) TabSheet(com.vaadin.ui.TabSheet) IFrameResourceMap(annis.libgui.visualizers.IFrameResourceMap) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) SpecificPagingCallback(annis.gui.controller.SpecificPagingCallback) MatchAndDocumentCount(annis.service.objects.MatchAndDocumentCount) AsyncWebResource(com.sun.jersey.api.client.AsyncWebResource)

Example 7 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class ExportBackgroundJob method call.

@Override
public File call() throws Exception {
    final File currentTmpFile = File.createTempFile("annis-export", "." + exporter.getFileEnding());
    currentTmpFile.deleteOnExit();
    final Map<String, CorpusConfig> corpusConfigs = new LinkedHashMap<>();
    for (String c : query.getCorpora()) {
        corpusConfigs.put(c, ui.getCorpusConfigWithCache(c));
    }
    try (final OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream(currentTmpFile), "UTF-8")) {
        exportError = exporter.convertText(query.getQuery(), query.getLeftContext(), query.getRightContext(), query.getCorpora(), query.getAnnotationKeys(), query.getParameters(), query.getAlignmc(), Helper.getAnnisWebResource().path("query"), outWriter, eventBus, corpusConfigs);
    } finally {
        ui.access(new Runnable() {

            @Override
            public void run() {
                if (panel != null) {
                    panel.showResult(currentTmpFile, exportError);
                }
                if (exportError instanceof UniformInterfaceException) {
                    ui.getQueryController().reportServiceException((UniformInterfaceException) exportError, true);
                }
            }
        });
    }
    return currentTmpFile;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) CorpusConfig(annis.service.objects.CorpusConfig) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class QueryServiceImpl method corpusConfig.

@GET
@Path("corpora/{top}/config")
@Produces("application/xml")
public CorpusConfig corpusConfig(@PathParam("top") String toplevelName) {
    Subject user = SecurityUtils.getSubject();
    user.checkPermission("query:config:" + toplevelName);
    try {
        Properties tmp = queryDao.getCorpusConfigurationSave(toplevelName);
        CorpusConfig corpusConfig = new CorpusConfig();
        corpusConfig.setConfig(tmp);
        return corpusConfig;
    } catch (Exception ex) {
        log.error("problems with reading config", ex);
        throw new WebApplicationException(ex, 500);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Properties(java.util.Properties) CorpusConfig(annis.service.objects.CorpusConfig) Subject(org.apache.shiro.subject.Subject) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with CorpusConfig

use of annis.service.objects.CorpusConfig in project ANNIS by korpling.

the class ResultViewPanel method updateVariables.

private void updateVariables(SaltProject p) {
    segmentationLayerSet.addAll(getSegmentationNames(p));
    tokenAnnotationLevelSet.addAll(CommonHelper.getTokenAnnotationLevelSet(p));
    Set<String> hiddenTokenAnnos = null;
    Set<String> corpusNames = CommonHelper.getToplevelCorpusNames(p);
    for (String corpusName : corpusNames) {
        CorpusConfig corpusConfig = Helper.getCorpusConfig(corpusName);
        if (corpusConfig != null && corpusConfig.containsKey(MAPPING_HIDDEN_ANNOS)) {
            hiddenTokenAnnos = new HashSet<>(Arrays.asList(StringUtils.split(corpusConfig.getConfig(MAPPING_HIDDEN_ANNOS), ",")));
        }
    }
    if (hiddenTokenAnnos != null) {
        for (String tokenLevel : hiddenTokenAnnos) {
            if (tokenAnnotationLevelSet.contains(tokenLevel)) {
                tokenAnnotationLevelSet.remove(tokenLevel);
            }
        }
    }
    updateSegmentationLayer(segmentationLayerSet);
    updateVisibleToken(tokenAnnotationLevelSet);
}
Also used : CorpusConfig(annis.service.objects.CorpusConfig)

Aggregations

CorpusConfig (annis.service.objects.CorpusConfig)9 Properties (java.util.Properties)2 CountCallback (annis.gui.controller.CountCallback)1 SpecificPagingCallback (annis.gui.controller.SpecificPagingCallback)1 DisplayedResultQuery (annis.gui.objects.DisplayedResultQuery)1 ResultFetchJob (annis.gui.resultfetch.ResultFetchJob)1 SingleResultFetchJob (annis.gui.resultfetch.SingleResultFetchJob)1 ResultViewPanel (annis.gui.resultview.ResultViewPanel)1 MediaController (annis.libgui.media.MediaController)1 IFrameResourceMap (annis.libgui.visualizers.IFrameResourceMap)1 AnnisCorpus (annis.service.objects.AnnisCorpus)1 CorpusConfigMap (annis.service.objects.CorpusConfigMap)1 MatchAndDocumentCount (annis.service.objects.MatchAndDocumentCount)1 AsyncWebResource (com.sun.jersey.api.client.AsyncWebResource)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 VaadinSession (com.vaadin.server.VaadinSession)1 TabSheet (com.vaadin.ui.TabSheet)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1