Search in sources :

Example 26 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueryServiceImpl method basicSubgraph.

protected SaltProject basicSubgraph(MatchGroup matches, @QueryParam("segmentation") String segmentation, @DefaultValue("0") @QueryParam("left") String leftRaw, @DefaultValue("0") @QueryParam("right") String rightRaw, @DefaultValue("all") @QueryParam("filter") String filterRaw) {
    Subject user = SecurityUtils.getSubject();
    int left = Integer.parseInt(leftRaw);
    int right = Integer.parseInt(rightRaw);
    SubgraphFilter filter = SubgraphFilter.valueOf(filterRaw);
    QueryData data = GraphHelper.createQueryData(matches, queryDao);
    data.addExtension(new AnnotateQueryData(left, right, segmentation, filter));
    Set<String> corpusNames = new TreeSet<>();
    for (Match singleMatch : matches.getMatches()) {
        // collect list of used corpora
        for (java.net.URI u : singleMatch.getSaltIDs()) {
            corpusNames.add(CommonHelper.getCorpusPath(u).get(0));
        }
    }
    for (String c : corpusNames) {
        user.checkPermission("query:subgraph:" + c);
    }
    List<String> corpusNamesList = new LinkedList<>(corpusNames);
    if (data.getCorpusList() == null || data.getCorpusList().isEmpty()) {
        throw new WebApplicationException(Response.Status.BAD_REQUEST.getStatusCode());
    }
    long start = new Date().getTime();
    SaltProject p = queryDao.graph(data);
    long end = new Date().getTime();
    String options = "matches: " + matches.toString() + ", seg: " + segmentation + ", left: " + left + ", right: " + right + ", filter: " + filter;
    logQuery("SUBGRAPH", "", corpusNamesList, end - start, options);
    return p;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatrixQueryData(annis.sqlgen.MatrixQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) SaltProject(org.corpus_tools.salt.common.SaltProject) SubgraphFilter(annis.service.objects.SubgraphFilter) Subject(org.apache.shiro.subject.Subject) LinkedList(java.util.LinkedList) Date(java.util.Date) Match(annis.service.objects.Match) TreeSet(java.util.TreeSet)

Example 27 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueryDaoImpl method graph.

@Override
@Transactional(readOnly = true)
public SaltProject graph(QueryData data) {
    SaltProject p = executeQueryFunction(data, graphSqlGenerator, saltAnnotateExtractor);
    List<MatchGroup> matchGroupExt = data.getExtensions(MatchGroup.class);
    SaltAnnotateExtractor.addMatchInformation(p, matchGroupExt.get(0));
    return p;
}
Also used : MatchGroup(annis.service.objects.MatchGroup) SaltProject(org.corpus_tools.salt.common.SaltProject) Transactional(org.springframework.transaction.annotation.Transactional)

Example 28 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class QueriesGenerator method generateQuery.

private void generateQuery(QueryBuilder queryBuilder) {
    try {
        // retrieve the aql query for analyzing purposes
        String aql = queryBuilder.getAQL();
        // set some necessary extensions for generating complete sql
        QueryData queryData = getQueryDao().parseAQL(aql, this.corpusIds);
        queryData.addExtension(queryBuilder.getLimitOffsetQueryData());
        // retrieve the salt project to analyze
        List<Match> matches = getQueryDao().find(queryData);
        if (matches.isEmpty()) {
            return;
        }
        QueryData matchQueryData = GraphHelper.createQueryData(new MatchGroup(matches), queryDao);
        matchQueryData.addExtension(queryBuilder.getAnnotateQueryData());
        SaltProject saltProject = getQueryDao().graph(matchQueryData);
        queryBuilder.analyzingQuery(saltProject);
        // set the corpus name
        ExampleQuery exampleQuery = queryBuilder.getExampleQuery();
        exampleQuery.setCorpusName(corpusName);
        // copy the example query to the database
        if (exampleQuery.getExampleQuery() != null && !"".equals(exampleQuery.getExampleQuery())) {
            if (getTableInsertSelect().containsKey("example_queries")) {
                Object[] values = new Object[] { exampleQuery.getExampleQuery(), exampleQuery.getDescription(), exampleQuery.getType() == null ? "" : exampleQuery.getType(), exampleQuery.getNodes(), "{}", corpusIds.get(0) };
                int[] argTypes = new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.INTEGER };
                getJdbcTemplate().update("INSERT INTO example_queries(" + getTableInsertSelect().get("example_queries") + ") VALUES(?, ?, ?, ?, ?::text[], ?)", values, argTypes);
                log.info("generated example query: {}", exampleQuery.getExampleQuery());
            }
        } else {
            log.warn("could not generating auto query with {}", queryBuilder.getClass().getName());
        }
    } catch (Exception ex) {
        log.warn("Cannot generate example query", ex);
    }
}
Also used : QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatchGroup(annis.service.objects.MatchGroup) ExampleQuery(annis.examplequeries.ExampleQuery) SaltProject(org.corpus_tools.salt.common.SaltProject) Match(annis.service.objects.Match)

