Search in sources :

Example 1 with FrequencyTableQuery

use of annis.service.objects.FrequencyTableQuery 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 FrequencyTableQuery

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

the class QueryController method executeFrequency.

public void executeFrequency(FrequencyQueryPanel panel) {
    // kill old request
    Future freqFuture = state.getExecutedTasks().get(QueryUIState.QueryType.FREQUENCY);
    if (freqFuture != null && !freqFuture.isDone()) {
        freqFuture.cancel(true);
    }
    if ("".equals(state.getAql().getValue())) {
        Notification.show("Empty query", Notification.Type.WARNING_MESSAGE);
        panel.showQueryDefinitionPanel();
        return;
    } else if (state.getSelectedCorpora().getValue().isEmpty()) {
        Notification.show("Please select a corpus", Notification.Type.WARNING_MESSAGE);
        panel.showQueryDefinitionPanel();
        return;
    }
    BeanContainer<Integer, UserGeneratedFrequencyEntry> container = state.getFrequencyTableDefinition();
    FrequencyTableQuery freqDefinition = new FrequencyTableQuery();
    for (Integer id : container.getItemIds()) {
        UserGeneratedFrequencyEntry userGen = container.getItem(id).getBean();
        freqDefinition.add(userGen.toFrequencyTableEntry());
    }
    // additionally add meta data columns
    for (String m : state.getFrequencyMetaData().getValue()) {
        FrequencyTableEntry entry = new FrequencyTableEntry();
        entry.setType(FrequencyTableEntryType.meta);
        entry.setKey(m);
        freqDefinition.add(entry);
    }
    FrequencyQuery query = QueryGenerator.frequency().query(state.getAql().getValue()).corpora(state.getSelectedCorpora().getValue()).def(freqDefinition).build();
    addHistoryEntry(query);
    FrequencyBackgroundJob job = new FrequencyBackgroundJob(ui, query, panel);
    freqFuture = Background.call(job);
    state.getExecutedTasks().put(QueryUIState.QueryType.FREQUENCY, freqFuture);
}
Also used : FrequencyTableQuery(annis.service.objects.FrequencyTableQuery) FrequencyQuery(annis.gui.objects.FrequencyQuery) UserGeneratedFrequencyEntry(annis.gui.frequency.UserGeneratedFrequencyEntry) Future(java.util.concurrent.Future) FrequencyBackgroundJob(annis.gui.controller.FrequencyBackgroundJob) FrequencyTableEntry(annis.service.objects.FrequencyTableEntry)

Example 3 with FrequencyTableQuery

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

the class FrequencySqlGenerator method fromClause.

@Override
public String fromClause(QueryData queryData, List<QueryNode> alternative, String indent) {
    FrequencyTableQuery ext;
    List<FrequencyTableQuery> freqQueryData = queryData.getExtensions(FrequencyTableQuery.class);
    Validate.notNull(freqQueryData);
    Validate.notEmpty(freqQueryData);
    ext = freqQueryData.get(0);
    Multimap<FrequencyTableEntry, String> conditions = conditionsForEntries(ext, queryData, alternative);
    StringBuilder sb = new StringBuilder();
    sb.append(indent).append("(\n");
    sb.append(indent);
    sb.append(getSolutionSqlGenerator().toSql(queryData, indent + TABSTOP));
    sb.append(indent).append(") AS solutions\n");
    int i = 1;
    Iterator<FrequencyTableEntry> itEntry = ext.iterator();
    while (itEntry.hasNext()) {
        FrequencyTableEntry e = itEntry.next();
        sb.append(indent).append(TABSTOP);
        sb.append("LEFT JOIN ");
        String tableSql;
        if (e.getType() == FrequencyTableEntryType.meta) {
            tableSql = "corpus_annotation";
        } else {
            tableSql = SelectedFactsFromClauseGenerator.inheritedFactTables(queryData.getCorpusList(), indent);
        }
        sb.append(tableSql);
        sb.append(" AS v").append(i);
        sb.append(" ON (");
        sb.append(Joiner.on(" AND ").join(conditions.get(e)));
        sb.append(")\n");
        i++;
    }
    return sb.toString();
}
Also used : FrequencyTableQuery(annis.service.objects.FrequencyTableQuery) FrequencyTableEntry(annis.service.objects.FrequencyTableEntry)

Example 4 with FrequencyTableQuery

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

the class FrequencySqlGenerator method selectClause.

@Override
public String selectClause(QueryData queryData, List<QueryNode> alternative, String indent) {
    TableAccessStrategy tas = tables(null);
    FrequencyTableQuery ext;
    List<FrequencyTableQuery> freqQueryData = queryData.getExtensions(FrequencyTableQuery.class);
    Validate.notNull(freqQueryData);
    Validate.notEmpty(freqQueryData);
    ext = freqQueryData.get(0);
    StringBuilder sb = new StringBuilder();
    int i = 1;
    for (FrequencyTableEntry e : ext) {
        if (e.getType() == FrequencyTableEntryType.annotation) {
            sb.append("v").append(i).append(".").append(tas.columnName(NODE_ANNOTATION_TABLE, "qannotext"));
        } else if (e.getType() == FrequencyTableEntryType.span) {
            sb.append("('annis:tok:' || ").append("v").append(i).append(".").append(tas.columnName(NODE_TABLE, "span)"));
        } else if (e.getType() == FrequencyTableEntryType.meta) {
            sb.append("('annis_meta:'").append(" || COALESCE(v").append(i).append(".").append("namespace").append(", '')").append(" || v").append(i).append(".").append("\"name\"").append(" || ':'").append(" || v").append(i).append(".").append("\"value\")");
        }
        sb.append(" AS value").append(i).append(", ");
        i++;
    }
    sb.append("count(*) AS \"count\"");
    return sb.toString();
}
Also used : FrequencyTableQuery(annis.service.objects.FrequencyTableQuery) FrequencyTableEntry(annis.service.objects.FrequencyTableEntry)

Example 5 with FrequencyTableQuery

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

the class FrequencySqlGenerator method groupByAttributes.

@Override
public String groupByAttributes(QueryData queryData, List<QueryNode> alternative) {
    FrequencyTableQuery ext;
    List<FrequencyTableQuery> freqQueryData = queryData.getExtensions(FrequencyTableQuery.class);
    Validate.notNull(freqQueryData);
    Validate.notEmpty(freqQueryData);
    ext = freqQueryData.get(0);
    StringBuilder sb = new StringBuilder();
    for (int i = 1; i <= ext.size(); i++) {
        sb.append("value").append(i);
        if (i < ext.size()) {
            sb.append(", ");
        }
    }
    return sb.toString();
}
Also used : FrequencyTableQuery(annis.service.objects.FrequencyTableQuery)

Aggregations

FrequencyTableQuery (annis.service.objects.FrequencyTableQuery)5 FrequencyTableEntry (annis.service.objects.FrequencyTableEntry)3 FrequencyBackgroundJob (annis.gui.controller.FrequencyBackgroundJob)1 UserGeneratedFrequencyEntry (annis.gui.frequency.UserGeneratedFrequencyEntry)1 FrequencyQuery (annis.gui.objects.FrequencyQuery)1 QueryData (annis.ql.parser.QueryData)1 FrequencyTable (annis.service.objects.FrequencyTable)1 MatrixQueryData (annis.sqlgen.MatrixQueryData)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)1 Date (java.util.Date)1 Future (java.util.concurrent.Future)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