use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method search.
/* These routes are still wip: */
/**
* Search the lucene index.
*
* @param json
* JSON-LD string with search and potential meta
* filters.
*/
@POST
@Path("/search")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String search(String json) {
Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Search index
// Reuse Response
Result kr = new Krill(json).apply(Node.getIndex());
return kr.toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method match.
@GET
@Path("/match/{matchID}")
@Produces(MediaType.APPLICATION_JSON)
public String match(@PathParam("matchID") String id, @Context UriInfo uri) {
Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Get index
KrillIndex index = Node.getIndex();
// Get query parameters
MultivaluedMap<String, String> qp = uri.getQueryParameters();
boolean includeSpans = false, includeHighlights = true, extendToSentence = false, info = false;
// Optional query parameter "info" for more information on the match
if (!_isNull(qp.getFirst("info")))
info = true;
// Optional query parameter "spans" for span information inclusion
if (!_isNull(qp.getFirst("spans"))) {
includeSpans = true;
info = true;
}
;
// Optional query parameter "highlights" for highlight information inclusion
String highlights = qp.getFirst("highlights");
if (highlights != null && _isNull(highlights))
includeHighlights = false;
// Optional query parameter "extended" for sentence expansion
if (!_isNull(qp.getFirst("extended")))
extendToSentence = true;
List<String> foundries = qp.get("foundry");
List<String> layers = qp.get("layer");
try {
// Get match info
return index.getMatchInfo(id, "tokens", info, foundries, layers, includeSpans, includeHighlights, extendToSentence).toJsonString();
}// Nothing found
catch (QueryException qe) {
// Todo: Make Match rely on Response!
kresp.addError(qe.getErrorCode(), qe.getMessage());
}
;
return kresp.toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method getCorpus.
// Return corpus info
@GET
@Path("/corpus")
@Produces(MediaType.APPLICATION_JSON)
public String getCorpus(@Context UriInfo uri) {
ObjectMapper mapper = new ObjectMapper();
// TODO: Accept fields!!!!
final Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// TODO: Statistics should be node fields - not annotations!
// TODO: This is just temporary
KrillIndex ki = Node.getIndex();
ObjectNode obj = mapper.createObjectNode();
obj.put("tokens", ki.numberOf("tokens"));
obj.put("base/texts", ki.numberOf("base/texts"));
obj.put("base/sentences", ki.numberOf("base/sentences"));
obj.put("base/paragraphs", ki.numberOf("base/paragraphs"));
// <legacy>
obj.put("sentences", ki.numberOf("sentences"));
obj.put("paragraphs", ki.numberOf("paragraphs"));
// </legacy>
kresp.addJsonNode("stats", obj);
return kresp.toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method get.
@GET
@Path("/index/{textID}")
@Produces(MediaType.APPLICATION_JSON)
public String get(@PathParam("textID") String uid, @Context UriInfo uri) {
if (DEBUG)
log.trace("Get document with unique identifier {}", uid);
final Response kresp = _initResponse();
if (kresp.hasErrors())
return kresp.toJsonString();
// Get index
index = Node.getIndex();
return index.getDoc(uid).toJsonString();
}
use of de.ids_mannheim.korap.response.Response in project Krill by KorAP.
the class Resource method _initResponse.
private Response _initResponse() {
Response kresp = new Response();
kresp.setNode(Node.getName());
kresp.setListener(Node.getListener());
// Get index
KrillIndex index = Node.getIndex();
if (index == null) {
kresp.addError(601, "Unable to find index");
return kresp;
}
;
kresp.setVersion(index.getVersion());
kresp.setName(index.getName());
return kresp;
}
Aggregations