package net.northking.cctp.scriptcase.api.nlp;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.exception.PlatformRuntimeException;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.nlp.service.NLPService;
import net.northking.cctp.scriptcase.enums.ScriptCaseAppError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "自然语言处理（nlp）")
@RequestMapping("/pub/nlp")
public class NLPPubCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(NLPPubCtrl.class);

    @Autowired
    private NLPService service;

    @ApiOperation(value = "对文本进行分词")
    @RequiredPermissions({"ui-saveScript","ui-updateScript"})
    @GetMapping(value = "/lexer")
    @ResponseBody
    public ResultWrapper<List<String>> lexer(@RequestParam(value = "text") String text) {
        logger.debug("lexer text:{}",text);
        if (!StringUtils.hasText(text)) {
            throw new PlatformRuntimeException(ScriptCaseAppError.TEXT_IS_NULL);
        }
        ResultWrapper<List<String>> wrapper = new ResultWrapper<>();
        List<String> list = service.getWordList(text);
        return wrapper.success(list);
    }
}
