Search in sources :

Example 1 with AnswerFormatter

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

the class AbstractItemIntentInterpreter method getTrainingData.

@Override
public InputStream getTrainingData(String language) throws UnsupportedLanguageException {
    answerFormatter = new AnswerFormatter(language);
    InputStream trainingData = Skill.class.getClassLoader().getResourceAsStream("train/" + language + "/" + this.getIntentId() + ".txt");
    if (trainingData == null) {
        throw new UnsupportedLanguageException(language);
    }
    return trainingData;
}
Also used : AnswerFormatter(org.openhab.ui.habot.nlp.internal.AnswerFormatter) InputStream(java.io.InputStream)

Example 2 with AnswerFormatter

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

the class HABotResource method greet.

@GET
@RolesAllowed({ Role.USER, Role.ADMIN })
@Path("/greet")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieves a first greeting message from the bot in the specified or configured language.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ChatReply.class), @ApiResponse(code = 500, message = "There is no support for the configured language") })
public Response greet(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language (will use the default if omitted)") String language) {
    final Locale locale = (this.localeProvider != null && this.localeProvider.getLocale() != null) ? this.localeProvider.getLocale() : LocaleUtil.getLocale(language);
    AnswerFormatter answerFormatter = new AnswerFormatter(locale);
    String greeting = answerFormatter.getRandomAnswer("greeting");
    ChatReply reply = new ChatReply(locale);
    reply.setAnswer(greeting);
    return Response.ok(reply).build();
}
Also used : Locale(java.util.Locale) AnswerFormatter(org.openhab.ui.habot.nlp.internal.AnswerFormatter) ChatReply(org.openhab.ui.habot.nlp.ChatReply) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

AnswerFormatter (org.openhab.ui.habot.nlp.internal.AnswerFormatter)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 InputStream (java.io.InputStream)1 Locale (java.util.Locale)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ChatReply (org.openhab.ui.habot.nlp.ChatReply)1