-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanRawVariableGroupsTree.py
47 lines (28 loc) · 1.14 KB
/
cleanRawVariableGroupsTree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
name: createDictionaryOfVariableGroups.py
date: 2/12/2014
@author: Misha
description: Converts entries of rawVariableGroupsTree where {variableName:None} to variableName
"""
import numpy as np
import cPickle as cp
def parseTree(currentDict):
if type(currentDict) == str: return
# if all values are None
if np.array([el is None for el in currentDict.values()]).all():
return map(str.upper, map(str, currentDict.keys())) # convert elements to str and then to uppercase
else:
for k, v in currentDict.iteritems():
if type(v) == dict:
currentDict[k] = parseTree(v)
return currentDict
if __name__ == "__main__":
# define variables
pathToData = '../data/'
rawTree = cp.load(open(pathToData + 'rawVariableGroupsTree.pickle'))
# fill out cognateVariables dict
for letter in rawTree:
print 'processing letter', letter
rawTree[letter] = parseTree(rawTree[letter])
cp.dump(rawTree, open(pathToData + 'rawVariableGroupsTree-cleaned.pickle', 'w'))