Search in sources :

Example 1 with MatrixQueryData

use of annis.sqlgen.MatrixQueryData in project ANNIS by korpling.

the class QueryServiceImpl method matrix.

/**
 * Get result as matrix in WEKA (ARFF) format.
 * @param query
 * @param rawCorpusNames
 * @param rawMetaKeys
 * @param rawCsv
 * @return
 */
@GET
@Path("search/matrix")
@Produces("text/plain")
public StreamingOutput matrix(@QueryParam("q") final String query, @QueryParam("corpora") final String rawCorpusNames, @QueryParam("metakeys") String rawMetaKeys, @DefaultValue("false") @QueryParam("csv") String rawCsv) {
    requiredParameter(query, "q", "AnnisQL query");
    requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
    final boolean outputCsv = Boolean.parseBoolean(rawCsv);
    Subject user = SecurityUtils.getSubject();
    List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
    for (String c : corpusNames) {
        user.checkPermission("query:matrix:" + c);
    }
    final QueryData data = queryDataFromParameters(query, rawCorpusNames);
    MatrixQueryData ext = new MatrixQueryData();
    if (rawMetaKeys != null) {
        ext.setMetaKeys(splitMatrixKeysFromRaw(rawMetaKeys));
    }
    if (ext.getMetaKeys() != null && ext.getMetaKeys().isEmpty()) {
        ext.setMetaKeys(null);
    }
    data.addExtension(ext);
    StreamingOutput result = new StreamingOutput() {

        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            long start = new Date().getTime();
            queryDao.matrix(data, outputCsv, output);
            long end = new Date().getTime();
            logQuery("MATRIX", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start);
        }
    };
    return result;
}
Also used : MatrixQueryData(annis.sqlgen.MatrixQueryData) QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatrixQueryData(annis.sqlgen.MatrixQueryData) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) 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)

Aggregations

QueryData (annis.ql.parser.QueryData)1 MatrixQueryData (annis.sqlgen.MatrixQueryData)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 Subject (org.apache.shiro.subject.Subject)1