diff software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/Normalize.java @ 19:4a3641ae14d2

Erstellung
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Wed, 09 Nov 2011 15:32:05 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/software/mpdl-services/mpiwg-mpdl-lt-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/lt/Normalize.java	Wed Nov 09 15:32:05 2011 +0100
@@ -0,0 +1,68 @@
+package de.mpg.mpiwg.berlin.mpdl.servlets.lt;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
+import de.mpg.mpiwg.berlin.mpdl.lt.text.norm.Normalizer;
+
+public class Normalize extends HttpServlet {
+  private static final long serialVersionUID = 1L;
+
+  public Normalize() {
+    super();
+  }
+
+  public void init(ServletConfig config) throws ServletException  {
+    super.init(config);
+  }
+
+  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    request.setCharacterEncoding("utf-8");
+    response.setCharacterEncoding("utf-8");
+    String inputString = request.getParameter("inputString");
+    String language = request.getParameter("language");
+    String method = request.getParameter("method");
+    String typeStr = request.getParameter("type");
+    if (language == null)
+      language = "eng";
+    if (method == null)
+      method = "norm";
+    String[] methods = method.split(" ");
+    if (typeStr == null)
+      typeStr = "display";
+    int type = Normalizer.DISPLAY;
+    if (typeStr.equals("dictionary"))
+      type = Normalizer.DICTIONARY;
+    else if (typeStr.equals("search"))
+      type = Normalizer.SEARCH;
+    String result = null;
+    try {
+      response.setContentType("text/html");
+      PrintWriter out = response.getWriter();
+      if (inputString == null || inputString.isEmpty()) {
+        out.print("request parameter \"inputString\" is empty. Please specify \"inputString\"");
+        out.close();
+        return;
+      }
+      Normalizer normalizer = new Normalizer(methods, language);
+      normalizer.setNormMode(type);
+      result = normalizer.normalize(inputString);
+      if (result != null)
+        out.print(result);
+      out.close();
+    } catch (ApplicationException e) { 
+      throw new ServletException(e);
+    }
+  }
+
+  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+    
+  }  
+}