use of annis.service.objects.FrequencyTable 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.FrequencyTable in project ANNIS by korpling.
the class FrequencyBackgroundJob method call.
@Override
public FrequencyTable call() throws Exception {
final FrequencyTable t = loadBeans();
ui.access(new Runnable() {
@Override
public void run() {
panel.showResult(t, query);
}
});
return t;
}
use of annis.service.objects.FrequencyTable in project ANNIS by korpling.
the class FrequencyBackgroundJob method loadBeans.
private FrequencyTable loadBeans() {
FrequencyTable result = new FrequencyTable();
WebResource annisResource = Helper.getAnnisWebResource();
try {
annisResource = annisResource.path("query").path("search").path("frequency").queryParam("q", Helper.encodeJersey(query.getQuery())).queryParam("corpora", StringUtils.join(query.getCorpora(), ",")).queryParam("fields", query.getFrequencyDefinition().toString());
result = annisResource.get(FrequencyTable.class);
} catch (final UniformInterfaceException ex) {
ui.access(new Runnable() {
@Override
public void run() {
ui.getQueryController().reportServiceException(ex, true);
}
});
} catch (ClientHandlerException ex) {
log.error("could not execute REST call to query frequency", ex);
}
return result;
}
use of annis.service.objects.FrequencyTable in project ANNIS by korpling.
the class FrequencySqlGenerator method extractData.
@Override
public FrequencyTable extractData(ResultSet rs) throws SQLException, DataAccessException {
FrequencyTable result = new FrequencyTable();
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
Validate.isTrue(meta.getColumnCount() > 1, "frequency table extractor needs at least 2 columns");
Validate.isTrue("count".equalsIgnoreCase(meta.getColumnName(meta.getColumnCount())), "last column name must be \"count\"");
long count = rs.getLong("count");
String[] tupel = new String[meta.getColumnCount() - 1];
for (int i = 1; i <= tupel.length; i++) {
String colVal = rs.getString(i);
if (colVal == null) {
tupel[i - 1] = "";
} else {
String[] splitted = colVal.split(":", 3);
if (splitted.length > 0) {
colVal = splitted[splitted.length - 1];
}
tupel[i - 1] = colVal;
}
}
// end for each column (except last "count" column)
result.addEntry(new FrequencyTable.Entry(tupel, count));
}
return result;
}
use of annis.service.objects.FrequencyTable in project ANNIS by korpling.
the class FrequencyResultPanel method recreateTable.
private void recreateTable(FrequencyTable table) {
if (tblResult != null) {
removeComponent(tblResult);
}
tblResult = new Table();
tblResult.setSizeFull();
tblResult.setCaption(table.getEntries().size() + " items with a total sum of " + table.getSum() + " (query on " + Joiner.on(", ").join(query.getCorpora()) + ")");
tblResult.setSelectable(true);
tblResult.setMultiSelect(false);
tblResult.addStyleName(Helper.CORPUS_FONT_FORCE);
if (!table.getEntries().isEmpty()) {
FrequencyTable.Entry firstEntry = table.getEntries().iterator().next();
int tupelCount = firstEntry.getTupel().length;
tblResult.addContainerProperty("rank", Integer.class, -1);
for (int i = 1; i <= tupelCount; i++) {
tblResult.addContainerProperty("tupel-" + i, String.class, "");
FrequencyTableEntry e = query.getFrequencyDefinition().get(i - 1);
tblResult.setColumnHeader("tupel-" + i, getCaption(e));
}
tblResult.addContainerProperty("count", Long.class, -1l);
int line = 0;
for (FrequencyTable.Entry e : table.getEntries()) {
Object[] cells = new Object[tupelCount + 2];
System.arraycopy(e.getTupel(), 0, cells, 1, tupelCount);
cells[0] = line + 1;
cells[cells.length - 1] = e.getCount();
tblResult.addItem(cells, "entry-" + line++);
}
}
addLexicalSort(tblResult.getContainerDataSource());
addComponent(tblResult);
setExpandRatio(tblResult, 1.0f);
}
Aggregations