From 8248681ae6e610de76cc2d3678decf8a6876e8c6 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Thu, 21 Nov 2019 08:10:32 +0100 Subject: [PATCH] chg: [tools] a quick-and-dirty script to dump missing expanded fields --- tools/fix.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tools/fix.py diff --git a/tools/fix.py b/tools/fix.py new file mode 100644 index 0000000..e740775 --- /dev/null +++ b/tools/fix.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import json +import argparse + +argParser = argparse.ArgumentParser(description='Fixing taxonomies with missing fields') +argParser.add_argument('-f', help='Taxonomy file to fix') +argParser.add_argument('-e', action='store_true', help='Fix missing expanded values at predicate level') +argParser.add_argument('-j', action='store_true', help='Dump partial JSON') +args = argParser.parse_args() + + +with open(args.f, 'rb') as f: + taxonomy = json.load(f) + for predicate_value in taxonomy['values']: + predicate = predicate_value['predicate'] + output = [] + for a in predicate_value['entry']: + if 'value' in a and 'expanded' in a: + continue + elif 'value' in a and 'expanded' not in a: + if args.e: + a['expanded'] = a['value'] + output.append(a) + if args.j: + print(json.dumps(output))