Skip to content

Commit

Permalink
name field used as index in enums
Browse files Browse the repository at this point in the history
  • Loading branch information
ddooley committed Aug 21, 2024
1 parent 0656d6a commit 9c376d4
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions script/tabular_to_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ def set_enums(enum_path, schema, locale_schemas, export_format, warnings):
reader = csv.DictReader(tsvfile, dialect='excel-tab');

enumerations = schema['enums'];

name = ''; # running title for chunks of enumeration rows
name = ''; # running name for chunks of enumeration rows
choice_path = [];
enum = {};

Expand All @@ -368,11 +367,14 @@ def set_enums(enum_path, schema, locale_schemas, export_format, warnings):
row[field] = row[field].strip();

# Each enumeration begins with a row that provides the name of the enum.
if row.get('name','') > '':
# subsequent rows may not have a name.
if row.get('name','') > '' or row.get('title','') > '':

# Process default language title
name = row.get('name');
title = row.get('title');
if not name: # For enumerations that don't have separate name field
name = title;
if not (name in enumerations):
enum = {
'name': name,
Expand Down Expand Up @@ -401,15 +403,15 @@ def set_enums(enum_path, schema, locale_schemas, export_format, warnings):
# Loop scans through columns until it gets a value
for depth in range(1,6):
menu_x = 'menu_' + str(depth);
choice_value = row.get(menu_x);
choice_text = row.get(menu_x);
# Here there is a menu item to process
if choice_value > '':
if choice_text > '':
del choice_path[depth-1:] # Menu path always points to parent

description = row.get('description','');
meaning = row.get('meaning','');

choice = {'text' : choice_value}
choice = {'text' : choice_text}
if description > '': choice['description'] = description;
if meaning > '': choice['meaning'] = meaning;

Expand All @@ -420,20 +422,19 @@ def set_enums(enum_path, schema, locale_schemas, export_format, warnings):
if len(choice_path) > 0:
choice['is_a'] = choice_path[-1]; # Last item in path

enum['permissible_values'][choice_value] = choice;
choice_path.append(choice_value);
enum['permissible_values'][choice_text] = choice;
choice_path.append(choice_text);

for lcode in locale_schemas.keys():
translation = row.get(menu_x + '_' + lcode, '');

if translation > '' and translation != choice['text']:

local_choice = {'title': translation}
description = row.get(description + '_' + lcode, '');
if description:
local_choice['description': description];

locale_schemas[lcode]['enums'][name]['permissible_values'][choice_value] = local_choice;
locale_schemas[lcode]['enums'][name]['permissible_values'][choice_text] = local_choice;

break;

Expand Down

0 comments on commit 9c376d4

Please sign in to comment.