# HG changeset patch # User casties # Date 1431532703 0 # Node ID ac466a164b61d884c60c0dbde03c69bbc2950f97 # Parent c009ce2e60be34bf49edba720b973843bdae53b6 new arabic translit normalizer works now. diff -r c009ce2e60be -r ac466a164b61 src/main/java/org/mpi/openmind/repository/utils/NormalizerUtils.java --- a/src/main/java/org/mpi/openmind/repository/utils/NormalizerUtils.java Tue May 12 15:39:29 2015 +0000 +++ b/src/main/java/org/mpi/openmind/repository/utils/NormalizerUtils.java Wed May 13 15:58:23 2015 +0000 @@ -244,8 +244,11 @@ wildCardCharMap.put("Z", ZList); } + public static String normalize(String w) { + return ArabicTranslitNormalizer.normalize(w); + } - public static String normalize(String w){ + public static String old_normalize(String w){ if(StringUtils.isEmpty(w)) return w; diff -r c009ce2e60be -r ac466a164b61 src/main/java/org/mpi/openmind/scripts/NormalizeOW.java --- a/src/main/java/org/mpi/openmind/scripts/NormalizeOW.java Tue May 12 15:39:29 2015 +0000 +++ b/src/main/java/org/mpi/openmind/scripts/NormalizeOW.java Wed May 13 15:58:23 2015 +0000 @@ -2,6 +2,7 @@ import java.sql.Connection; import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -10,12 +11,15 @@ import org.mpi.openmind.repository.utils.ArabicNormalizerUtils; import org.mpi.openmind.repository.utils.ArabicTranslitNormalizer; -import org.mpi.openmind.repository.utils.NormalizerUtils; public class NormalizeOW { - public static void execute(String type, String dbUser, String dbPw) { + public static void execute(String type, String dbUser, String dbPw, boolean modify) { try { - System.out.println("Normalizing own values for all: " + type +"S."); + if (modify) { + System.out.println("Fixing normalized own values for: " + type); + } else { + System.out.println("Showing normalized own values for: " + type); + } System.out.println("INFO: only the CURRENT_VERSION of the nodes will be affected."); Connection conn; @@ -26,7 +30,7 @@ Map selectedMap = select(conn, type); System.out.println("Number of nodes=" + selectedMap.size()); - change(conn, selectedMap); + change(conn, selectedMap, modify); System.out.println("End"); conn.close(); @@ -42,30 +46,52 @@ } - public static void change(Connection conn, Map map){ - String s = new String(); - for(Long id : map.keySet()){ - try { - String[] ows = map.get(id); - String ow = ows[0]; - String oldNormalizedOW = ows[1]; - String oldNormalizedArabicOW = ows[2]; - String normalizedOW = ArabicTranslitNormalizer.normalize(ow); - String normalizedArabicOW = ArabicNormalizerUtils.normalize(ow); - if (normalizedOW != null && !normalizedOW.equals(oldNormalizedOW)) { - System.out.println("normOW changes ("+id+"): old="+oldNormalizedOW+" new="+normalizedOW); - } - Statement st = conn.createStatement(); - /* st.executeUpdate("UPDATE node SET normalized_own_value='" + normalizedOW + "' WHERE row_id='"+ id +"'"); + public static void change(Connection conn, Map map, boolean modify){ + String s = new String(); + int cnt = 0; + PreparedStatement st = null; + if (modify) { + try { + st = conn.prepareStatement("UPDATE node SET normalized_own_value = ?, normalized_arabic_own_value = ? WHERE row_id = ?"); + } catch (SQLException e) { + System.err.println(e); + return; + } + } + for(Long id : map.keySet()){ + cnt += 1; + String[] ows = map.get(id); + String ow = ows[0]; + String oldNormalizedOW = ows[1]; + String oldNormalizedArabicOW = ows[2]; + String normalizedOW = ArabicTranslitNormalizer.normalize(ow); + String normalizedArabicOW = ArabicNormalizerUtils.normalize(ow); + if (normalizedOW != null && !normalizedOW.equals(oldNormalizedOW)) { + System.out.println("normOW changes (#"+cnt+" @"+id+"): old="+oldNormalizedOW+" new="+normalizedOW); + } + if (normalizedArabicOW != null && !normalizedArabicOW.equals(oldNormalizedArabicOW)) { + System.out.println("normArabicOW changes (#"+cnt+" @"+id+"): old="+oldNormalizedArabicOW+" new="+normalizedArabicOW); + } + if (modify) { + try { + st.setString(1, normalizedOW); + st.setString(2, normalizedArabicOW); + st.setString(3, id.toString()); + st.executeUpdate(); + + /* Statement st = conn.createStatement(); + st.executeUpdate("UPDATE node SET normalized_own_value='" + normalizedOW + "' WHERE row_id='"+ id +"'"); s = "UPDATE node SET normalized_arabic_own_value='" + normalizedArabicOW + "' WHERE row_id='"+ id +"'"; //System.out.println(s); st.executeUpdate(s); - */ - } catch (SQLException e) { - System.err.println(s); - e.printStackTrace(); - } - } + */ + } catch (SQLException e) { + System.err.println(s); + e.printStackTrace(); + } + } + //if (cnt > 100) break; // FIXME: testing + } } public static Map select(Connection conn, String type){ @@ -80,6 +106,7 @@ try { Statement st = conn.createStatement(); + System.out.println(" fetching rows..."); ResultSet rs = st.executeQuery(query); while (rs.next()) { String id = rs.getString("row_id"); @@ -102,9 +129,9 @@ String user = args[1]; String pw = (args.length == 3) ? args[2] : null; if (args[0].equalsIgnoreCase("fix")) { - //rc = repair(user, pw); + execute("all", user, pw, true); } else { - execute("all", user, pw); + execute("all", user, pw, false); } } else { System.out.println("Parameter/s not found! Should be: mode(SHOW/FIX), mysql_user, mysql_password");