#!/usr/bin/env python

import argparse

from dictlearn.vocab import Vocabulary

def main():
  parser = argparse.ArgumentParser("Builds a dictionary")
  parser.add_argument("--top_k", type=int, help="Top most frequent words to leave")
  parser.add_argument("text", help="The text to use")
  parser.add_argument("vocab", help="Destination")
  args = parser.parse_args()

  vocab = Vocabulary.build(args.text, args.top_k)
  vocab.save(args.vocab)

if __name__ == "__main__":
    main()

@@ -16,16 +16,28 @@
 python%0A%0A
+import h5py%0A
 import a
@@ -97,16 +97,18 @@
 main():%0A
+  
   parser
@@ -157,16 +157,18 @@
 onary%22)%0A
+  
   parser
@@ -239,24 +239,26 @@
  to leave%22)%0A
+  
   parser.add
@@ -299,16 +299,18 @@
 o use%22)%0A
+  
   parser
@@ -352,16 +352,18 @@
 ation%22)%0A
+  
   args =
@@ -384,16 +384,171 @@
 args()%0A%0A
+    if args.text.endswith('.h5'):%0A        with h5py.File(args.text) as h5_file:%0A            text = h5_file%5B'text'%5D%5B:%5D%0A    else:%0A        text = args.text%0A  
   vocab 
@@ -566,21 +566,16 @@
 y.build(
-args.
 text, ar
@@ -584,16 +584,18 @@
 .top_k)%0A
+  
   vocab.

support hdf5 input of SQuAD-like format