# Path: tupa/model_util.py
# def save_json(filename, d):
#     """
#     Save dictionary to JSON file
#     :param filename: file to write to
#     :param d: dictionary to save
#     """
#     remove_existing(filename)
#     print("Saving to '%s'." % filename)
#     with open(filename, "w") as h:
#         json.dump(d, h, default=jsonify)
# 
# Path: tupa/scripts/export.py
# def load_model(filename):
#     model = Model(filename=filename)
#     model.load()
#     return model


from configargparse import ArgParser
from ucca.textutil import get_vocab
from tupa.model_util import save_json
from tupa.scripts.export import load_model



def decode(vocab, value):
    if isinstance(value, int):
        try:
            return vocab.strings[value]
        except KeyError:
            pass
    return value


def main():
    argparser = ArgParser(description="Load TUPA model and save the features enumeration as a text JSON file.")
    argparser.add_argument("models", nargs="+", help="model file basename(s) to load")
    argparser.add_argument("-s", "--suffix", default=".enum.json", help="filename suffix to append")
    argparser.add_argument("-l", "--lang", help="use spaCy model to decode numeric IDs")
    args = argparser.parse_args()
    for filename in args.models:

# Path: tupa/model_util.py
# def save_json(filename, d):
#     """
#     Save dictionary to JSON file
#     :param filename: file to write to
#     :param d: dictionary to save
#     """
#     remove_existing(filename)
#     print("Saving to '%s'." % filename)
#     with open(filename, "w") as h:
#         json.dump(d, h, default=jsonify)
# 
# Path: tupa/scripts/export.py
# def load_model(filename):
#     model = Model(filename=filename)
#     model.load()
#     return model


# Path: tupa/scripts/enum_to_json.py
from configargparse import ArgParser
from ucca.textutil import get_vocab
from tupa.model_util import save_json
from tupa.scripts.export import load_model




def decode(vocab, value):
    if isinstance(value, int):
        try:
            return vocab.strings[value]
        except KeyError:
            pass
    return value


def main():
    argparser = ArgParser(description="Load TUPA model and save the features enumeration as a text JSON file.")
    argparser.add_argument("models", nargs="+", help="model file basename(s) to load")
    argparser.add_argument("-s", "--suffix", default=".enum.json", help="filename suffix to append")
    argparser.add_argument("-l", "--lang", help="use spaCy model to decode numeric IDs")
    args = argparser.parse_args()
    for filename in args.models:

        model = load_model(filename)