changeset 67:34d0f1187b0f norm_json

add arabic normalization type to normalize_string JSON method.
author casties
date Thu, 10 Dec 2015 17:24:08 -0500
parents a241cef14561
children aa8a0578fbc6
files src/main/java/de/mpiwg/itgroup/ismi/servlets/jsonmethods/JSONNormString.java
diffstat 1 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/servlets/jsonmethods/JSONNormString.java	Thu Dec 10 12:53:10 2015 -0500
+++ b/src/main/java/de/mpiwg/itgroup/ismi/servlets/jsonmethods/JSONNormString.java	Thu Dec 10 17:24:08 2015 -0500
@@ -7,8 +7,10 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.StringUtils;
 import org.json.JSONObject;
 import org.mpi.openmind.cache.WrapperService;
+import org.mpi.openmind.repository.utils.ArabicNormalizerUtils;
 import org.mpi.openmind.repository.utils.ArabicTranslitNormalizer;
 
 public class JSONNormString extends AbstractServletJSONMethod {
@@ -20,12 +22,30 @@
 
         try {
             String text = request.getParameter("text");
-
-            if (text != null) {
-                String normText = ArabicTranslitNormalizer.normalize(text);
-                json.put("text", text);
-                json.put("normalization_type", "arabic_translit");
-                json.put("normalized_text", normText);
+            String type = request.getParameter("type");
+            if (StringUtils.isEmpty(type)) {
+                json.put(RESPONSE, EXCEPTION);
+                json.put(RESPONSE_INFO, "Normalization type parameter missing.");                
+                PrintWriter out = response.getWriter();
+                out.print(json.toString());
+                response.sendError(HttpServletResponse.SC_BAD_REQUEST, 
+                        "Normalization type parameter missing.");
+                return;
+            }
+            if (type.equalsIgnoreCase("arabic_translit")) {
+                if (text != null) {
+                    String normText = ArabicTranslitNormalizer.normalize(text);
+                    json.put("text", text);
+                    json.put("normalization_type", "arabic_translit");
+                    json.put("normalized_text", normText);
+                }
+            } else if (type.equalsIgnoreCase("arabic")) {
+                if (text != null) {
+                    String normText = ArabicNormalizerUtils.normalize(text);
+                    json.put("text", text);
+                    json.put("normalization_type", type);
+                    json.put("normalized_text", normText);
+                }
             }
 
         } catch (Exception e) {