package com.google.musicanalysis.site;

import com.google.cloud.language.v1.Document;
import com.google.cloud.language.v1.Document.Type;
import com.google.cloud.language.v1.LanguageServiceClient;
import com.google.cloud.language.v1.Sentiment;
import com.google.musicanalysis.api.perspective.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/api/perspective")
public class PerspectiveServlet extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException {

    // Instantiates a client
    try (LanguageServiceClient language = LanguageServiceClient.create()) {

      // The text to analyze
      String text = "Hello, world!";
      Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();

      // Detects the sentiment of the text
      Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();

      System.out.printf("Text: %s%n", text);
      System.out.printf("Sentiment: %s, %s%n", sentiment.getScore(), sentiment.getMagnitude());
    }

    PerspectiveRequest request;
    ArrayList<String> attributes =
        new ArrayList<>(
            Arrays.asList(
                "TOXICITY",
                "IDENTITY_ATTACK",
                "INSULT",
                "PROFANITY",
                "THREAT",
                "SEXUALLY_EXPLICIT",
                "FLIRTATION"));
    request = new PerspectiveRequest("I love you.", attributes);
    res.getWriter().println(request.getResponse());
  }
}

@@ -37,211 +37,8 @@
 e;%0A%0A
-import com.google.cloud.language.v1.Document;%0Aimport com.google.cloud.language.v1.Document.Type;%0Aimport com.google.cloud.language.v1.LanguageServiceClient;%0Aimport com.google.cloud.language.v1.Sentiment;%0A
 impo
@@ -601,550 +601,8 @@
  %7B%0A%0A
-    // Instantiates a client%0A    try (LanguageServiceClient language = LanguageServiceClient.create()) %7B%0A%0A      // The text to analyze%0A      String text = %22Hello, world!%22;%0A      Document doc = Document.newBuilder().setContent(text).setType(Type.PLAIN_TEXT).build();%0A%0A      // Detects the sentiment of the text%0A      Sentiment sentiment = language.analyzeSentiment(doc).getDocumentSentiment();%0A%0A      System.out.printf(%22Text: %25s%25n%22, text);%0A      System.out.printf(%22Sentiment: %25s, %25s%25n%22, sentiment.getScore(), sentiment.getMagnitude());%0A    %7D%0A%0A
     

fix perspective