Example 29 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class AbstractResultFetchJob method executeQuery.

/**
 * Asks for salt graphs with a given list of matches {@link MatchGroup}.
 *
 * @param subgraphRes Handles the REST connection with the annis service.
 * @param matches A list of matches. This implies, that the "find" method of
 * the annis-service was executed before.
 * @param left The left context.
 * @param right The right context.
 * @param segmentation restrict results to this segmentations
 * @param filter
 * @return
 */
protected final SaltProject executeQuery(WebResource subgraphRes, MatchGroup matches, int left, int right, String segmentation, SubgraphFilter filter) {
    SaltProject p = null;
    WebResource res = subgraphRes.queryParam("left", "" + left).queryParam("right", "" + right);
    try {
        if (segmentation != null) {
            res = res.queryParam("segmentation", segmentation);
        }
        if (filter != null) {
            res = res.queryParam("filter", filter.name());
        }
        p = res.post(SaltProject.class, matches);
    } catch (UniformInterfaceException ex) {
        log.error(ex.getMessage(), ex);
    }
    return p;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) SaltProject(org.corpus_tools.salt.common.SaltProject)

Example 30 with SaltProject

use of org.corpus_tools.salt.common.SaltProject in project ANNIS by korpling.

the class ResultViewPanel method setQueryResultQueue.

/**
 * Set a new querys in result panel.
 *
 * @param queue holds the salt graph
 * @param q holds the ordinary query
 * @param allMatches All matches.
 */
public void setQueryResultQueue(BlockingQueue<SaltProject> queue, PagedResultQuery q, ArrayList<Match> allMatches) {
    this.projectQueue = queue;
    this.currentQuery = q;
    this.numberOfResults = allMatches.size();
    this.allMatches = allMatches;
    paging.setPageSize(q.getLimit(), false);
    paging.setInfo(q.getQuery());
    resultLayout.removeAllComponents();
    resultPanelList.clear();
    // get the first query result
    SaltProject first = queue.poll();
    Preconditions.checkState(first != null, "There must be already an element in the queue");
    addQueryResult(q, Arrays.asList(first));
}
Also used : SaltProject(org.corpus_tools.salt.common.SaltProject)

Aggregations

SaltProject (org.corpus_tools.salt.common.SaltProject)34 Test (org.junit.Test)11 Match (annis.service.objects.Match)8 WebResource (com.sun.jersey.api.client.WebResource)8 LinkedList (java.util.LinkedList)8 SDocumentGraph (org.corpus_tools.salt.common.SDocumentGraph)8 MatchGroup (annis.service.objects.MatchGroup)7 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)6 ArrayList (java.util.ArrayList)6 SDocument (org.corpus_tools.salt.common.SDocument)6 HashMap (java.util.HashMap)4 SCorpusGraph (org.corpus_tools.salt.common.SCorpusGraph)4 SNode (org.corpus_tools.salt.core.SNode)4 VisualizerInput (annis.libgui.visualizers.VisualizerInput)3 QueryData (annis.ql.parser.QueryData)3 SubgraphFilter (annis.service.objects.SubgraphFilter)3 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)3 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)3 IOException (java.io.IOException)3 AnnisCorpusAccessException (annis.exceptions.AnnisCorpusAccessException)2