Skip to content

Setting variable names to be type-based#27

Merged
jkkummerfeld merged 2 commits intodata-developmentfrom
variable-renaming
Nov 17, 2018
Merged

Setting variable names to be type-based#27
jkkummerfeld merged 2 commits intodata-developmentfrom
variable-renaming

Conversation

@jkkummerfeld
Copy link
Copy Markdown
Owner

GeoQuery variables were just 'varN', this changes them to specify the type and be of the form 'typeN' instead.

@jkkummerfeld
Copy link
Copy Markdown
Owner Author

This involved:

(1) Manually changing the types to match database fields.
(2) Running this code to propagate those changes:

import json

data = json.load(open('geography.json'))

for query in data:
    done = {}
    for variable in query['variables']:
        cname = variable['name']
        vtype = variable['type']
        num = done.get(vtype, -1) + 1
        done[vtype] = num
        nname = vtype + str(num)

        variable['name'] = nname
        for i, sql in enumerate(query['sql']):
            query['sql'][i] = nname.join(sql.split(cname))
        for sentence in query['sentences']:
            sentence['variables'][nname] = sentence['variables'][cname]
            sentence['variables'].pop(cname)
            sentence['text'] = nname.join(sentence['text'].split(cname))

print(json.dumps(data, indent=4, sort_keys=True))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant