|
6 | 6 | #
|
7 | 7 | # Author: Damion Dooley
|
8 | 8 | #
|
| 9 | +# Run this in folder where one wants DataHarmonizer schema to be built, so |
| 10 | +# typically, in some DH web/templates/[schema folder]/, which reads by default |
| 11 | +# a file called oca_bundle.json |
| 12 | +# |
| 13 | +# > python3 ../../../script/oca_to_linkml.py [-i oca_bundle_file_name] |
| 14 | +# |
| 15 | +# Output: |
| 16 | +# schema_core.yaml - the main LinkML upper structure within which slots and enums are added. |
| 17 | +# schema_slots.tsv - the list of column fields |
| 18 | +# schema_enums.tsv - the list of enumerations (code lists) |
| 19 | +# |
| 20 | +# Then in DH context, run "> python3 tabular_to_schema.py" to generate |
| 21 | +# schema.yaml - yaml version of complete LinkML schema for default language |
| 22 | +# schema.json - json version of complete LinkML schema for default language used by DataHarmonizer |
| 23 | +# and for any language locale variants, a language overlay file which is layered on top of the above schema.json file: |
| 24 | +# locales/[i18n locale code]/schema.yaml |
| 25 | +# locales/[i18n locale code]/schema.json |
| 26 | +# |
| 27 | +# DataHarmonizer can load the complete schema.json file directly via |
| 28 | +# "load template" option. However access to multilingual functionality will |
| 29 | +# require adding the complete schema into the schema bundle and menu.js file. |
9 | 30 |
|
10 | 31 | import json
|
11 | 32 | import optparse
|
|
18 | 39 |
|
19 | 40 | ###############################################################################
|
20 | 41 |
|
21 |
| -input_oca_file = 'oca_bundle.json'; |
22 |
| -schema_core_file = 'schema_core.yaml'; |
23 | 42 | warnings = [];
|
24 | 43 | locale_mapping = {}; # Converting OCA language terms to i18n
|
25 | 44 |
|
|
91 | 110 |
|
92 | 111 | def init_parser():
|
93 | 112 | parser = optparse.OptionParser()
|
94 |
| - """ |
| 113 | + |
95 | 114 | parser.add_option(
|
96 |
| - "-m", |
97 |
| - "--menu", |
98 |
| - dest="menu", |
99 |
| - default=False, |
100 |
| - action="store_true", |
101 |
| - help="A flag which indicates menu entries should be generated or updated for a schema's templates (classes).", |
| 115 | + "-i", |
| 116 | + "--input", |
| 117 | + dest="input_oca_file", |
| 118 | + default="oca_bundle.json", |
| 119 | + help="Provide an OCA json bundle file path and name to read.", |
102 | 120 | )
|
103 |
| - """ |
| 121 | + |
104 | 122 | return parser.parse_args();
|
105 | 123 |
|
106 | 124 | def save_tsv(file_name, headers, data):
|
@@ -267,9 +285,11 @@ def writeEnums():
|
267 | 285 | options, args = init_parser();
|
268 | 286 |
|
269 | 287 | # Load OCA schema bundle specification
|
270 |
| -if os.path.isfile(input_oca_file): |
271 |
| - with open(input_oca_file, "r") as f: |
| 288 | +if options.input_oca_file and os.path.isfile(options.input_oca_file): |
| 289 | + with open(options.input_oca_file, "r") as f: |
272 | 290 | oca_obj = json.load(f);
|
| 291 | +else: |
| 292 | + os.exit("- [Input OCA bundle file is required]") |
273 | 293 |
|
274 | 294 | # In parsing input_oca_file, a few attributes are ignored for now in much of
|
275 | 295 | # the structure:
|
|
0 commit comments