Search in sources :

Example 1 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) Krill(de.ids_mannheim.korap.Krill) Result(de.ids_mannheim.korap.response.Result) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 2 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) QueryException(de.ids_mannheim.korap.util.QueryException) KrillIndex(de.ids_mannheim.korap.KrillIndex) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KrillIndex(de.ids_mannheim.korap.KrillIndex) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Response

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();
}
Also used : Response(de.ids_mannheim.korap.response.Response) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Response

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;
}
Also used : Response(de.ids_mannheim.korap.response.Response) KrillIndex(de.ids_mannheim.korap.KrillIndex)

Aggregations

Response (de.ids_mannheim.korap.response.Response)14 Produces (javax.ws.rs.Produces)9 Path (javax.ws.rs.Path)7 Consumes (javax.ws.rs.Consumes)4 GET (javax.ws.rs.GET)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Krill (de.ids_mannheim.korap.Krill)3 KrillIndex (de.ids_mannheim.korap.KrillIndex)3 POST (javax.ws.rs.POST)3 Test (org.junit.Test)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 PUT (javax.ws.rs.PUT)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ComboPooledDataSource (com.mchange.v2.c3p0.ComboPooledDataSource)1 KrillCollection (de.ids_mannheim.korap.KrillCollection)1 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)1 MatchCollector (de.ids_mannheim.korap.response.MatchCollector)1 Result (de.ids_mannheim.korap.response.Result)1 MatchCollectorDB (de.ids_mannheim.korap.response.collector.MatchCollectorDB)1 QueryException (de.ids_mannheim.korap.util.QueryException)1