Blame view

egs/gale_arabic/s5b/local/prepare_lexicon.py 779 Bytes
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #!/usr/bin/env python3
  
  # Copyright      2018  Ashish Arora
  # Apache 2.0
  
  # This script prepares lexicon.
  
  import argparse
  import os
  
  parser = argparse.ArgumentParser(description="""Creates the list of characters and words in lexicon""")
  args = parser.parse_args()
  
  ### main ###
  lex = {}
  text_path = os.path.join('data','local', 'lexicon_data', 'processed_lexicon')
  with open(text_path, 'r', encoding='utf-8') as f:
      for line in f:
          line = line.strip()
          characters = list(line)
          characters = " ".join(['V' if char == '*' else char for char in characters])
          lex[line] = characters
  
  with open(os.path.join('data','local','dict', 'lexicon.txt'), 'w', encoding='utf-8') as fp:
      for key in sorted(lex):
          fp.write(key + "  " + lex[key] + "
  ")