use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.
the class ListCorpusSqlHelper method mapRow.
public AnnisCorpus mapRow(ResultSet rs, int rowNum) throws SQLException {
AnnisCorpus corpus = new AnnisCorpus();
corpus.setId(rs.getLong("id"));
corpus.setName(rs.getString("name"));
corpus.setTextCount(rs.getInt("text"));
corpus.setTokenCount(rs.getInt("tokens"));
try {
corpus.setSourcePath(rs.getString("source_path"));
} catch (SQLException ex) {
log.debug(null, ex);
}
return corpus;
}
use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.
the class SearchView method getMappedCorpora.
/**
* Takes a list of raw corpus names as given by the #c parameter and returns a
* list of corpus names that are known to exist. It also replaces alias names
* with the real corpus names.
*
* @param originalNames
* @return
*/
private Set<String> getMappedCorpora(List<String> originalNames) {
WebResource rootRes = Helper.getAnnisWebResource();
Set<String> mappedNames = new HashSet<>();
// iterate over given corpora and map names if necessary
for (String selectedCorpusName : originalNames) {
// get the real corpus descriptions by the name (which could be an alias)
try {
List<AnnisCorpus> corporaByName = rootRes.path("query").path("corpora").path(urlPathEscape.escape(selectedCorpusName)).get(new GenericType<List<AnnisCorpus>>() {
});
if (corporaByName != null && !corporaByName.isEmpty()) {
for (AnnisCorpus c : corporaByName) {
mappedNames.add(c.getName());
}
}
} catch (ClientHandlerException ex) {
String msg = "alias mapping does not work for alias: " + selectedCorpusName;
log.error(msg, ex);
Notification.show(msg, Notification.Type.TRAY_NOTIFICATION);
}
}
return mappedNames;
}
use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.
the class CorpusManagement method fetchFromService.
public void fetchFromService() throws CriticalServiceQueryException, ServiceQueryException {
if (webResourceProvider != null) {
corpora.clear();
try {
WebResource rootRes = webResourceProvider.getWebResource();
List<AnnisCorpus> corporaList = rootRes.path("query").path("corpora").get(new GenericType<List<AnnisCorpus>>() {
});
for (AnnisCorpus c : corporaList) {
corpora.put(c.getName(), c);
}
} catch (ClientHandlerException ex) {
log.error(null, ex);
throw new ServiceQueryException("Service not available: " + ex.getLocalizedMessage());
} catch (UniformInterfaceException ex) {
if (ex.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode()) {
throw new CriticalServiceQueryException("You are not authorized to get the corpus list.");
} else {
log.error(null, ex);
throw new ServiceQueryException("Remote exception: " + ex.getLocalizedMessage());
}
}
}
}
use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.
the class AcceptanceTest method runKickstarter.
@BeforeClass
public static void runKickstarter() {
try {
runner = new KickstartRunner(WEB_PORT, SERVICE_PORT);
runner.startService();
runner.startJetty();
// get all installed corpora
for (AnnisCorpus c : runner.getCorpora()) {
corpora.add(c.getName());
}
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("takesScreenshot", true);
driver = new PhantomJSDriver(caps);
driver.manage().window().setSize(new Dimension(1024, 768));
} catch (Exception ex) {
log.error(null, ex);
runner = null;
}
}
use of annis.service.objects.AnnisCorpus in project ANNIS by korpling.
the class SearchView method evaluateCitation.
public void evaluateCitation(String relativeUri) {
Matcher m = citationPattern.matcher(relativeUri);
if (m.matches()) {
// AQL
String aql = "";
if (m.group(1) != null) {
aql = m.group(1);
}
// CIDS
Set<String> selectedCorpora = new HashSet<>();
if (m.group(2) != null) {
String[] cids = m.group(2).split(",");
selectedCorpora.addAll(Arrays.asList(cids));
}
// filter by actually avaible user corpora in order not to get any exception later
WebResource res = Helper.getAnnisWebResource();
List<AnnisCorpus> userCorpora = res.path("query").path("corpora").get(new AnnisCorpusListType());
LinkedList<String> userCorporaStrings = new LinkedList<>();
for (AnnisCorpus c : userCorpora) {
userCorporaStrings.add(c.getName());
}
selectedCorpora.retainAll(userCorporaStrings);
// CLEFT and CRIGHT
if (m.group(4) != null && m.group(6) != null) {
int cleft = 0;
int cright = 0;
try {
cleft = Integer.parseInt(m.group(4));
cright = Integer.parseInt(m.group(6));
} catch (NumberFormatException ex) {
log.error("could not parse context value", ex);
}
ui.getQueryController().setQuery(new PagedResultQuery(cleft, cright, 0, 10, null, aql, selectedCorpora));
} else {
ui.getQueryController().setQuery(new Query(aql, selectedCorpora));
}
// remove all currently openend sub-windows
Set<Window> all = new HashSet<>(ui.getWindows());
for (Window w : all) {
ui.removeWindow(w);
}
} else {
Notification.show("Invalid citation", Notification.Type.WARNING_MESSAGE);
}
}
Aggregations