package org.diagbot.bigdata.controller;

import org.diagbot.bigdata.work.AlgorithmCore;
import org.diagbot.common.push.bean.ResponseData;
import org.diagbot.common.push.bean.SearchData;
import org.diagbot.nlp.util.Constants;
import org.diagbot.pub.api.Response;
import org.diagbot.pub.web.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/algorithm")
public class AlgorithmController extends BaseController {
    private String[] negative_words = Constants.negative_words;

    @RequestMapping(value = "/page_neural")
    @ResponseBody
    public Response<ResponseData> neuralData(HttpServletRequest request, SearchData searchData) throws Exception {
        return algorithm(request, searchData);
    }

    @RequestMapping(value = "/neural", method = RequestMethod.POST)
    @ResponseBody
    public Response<ResponseData> bayesPageData(HttpServletRequest request, @RequestBody SearchData searchData) throws Exception {
        return algorithm(request, searchData);
    }

    public Response<ResponseData> algorithm(HttpServletRequest request, SearchData searchData) throws Exception {
        Response<ResponseData> response = new Response();
        AlgorithmCore core = new AlgorithmCore();
        ResponseData responseData = core.algorithm(request, searchData, null);
        response.setData(responseData);
        return response;
    }
}
