package org.diagbot.nlp.controller;

import org.diagbot.nlp.participle.ParticipleUtil;
import org.diagbot.nlp.util.DictUtil;
import org.diagbot.nlp.util.NlpCache;
import org.diagbot.pub.api.Response;
import org.diagbot.pub.web.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
@RequestMapping("/participle")
public class ParticipleController extends BaseController {
    {
        listView = "pages/kl/participle/sample";
    }

    @ResponseBody
    @RequestMapping("/split")
    public Response split(String content) throws IOException {
        Response response = new Response();
        long start = System.currentTimeMillis();
        response.setData(ParticipleUtil.participle(content));
        long end = System.currentTimeMillis();
        System.out.println("总耗时:........." + (end - start));
        return response;
    }

    @ResponseBody
    @RequestMapping("/split_and_highlight")
    public Response splitAndHighlight(String content) throws IOException {
        Response response = new Response();
        long start = System.currentTimeMillis();
        response.setData(ParticipleUtil.participleAndHighlight(content));
        long end = System.currentTimeMillis();
        System.out.println("总耗时:........." + (end - start));
        return response;
    }

    @ResponseBody
    @RequestMapping("/write_file")
    public Response writeFile() throws IOException {
        Response response = new Response();
        long start = System.currentTimeMillis();

        String path = this.getClass().getClassLoader().getResource("").getPath();
        DictUtil dictUtil = new DictUtil();
        dictUtil.writeToDict(path);

        NlpCache.createSegmentCache();
        NlpCache.createSynonymCache();
        NlpCache.createClassifyCache();

        long end = System.currentTimeMillis();
        System.out.println("总耗时:........." + (end - start));
        return response;
    }
}
