# HG changeset patch # User casties # Date 1449786248 18000 # Node ID 34d0f1187b0f3a315c1d83bb0ec9c1b70c83df39 # Parent a241cef1456174c6af3362a585d2ea87ae0552f1 add arabic normalization type to normalize_string JSON method. diff -r a241cef14561 -r 34d0f1187b0f src/main/java/de/mpiwg/itgroup/ismi/servlets/jsonmethods/JSONNormString.java --- 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) {