Example usage for edu.stanford.nlp.util StringUtils isNumeric

List of usage examples for edu.stanford.nlp.util StringUtils isNumeric

Introduction

In this page you can find the example usage for edu.stanford.nlp.util StringUtils isNumeric.

Prototype

public static boolean isNumeric(String s) 

Source Link

Document

Given a String the method uses Regex to check if the String only contains numeric characters

Usage

From source file:org.apdplat.qa.api.AskServlet.java

License:Open Source License

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w ww. j  a  v  a  2 s  .c o m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/json;charset=UTF-8");
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");

    String questionStr = request.getParameter("q");
    String n = request.getParameter("n");
    int topN = -1;
    if (n != null && StringUtils.isNumeric(n)) {
        topN = Integer.parseInt(n);
    }
    Question question = null;
    List<CandidateAnswer> candidateAnswers = null;
    if (questionStr != null && questionStr.trim().length() > 3) {
        question = SharedQuestionAnsweringSystem.getInstance().answerQuestion(questionStr);
        if (question != null) {
            candidateAnswers = question.getAllCandidateAnswer();
        }
    }
    LOG.info("" + questionStr);
    try (PrintWriter out = response.getWriter()) {
        String json = JsonGenerator.generate(candidateAnswers, topN);
        out.println(json);
        LOG.info("" + json);
    }
}