@@ -0,0 +1,1656 @@
+%0Apackage com.google.sps.servlets;%0A%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.Collection;%0Aimport java.util.List;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/**%0A * Given a tweet or sentence, the servlet will extract salient terms from those%0A * and store them in a list.%0A */%0A@WebServlet(%22/keyword%22)%0Apublic class KeywordServlet extends HttpServlet %7B%0A%0A  private static final List%3CString%3E tweets = new ArrayList%3C%3E();%0A  private static final List%3CString%3E terms = Arrays.asList(%22Black Lives Matter%22, %22COVID-19%22);%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    // TODO: Extract saliency%0A    String json = mustacheJsonBuilder(terms);%0A    response.getWriter().println(json);%0A  %7D%0A%0A  @Override%0A  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    final String tweet = request.getParameter(%22keyword-sentence%22);%0A    if (tweet != null && !tweet.equals(%22%22)) %7B%0A      tweets.add(request.getParameter(%22keyword-sentence%22));%0A    %7D%0A    response.sendRedirect(%22/main.html%22);%0A  %7D%0A%0A  /**%0A   * Generates and returns a JSON usable by Mustache.%0A   */%0A  private String mustacheJsonBuilder(Collection%3CString%3E toJson) %7B%0A    String builder = %22%7B%5C%22keywords%5C%22: %5B%22;%0A    for (String term : toJson) %7B%0A      builder += %22%7B%5C%22term%5C%22: %5C%22%22 + term + %22%5C%22%7D,%22;%0A    %7D%0A%0A    // Remove extra comma at the end.%0A    builder = builder.substring(0, builder.length() - 1) + %22%5D%7D%22;%0A    return builder;%0A  %7D%0A%0A%7D

Add servlet to query Keywords