#!/usr/bin/python2.7
"""
Makes dictionary file from mozc
(dictionary*.txt in https://github.com/google/mozc/tree/master/src/data/dictionary_oss/)

command line example: tools/make_dictionary_file.py dictionary*.txt

The path to the output file: app/japanese_name_location_dict.txt
"""
import sys

def check_number(id1, id2, numbers):
    """
    checks id1 == id2 (id1 and id2 are in numbers)
    """
    return id1 in numbers and id1 == id2


def make_dictionary(input_file_names, output_file_name, numbers):
    """
    Makes dictionary.

    Args:
        input_file_names: a list of file names

    Output format:
        kanji '\t' yomigana(hiragana) '\n'
        kanji '\t' yomigana(hiragana) '\n' ...
    """
    yomigana_list = []
    for input_file_name in input_file_names:
        with open(input_file_name, 'r') as input_file:
            for line in input_file:
                line = line.rstrip()
                splited_line = line.split('\t')
                id1 = int(splited_line[1])
                id2 = int(splited_line[2])
                if (check_number(id1, id2, numbers)):
                    yomigana = splited_line[0]
                    kanji = splited_line[4]
                    yomigana_list.append(kanji + '\t' + yomigana + '\n')

    with open(output_file_name, 'w') as output_file:
        output_file.writelines(yomigana_list)


def make_jp_name_location_dictionary(input_file_names):
    """
    Makes japanese name and location dictionary.
    """
    # 1845: id for given name in mozc dictionary
    # 1846: id for family name in mozc dictionary
    # 1847 ~ 1850: ids for location in mozc dictionary
    # if we want to get given name, we need to get results (id1 == id2 == 1845)
    numbers = [1845, 1846, 1847, 1848, 1849, 1850]
    make_dictionary(input_file_names, 'app/japanese_name_location_dict.txt', numbers)


def main():
    dictionaries = sys.argv[1:]
    make_jp_name_location_dictionary(dictionaries)


if __name__ == '__main__':
    main()

@@ -14,20 +14,20 @@
 thon2.7%0A
+%0A
 %22%22%22
-%0A
 Makes di
@@ -53,196 +53,168 @@
 mozc
-%0A(dictionary*.txt in https://github.com/google/mozc/tree/master/src/data/dictionary_oss/)%0A%0Acommand line example: tools/make_dictionary_file.py dictionary*.txt%0A%0AThe path to the output file:
+ files.%0A%0AHow to use this tool:%0A  $ git clone https://github.com/google/mozc.git%0A  $ tools/make_dictionary_file.py mozc/src/data/dictionary_oss/dictionary*.txt %3E
  app
@@ -250,16 +250,17 @@
 txt%0A%22%22%22%0A
+%0A
 import s
@@ -267,155 +267,8 @@
 ys%0A%0A
-def check_number(id1, id2, numbers):%0A    %22%22%22%0A    checks id1 == id2 (id1 and id2 are in numbers)%0A    %22%22%22%0A    return id1 in numbers and id1 == id2%0A%0A%0A
 def 
@@ -332,29 +332,24 @@
 rs):%0A    %22%22%22
-%0A    
 Makes dictio
@@ -352,16 +352,50 @@
 ctionary
+ and writes it to output_file_name
 .%0A%0A    A
@@ -777,26 +777,24 @@
        split
-ed
 _line = line
@@ -833,26 +833,24 @@
  = int(split
-ed
 _line%5B1%5D)%0A  
@@ -874,26 +874,24 @@
  = int(split
-ed
 _line%5B2%5D)%0A  
@@ -907,43 +907,89 @@
     
+ 
- if (check_number(
+# e.g. (id1 == id2 == 1845) means %22given name%22%0A                if 
 id1
-,
  i
-d2,
+n
  numbers
 )):%0A
@@ -988,10 +988,23 @@
 bers
-))
+ and id1 == id2
 :%0A  
@@ -1033,26 +1033,24 @@
 gana = split
-ed
 _line%5B0%5D%0A   
@@ -1079,18 +1079,16 @@
  = split
-ed
 _line%5B4%5D
@@ -1326,21 +1326,16 @@
 %0A    %22%22%22
-%0A    
 Makes ja
@@ -1370,21 +1370,16 @@
 tionary.
-%0A    
 %22%22%22%0A    
@@ -1399,24 +1399,25 @@
 r given name
+s
  in mozc dic
@@ -1450,24 +1450,25 @@
  family name
+s
  in mozc dic
@@ -1511,16 +1511,22 @@
 ocation 
+names 
 in mozc 
@@ -1540,88 +1540,8 @@
 ary%0A
-    # if we want to get given name, we need to get results (id1 == id2 == 1845)%0A
     

Apply review comments from mikahashimoto-add-createDict branch and apply some clean ups.