66import argparse
77
88parser = argparse .ArgumentParser ()
9- parser .add_argument ('-o' , ' --output' , type = str , help = ' Output file name' )
9+ parser .add_argument ("-o" , " --output" , type = str , help = " Output file name" )
1010args = parser .parse_args ()
1111
1212if args .output is None :
13- print (' Error: Output file path not provided.' )
13+ print (" Error: Output file path not provided." )
1414 exit (1 )
1515
1616output_file = args .output
17- vocab_file = ' ../vocabulary/seedEmbeddingVocab.txt'
17+ vocab_file = " ../vocabulary/seedEmbeddingVocab.txt"
1818
1919# Define headers and opening/closing of map
2020header = """\
@@ -44,7 +44,7 @@ class Vocabulary {
4444
4545"""
4646
47- opening = ' \n const std::map<std::string, IR2Vec::Vector> Vocabulary::vocabulary = {\n '
47+ opening = " \n const std::map<std::string, IR2Vec::Vector> Vocabulary::vocabulary = {\n "
4848closing = """\
4949 };
5050} // namespace IR2Vec
@@ -53,24 +53,24 @@ class Vocabulary {
5353"""
5454
5555try :
56- with open (output_file , 'w' ) as fw :
56+ with open (output_file , "w" ) as fw :
5757 fw .write (header )
58- with open (vocab_file , 'r' ) as fr :
58+ with open (vocab_file , "r" ) as fr :
5959 # Write vector declarations to the output file
6060 for line in fr .readlines ():
61- key , val = line .strip ().split (':' )
62- e = val .find (']' )
63- fw .write (f' const IR2Vec::Vector { key } _vector = {{ { val [1 :e ]} }};\n ' )
64-
61+ key , val = line .strip ().split (":" )
62+ e = val .find ("]" )
63+ fw .write (f" const IR2Vec::Vector { key } _vector = {{ { val [1 :e ]} }};\n " )
64+
6565 fw .write (opening )
66- with open (vocab_file , 'r' ) as fr :
66+ with open (vocab_file , "r" ) as fr :
6767 # Write map entries to the output file
6868 for line in fr .readlines ():
69- key , _ = line .strip ().split (':' )
69+ key , _ = line .strip ().split (":" )
7070 fw .write (f' {{ "{ key } ", { key } _vector }},\n ' )
7171 fw .write (closing )
72-
73- print (f' Generated { output_file } ' )
72+
73+ print (f" Generated { output_file } " )
7474
7575except FileNotFoundError :
7676 print (f"Error: Vocabulary file '{ vocab_file } ' not found." )
0 commit comments