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