Search in sources :

Example 1 with FrequencyTable

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

the class QueryServiceImpl method frequency.

/**
 * Frequency analysis.
 *
 * @param  rawFields Comma seperated list of result vector elements.
 *                   Each element has the form <node-nr>:<anno-name>. The
 *                   annotation name can be set to "tok" to indicate that the
 *                   span should be used instead of an annotation.
 */
@GET
@Path("search/frequency")
@Produces("application/xml")
public FrequencyTable frequency(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @QueryParam("fields") String rawFields) {
    requiredParameter(query, "q", "AnnisQL query");
    requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
    requiredParameter(rawFields, "fields", "Comma seperated list of result vector elements.");
    Subject user = SecurityUtils.getSubject();
    List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
    for (String c : corpusNames) {
        user.checkPermission("query:matrix:" + c);
    }
    QueryData data = queryDataFromParameters(query, rawCorpusNames);
    FrequencyTableQuery ext = FrequencyTableQuery.parse(rawFields);
    data.addExtension(ext);
    long start = new Date().getTime();
    FrequencyTable freqTable = queryDao.frequency(data);
    long end = new Date().getTime();
    logQuery("FREQUENCY", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start);
    return freqTable;
}
Also used : FrequencyTableQuery(annis.service.objects.FrequencyTableQuery) QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatrixQueryData(annis.sqlgen.MatrixQueryData) FrequencyTable(annis.service.objects.FrequencyTable) Subject(org.apache.shiro.subject.Subject) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with FrequencyTable

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

the class FrequencyBackgroundJob method call.

@Override
public FrequencyTable call() throws Exception {
    final FrequencyTable t = loadBeans();
    ui.access(new Runnable() {

        @Override
        public void run() {
            panel.showResult(t, query);
        }
    });
    return t;
}
Also used : FrequencyTable(annis.service.objects.FrequencyTable)

Example 3 with FrequencyTable

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

the class FrequencyBackgroundJob method loadBeans.

private FrequencyTable loadBeans() {
    FrequencyTable result = new FrequencyTable();
    WebResource annisResource = Helper.getAnnisWebResource();
    try {
        annisResource = annisResource.path("query").path("search").path("frequency").queryParam("q", Helper.encodeJersey(query.getQuery())).queryParam("corpora", StringUtils.join(query.getCorpora(), ",")).queryParam("fields", query.getFrequencyDefinition().toString());
        result = annisResource.get(FrequencyTable.class);
    } catch (final UniformInterfaceException ex) {
        ui.access(new Runnable() {

            @Override
            public void run() {
                ui.getQueryController().reportServiceException(ex, true);
            }
        });
    } catch (ClientHandlerException ex) {
        log.error("could not execute REST call to query frequency", ex);
    }
    return result;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) FrequencyTable(annis.service.objects.FrequencyTable)

Example 4 with FrequencyTable

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

the class FrequencySqlGenerator method extractData.

@Override
public FrequencyTable extractData(ResultSet rs) throws SQLException, DataAccessException {
    FrequencyTable result = new FrequencyTable();
    ResultSetMetaData meta = rs.getMetaData();
    while (rs.next()) {
        Validate.isTrue(meta.getColumnCount() > 1, "frequency table extractor needs at least 2 columns");
        Validate.isTrue("count".equalsIgnoreCase(meta.getColumnName(meta.getColumnCount())), "last column name must be \"count\"");
        long count = rs.getLong("count");
        String[] tupel = new String[meta.getColumnCount() - 1];
        for (int i = 1; i <= tupel.length; i++) {
            String colVal = rs.getString(i);
            if (colVal == null) {
                tupel[i - 1] = "";
            } else {
                String[] splitted = colVal.split(":", 3);
                if (splitted.length > 0) {
                    colVal = splitted[splitted.length - 1];
                }
                tupel[i - 1] = colVal;
            }
        }
        // end for each column (except last "count" column)
        result.addEntry(new FrequencyTable.Entry(tupel, count));
    }
    return result;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) FrequencyTable(annis.service.objects.FrequencyTable)

Example 5 with FrequencyTable

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

the class FrequencyResultPanel method recreateTable.

private void recreateTable(FrequencyTable table) {
    if (tblResult != null) {
        removeComponent(tblResult);
    }
    tblResult = new Table();
    tblResult.setSizeFull();
    tblResult.setCaption(table.getEntries().size() + " items with a total sum of " + table.getSum() + " (query on " + Joiner.on(", ").join(query.getCorpora()) + ")");
    tblResult.setSelectable(true);
    tblResult.setMultiSelect(false);
    tblResult.addStyleName(Helper.CORPUS_FONT_FORCE);
    if (!table.getEntries().isEmpty()) {
        FrequencyTable.Entry firstEntry = table.getEntries().iterator().next();
        int tupelCount = firstEntry.getTupel().length;
        tblResult.addContainerProperty("rank", Integer.class, -1);
        for (int i = 1; i <= tupelCount; i++) {
            tblResult.addContainerProperty("tupel-" + i, String.class, "");
            FrequencyTableEntry e = query.getFrequencyDefinition().get(i - 1);
            tblResult.setColumnHeader("tupel-" + i, getCaption(e));
        }
        tblResult.addContainerProperty("count", Long.class, -1l);
        int line = 0;
        for (FrequencyTable.Entry e : table.getEntries()) {
            Object[] cells = new Object[tupelCount + 2];
            System.arraycopy(e.getTupel(), 0, cells, 1, tupelCount);
            cells[0] = line + 1;
            cells[cells.length - 1] = e.getCount();
            tblResult.addItem(cells, "entry-" + line++);
        }
    }
    addLexicalSort(tblResult.getContainerDataSource());
    addComponent(tblResult);
    setExpandRatio(tblResult, 1.0f);
}
Also used : FrequencyTable(annis.service.objects.FrequencyTable) Table(com.vaadin.ui.Table) FrequencyTableEntry(annis.service.objects.FrequencyTableEntry) FrequencyTable(annis.service.objects.FrequencyTable)

Aggregations

FrequencyTable (annis.service.objects.FrequencyTable)6 FrequencyTableEntry (annis.service.objects.FrequencyTableEntry)2 QueryData (annis.ql.parser.QueryData)1 FrequencyTableQuery (annis.service.objects.FrequencyTableQuery)1 MatrixQueryData (annis.sqlgen.MatrixQueryData)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)1 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)1 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)1 WebResource (com.sun.jersey.api.client.WebResource)1 FileDownloader (com.vaadin.server.FileDownloader)1 StreamResource (com.vaadin.server.StreamResource)1 Table (com.vaadin.ui.Table)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Subject (org.apache.shiro.subject.Subject)1