/** * Get a graph as {@link SaltProject} of a set of Salt IDs. * * @param saltIDs saltIDs must have at least one saltId, more than one id are separated by + or * space * @param leftRaw left context parameter * @param rightRaw right context parameter * @return the graph of this hit. */ @POST @Path("search/subgraph") @Produces({"application/xml", "application/xmi+xml", "application/xmi+binary"}) public SaltProject subgraph(final SubgraphQuery query) { // some robustness stuff if (query == null) { throw new WebApplicationException( Response.status(Response.Status.BAD_REQUEST) .type(MediaType.TEXT_PLAIN) .entity("missing required request body") .build()); } QueryData data = new QueryData(); data.addExtension( new AnnotateQueryData(query.getLeft(), query.getRight(), query.getSegmentationLayer())); Set<String> corpusNames = new TreeSet<String>(); for (SaltURIGroup singleMatch : query.getMatches().getGroups().values()) { // collect list of used corpora and created pseudo QueryNodes for each URI List<QueryNode> pseudoNodes = new ArrayList<QueryNode>(singleMatch.getUris().size()); for (java.net.URI u : singleMatch.getUris()) { pseudoNodes.add(new QueryNode()); corpusNames.add(CommonHelper.getCorpusPath(u).get(0)); } data.addAlternative(pseudoNodes); } Subject user = SecurityUtils.getSubject(); for (String c : corpusNames) { user.checkPermission("query:subgraph:" + c); } List<String> corpusNamesList = new LinkedList<String>(corpusNames); List<Long> corpusIDs = annisDao.mapCorpusNamesToIds(corpusNamesList); data.setCorpusList(corpusIDs); data.addExtension(query.getMatches()); long start = new Date().getTime(); SaltProject p = annisDao.graph(data); long end = new Date().getTime(); logQuery("SUBGRAPH", "", corpusNamesList, end - start); return p; }
@GET @Path("search/find") @Produces("application/xml") public List<Match> find( @QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @DefaultValue("0") @QueryParam("offset") String offsetRaw, @DefaultValue("10") @QueryParam("limit") String limitRaw) throws IOException { requiredParameter(query, "q", "AnnisQL query"); requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names"); Subject user = SecurityUtils.getSubject(); List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames); for (String c : corpusNames) { user.checkPermission("query:find:" + c); } int offset = Integer.parseInt(offsetRaw); int limit = Integer.parseInt(limitRaw); QueryData data = queryDataFromParameters(query, rawCorpusNames); data.setCorpusConfiguration(annisDao.getCorpusConfiguration()); data.addExtension(new LimitOffsetQueryData(offset, limit)); long start = new Date().getTime(); List<Match> matches = annisDao.find(data); long end = new Date().getTime(); logQuery("FIND", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start); return matches; }
/** Get result as matrix in WEKA (ARFF) format. */ @GET @Path("search/matrix") @Produces("text/plain") public String matrix( @QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @QueryParam("metakeys") String rawMetaKeys) { requiredParameter(query, "q", "AnnisQL query"); requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names"); Subject user = SecurityUtils.getSubject(); List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames); for (String c : corpusNames) { user.checkPermission("query:matrix:" + c); } QueryData data = queryDataFromParameters(query, rawCorpusNames); MatrixQueryData ext = new MatrixQueryData(); if (rawMetaKeys != null) { ext.setMetaKeys(splitMatrixKeysFromRaw(rawMetaKeys)); } data.addExtension(ext); long start = new Date().getTime(); List<AnnotatedMatch> matches = annisDao.matrix(data); long end = new Date().getTime(); logQuery("MATRIX", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start); if (matches.isEmpty()) { return "(empty)"; } else { return WekaHelper.exportAsArff(matches); } }
@GET @Path("search/annotate") @Produces("application/xml") public SaltProject annotate( @QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @DefaultValue("0") @QueryParam("offset") String offsetRaw, @DefaultValue("10") @QueryParam("limit") String limitRaw, @DefaultValue("5") @QueryParam("left") String leftRaw, @DefaultValue("5") @QueryParam("right") String rightRaw, @QueryParam("seglayer") String segmentationLayer) throws IOException { requiredParameter(query, "q", "AnnisQL query"); requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names"); Subject user = SecurityUtils.getSubject(); List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames); for (String c : corpusNames) { user.checkPermission("query:annotate:" + c); } int offset = Integer.parseInt(offsetRaw); int limit = Integer.parseInt(limitRaw); int left = Math.min(maxContext, Integer.parseInt(leftRaw)); int right = Math.min(maxContext, Integer.parseInt(rightRaw)); QueryData data = queryDataFromParameters(query, rawCorpusNames); String logParameters = createAnnotateLogParameters(left, right, offset, limit); data.addExtension(new LimitOffsetQueryData(offset, limit)); data.addExtension(new AnnotateQueryData(left, right, segmentationLayer)); long start = new Date().getTime(); SaltProject p = annisDao.annotate(data); long end = new Date().getTime(); logQuery( "ANNOTATE", query, splitCorpusNamesFromRaw(rawCorpusNames), end - start, logParameters); return p; }