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;
}
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;
}
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);
}
}
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;
}
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));
}
Aggregations