Search in sources :

Example 1 with OpenNLPInterpreter

use of org.openhab.ui.habot.nlp.internal.OpenNLPInterpreter in project habot by ghys.

the class HABotResource method chat.

@POST
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/chat")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Send a query to HABot to interpret.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ChatReply.class), @ApiResponse(code = 500, message = "An interpretation error occured") })
public Response chat(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @ApiParam(value = "human language query", required = true) String query) throws Exception {
    final Locale locale = (this.localeProvider != null && this.localeProvider.getLocale() != null) ? this.localeProvider.getLocale() : LocaleUtil.getLocale(language);
    // interpret
    OpenNLPInterpreter hli = (OpenNLPInterpreter) voiceManager.getHLI(OPENNLP_HLI);
    if (hli == null) {
        throw new InterpretationException("The OpenNLP interpreter is not available");
    }
    ChatReply reply = hli.reply(locale, query);
    return Response.ok(reply).build();
}
Also used : Locale(java.util.Locale) OpenNLPInterpreter(org.openhab.ui.habot.nlp.internal.OpenNLPInterpreter) InterpretationException(org.eclipse.smarthome.core.voice.text.InterpretationException) ChatReply(org.openhab.ui.habot.nlp.ChatReply) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Locale (java.util.Locale)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 InterpretationException (org.eclipse.smarthome.core.voice.text.InterpretationException)1 ChatReply (org.openhab.ui.habot.nlp.ChatReply)1 OpenNLPInterpreter (org.openhab.ui.habot.nlp.internal.OpenNLPInterpreter)1