Search in sources :

Example 6 with AnnisCorpus

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

the class ListCorpusSqlHelper method mapRow.

public AnnisCorpus mapRow(ResultSet rs, int rowNum) throws SQLException {
    AnnisCorpus corpus = new AnnisCorpus();
    corpus.setId(rs.getLong("id"));
    corpus.setName(rs.getString("name"));
    corpus.setTextCount(rs.getInt("text"));
    corpus.setTokenCount(rs.getInt("tokens"));
    try {
        corpus.setSourcePath(rs.getString("source_path"));
    } catch (SQLException ex) {
        log.debug(null, ex);
    }
    return corpus;
}
Also used : AnnisCorpus(annis.service.objects.AnnisCorpus) SQLException(java.sql.SQLException)

Example 7 with AnnisCorpus

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

the class SearchView method getMappedCorpora.

/**
 * Takes a list of raw corpus names as given by the #c parameter and returns a
 * list of corpus names that are known to exist. It also replaces alias names
 * with the real corpus names.
 *
 * @param originalNames
 * @return
 */
private Set<String> getMappedCorpora(List<String> originalNames) {
    WebResource rootRes = Helper.getAnnisWebResource();
    Set<String> mappedNames = new HashSet<>();
    // iterate over given corpora and map names if necessary
    for (String selectedCorpusName : originalNames) {
        // get the real corpus descriptions by the name (which could be an alias)
        try {
            List<AnnisCorpus> corporaByName = rootRes.path("query").path("corpora").path(urlPathEscape.escape(selectedCorpusName)).get(new GenericType<List<AnnisCorpus>>() {
            });
            if (corporaByName != null && !corporaByName.isEmpty()) {
                for (AnnisCorpus c : corporaByName) {
                    mappedNames.add(c.getName());
                }
            }
        } catch (ClientHandlerException ex) {
            String msg = "alias mapping does not work for alias: " + selectedCorpusName;
            log.error(msg, ex);
            Notification.show(msg, Notification.Type.TRAY_NOTIFICATION);
        }
    }
    return mappedNames;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) AnnisCorpus(annis.service.objects.AnnisCorpus) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 8 with AnnisCorpus

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

the class CorpusManagement method fetchFromService.

public void fetchFromService() throws CriticalServiceQueryException, ServiceQueryException {
    if (webResourceProvider != null) {
        corpora.clear();
        try {
            WebResource rootRes = webResourceProvider.getWebResource();
            List<AnnisCorpus> corporaList = rootRes.path("query").path("corpora").get(new GenericType<List<AnnisCorpus>>() {
            });
            for (AnnisCorpus c : corporaList) {
                corpora.put(c.getName(), c);
            }
        } catch (ClientHandlerException ex) {
            log.error(null, ex);
            throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
        } catch (UniformInterfaceException ex) {
            if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
                throw new CriticalServiceQueryException("You are not authorized to get the corpus list.");
            } else {
                log.error(null, ex);
                throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
            }
        }
    }
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) AnnisCorpus(annis.service.objects.AnnisCorpus) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException) ServiceQueryException(annis.gui.ServiceQueryException) WebResource(com.sun.jersey.api.client.WebResource) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) CriticalServiceQueryException(annis.gui.CriticalServiceQueryException)

Example 9 with AnnisCorpus

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

the class AcceptanceTest method runKickstarter.

@BeforeClass
public static void runKickstarter() {
    try {
        runner = new KickstartRunner(WEB_PORT, SERVICE_PORT);
        runner.startService();
        runner.startJetty();
        // get all installed corpora
        for (AnnisCorpus c : runner.getCorpora()) {
            corpora.add(c.getName());
        }
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("takesScreenshot", true);
        driver = new PhantomJSDriver(caps);
        driver.manage().window().setSize(new Dimension(1024, 768));
    } catch (Exception ex) {
        log.error(null, ex);
        runner = null;
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) AnnisCorpus(annis.service.objects.AnnisCorpus) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) KickstartRunner(de.hu_berlin.german.korpling.annis.kickstarter.KickstartRunner) Dimension(org.openqa.selenium.Dimension) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 10 with AnnisCorpus

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

the class SearchView method evaluateCitation.

public void evaluateCitation(String relativeUri) {
    Matcher m = citationPattern.matcher(relativeUri);
    if (m.matches()) {
        // AQL
        String aql = "";
        if (m.group(1) != null) {
            aql = m.group(1);
        }
        // CIDS
        Set<String> selectedCorpora = new HashSet<>();
        if (m.group(2) != null) {
            String[] cids = m.group(2).split(",");
            selectedCorpora.addAll(Arrays.asList(cids));
        }
        // filter by actually avaible user corpora in order not to get any exception later
        WebResource res = Helper.getAnnisWebResource();
        List<AnnisCorpus> userCorpora = res.path("query").path("corpora").get(new AnnisCorpusListType());
        LinkedList<String> userCorporaStrings = new LinkedList<>();
        for (AnnisCorpus c : userCorpora) {
            userCorporaStrings.add(c.getName());
        }
        selectedCorpora.retainAll(userCorporaStrings);
        // CLEFT and CRIGHT
        if (m.group(4) != null && m.group(6) != null) {
            int cleft = 0;
            int cright = 0;
            try {
                cleft = Integer.parseInt(m.group(4));
                cright = Integer.parseInt(m.group(6));
            } catch (NumberFormatException ex) {
                log.error("could not parse context value", ex);
            }
            ui.getQueryController().setQuery(new PagedResultQuery(cleft, cright, 0, 10, null, aql, selectedCorpora));
        } else {
            ui.getQueryController().setQuery(new Query(aql, selectedCorpora));
        }
        // remove all currently openend sub-windows
        Set<Window> all = new HashSet<>(ui.getWindows());
        for (Window w : all) {
            ui.removeWindow(w);
        }
    } else {
        Notification.show("Invalid citation", Notification.Type.WARNING_MESSAGE);
    }
}
Also used : Window(com.vaadin.ui.Window) DisplayedResultQuery(annis.gui.objects.DisplayedResultQuery) PagedResultQuery(annis.gui.objects.PagedResultQuery) Query(annis.gui.objects.Query) Matcher(java.util.regex.Matcher) AnnisCorpus(annis.service.objects.AnnisCorpus) WebResource(com.sun.jersey.api.client.WebResource) LinkedList(java.util.LinkedList) PagedResultQuery(annis.gui.objects.PagedResultQuery) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

AnnisCorpus (annis.service.objects.AnnisCorpus)14 LinkedList (java.util.LinkedList)5 WebResource (com.sun.jersey.api.client.WebResource)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Subject (org.apache.shiro.subject.Subject)3 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 Window (com.vaadin.ui.Window)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Properties (java.util.Properties)2 CorpusBrowserPanel (annis.gui.CorpusBrowserPanel)1 CriticalServiceQueryException (annis.gui.CriticalServiceQueryException)1 MetaDataPanel (annis.gui.MetaDataPanel)1