Index: WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py
===================================================================
--- WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py	(revision 2992)
+++ WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py	(revision 2997)
@@ -16,4 +16,5 @@
     def set_trace():
         pass
+
 
 mtool = context.portal_membership
@@ -39,26 +40,28 @@
     response.write("%s<br>\n\r" % s)
 
-def getLGAs():
-    voc = getattr(context.portal_vocabularies,'local_gov_areas')
-    states = []
-    lgas  = []
-    d = {}
-    for k,v in voc.items():
-        parts = v.split(' / ')
-        if len(parts) == 1:
-            state = parts[0].lower()
-            lga = ""
-        elif len(parts) == 2:
-            state = parts[0].lower()
-            lga = "_".join(parts[1].lower().split())
-        else:
-            continue
-        if state not in states:
-            states.append(state)
-        if lga not in lgas:
-            lgas.append(lga)
-        d[k] = v
-    return (d,states,lgas)
+# def getLGAs():
+#     voc = getattr(context.portal_vocabularies,'local_gov_areas')
+#     states = []
+#     lgas  = []
+#     d = {}
+#     for k,v in voc.items():
+#         parts = v.split(' / ')
+#         if len(parts) == 1:
+#             state = parts[0].lower()
+#             lga = ""
+#         elif len(parts) == 2:
+#             state = parts[0].lower()
+#             lga = "_".join(parts[1].lower().split())
+#         else:
+#             continue
+#         if state not in states:
+#             states.append(state)
+#         if lga not in lgas:
+#             lgas.append(lga)
+#         d[k] = v
+#     return (d,states,lgas)
 
+difference = context.waeup_tool.difference
+re_split = context.waeup_tool.re_split
 #logger.info('')
 student_records = context.students_catalog()
@@ -68,53 +71,54 @@
 commit_after = 100
 logger.info('started to fix %d records in students_catalog' % total)
-d,states,lgas = getLGAs()
+mapping = context.waeup_tool.getStatesLgas()
+states = mapping['states']
+lgas = mapping['lgas']
+words_dict = mapping['word_dict']
 d = {}
 for student_record in student_records:
     # skip record without lga value
+    count += 1
     if not student_record.lga:
         continue
-    #skip records with correct lga key value
-    if student_record.lga.find('_') > -1:
-        continue
+    # if student_record.lga.find(' ') < 0:
+    #     continue
     if student_record.lga.startswith('no state'):
-        logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))
+        #logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))
         continue
     #rwrite("%s: %s" % (student_record.id,student_record.lga))
-    sl = student_record.lga.split(' / ')
-    if len(sl) != 2:
-        sl = student_record.lga.split('/')
-        if len(sl) != 2:
-            logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))
-            #rwrite("wrong size %s: %s" % (student_record.id,sl))
-            continue
-    state = sl[0].lower().strip()
-    lga = sl[1].lower().strip()
-    if not lga or not state:
-        logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))
-        continue
-    count += 1
-    if len(d) and not len(d)  % commit_after:
-        logger.info("found %d correct state/lga combinations of %d so far" % (len(d),count))
-    if state in states:
-        found = False
-        while True:
-            if lga in lgas:
-                found = True
+    words = student_record.lga 
+    if len(words.split(' / ')) == 2:
+        words = words.replace(' / ',' ')
+    words = re_split('[^a-zA-Z0-9/]',words)
+    lga_words = []
+    for word in words:
+        if word:
+            lga_words += word.lower(),
+    lga_words.sort()
+    # state = sl[0].lower().strip()
+    # state = '_'.join(state.split())
+    # lga = sl[1].lower().strip()
+    # if not lga or not state:
+    #     logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))
+    #     continue
+    state_lga = ''
+    while not state_lga:
+        for k,l in words_dict.items():
+            if lga_words == l:
+                state_lga = k
                 break
-            lga = lga.replace(' ','-')
-            if lga in lgas:
-                found = True
-            break
-        if found:
-            #msg = "found %s for %s" % (state_lga,student_record.id)
-            state_lga = state + '_' + lga
+        break
+    if state_lga:
+        if state_lga != student_record.lga:
+            msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id)
+            #rwrite(msg)
             d[student_record.id] = state_lga
-        #else:
-            #msg = "no '%s' '%s' for %s" % (state,lga,student_record.id)
-            #rwrite(msg)
-    #else:
-        #msg = "no state '%s' '%s' for %s" % (state,lga,student_record.id)
-        #rwrite(msg)
-    # if count > 150:
+            if len(d) and not len(d)  % commit_after:
+                logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
+        else:
+            msg = "already corrected %s : %s for %s " % (state_lga,student_record.lga,student_record.id)
+    else:
+        msg = "no '%s' for %s" % (lga_words,student_record.id)
+    # if count > 2000:
     #     break
 to_edit = len(d)
