# Path: nn_serialization.py
# def load_params(path, params):
#     logging.info("Loading model from file '%s'...", path)
#     pp = numpy.load(path)
#     for k in pp:
#         params[k] = pp[k]
#     path = "%s.pkl" % (path,)
#     logging.info("Loading model from file '%s'...", path)
#     with open(path, 'rb') as fin:
#         data = pickle.load(fin)
#         for k in ['dim_proj_chars', 'char_dict', 'pos_dict', 'word_dict']:
#             params[k] = data[k]
#     return params


from nn_serialization import load_params
import types
    if type(l[0]) == types.ListType:
        ret = []
        for i in l:
#            ret.append(list_to_js(i))
            inner = list_to_js(i)
            inner = 'Float32Array.from({})'.format(inner)
            ret.append(inner)
        return list_to_js(ret)
    l = ','.join([str(i) for i in arr])
    return '[{}]'.format(l)

def dict_to_js(name, d):
    print '{}'.format(name) + '= {'
    for c in d:
      a = c
      v = d[c]
      def escape(p):
        if '\\' in p:
            p = '\\\\'
        if '\'' in p:
            p = '\\\''
        return p
      if type(a) != type(0):
        a = "'" + escape(a) + "'"
      if type(v) != type(0):
        v = "'" + escape(v) + "'"
      print "\t{}: {},".format(a, v)
    print '};'

if __name__ == "__main__":

# Path: nn_serialization.py
# def load_params(path, params):
#     logging.info("Loading model from file '%s'...", path)
#     pp = numpy.load(path)
#     for k in pp:
#         params[k] = pp[k]
#     path = "%s.pkl" % (path,)
#     logging.info("Loading model from file '%s'...", path)
#     with open(path, 'rb') as fin:
#         data = pickle.load(fin)
#         for k in ['dim_proj_chars', 'char_dict', 'pos_dict', 'word_dict']:
#             params[k] = data[k]
#     return params


# Path: export.py
from nn_serialization import load_params
import types

    if type(l[0]) == types.ListType:
        ret = []
        for i in l:
#            ret.append(list_to_js(i))
            inner = list_to_js(i)
            inner = 'Float32Array.from({})'.format(inner)
            ret.append(inner)
        return list_to_js(ret)
    l = ','.join([str(i) for i in arr])
    return '[{}]'.format(l)

def dict_to_js(name, d):
    print '{}'.format(name) + '= {'
    for c in d:
      a = c
      v = d[c]
      def escape(p):
        if '\\' in p:
            p = '\\\\'
        if '\'' in p:
            p = '\\\''
        return p
      if type(a) != type(0):
        a = "'" + escape(a) + "'"
      if type(v) != type(0):
        v = "'" + escape(v) + "'"
      print "\t{}: {},".format(a, v)
    print '};'

if __name__ == "__main__":

   params = load_params("lstm_model.npz", {})