-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdgmDict-jreplace.py
More file actions
61 lines (43 loc) · 2.1 KB
/
pdgmDict-jreplace.py
File metadata and controls
61 lines (43 loc) · 2.1 KB
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
48
49
50
51
52
53
54
#!/usr/local/bin/python3
'''
Script to be used as template for replacing one term in json file
with another. This script's present form replaces an old subfamily
term with another. Opens dict with 'oldfam: newfam'. Then for each
languages file reads old fam and replaces it with newfam
AS OPPOSED TO pdgmDict-jreplace-old.py THIS VERSION GETS JSON INFO
WITH json.load, BUT REPLACES OLD INFO USING ftext.replace(a,b),
THUS PRESERVING JSON FORMAT
'''
import shutil
import json
# For single lang:
#language = input('Type language name: ')
#languagenames = (language, )
# For adhoc test set:
#languagenames = ('beja-alm', 'beja-hud', 'beja-rei', 'beja-rop', 'beja-van', 'beja-wed')
#sample = input('Type sample name: ')
# For corpus:
languagenames = ('aari', 'afar', 'alaaba', 'alagwa', 'akkadian-ob', 'arabic', 'arbore', 'awngi', 'bayso', 'beja-alm', 'beja-hud', 'beja-rei', 'beja-rop', 'beja-van', 'beja-wed', 'berber-ghadames', 'bilin', 'boni-jara', 'boni-kijee-bala', 'boni-kilii', 'burji', 'burunge', 'coptic-sahidic', 'dahalo', 'dhaasanac', 'dizi', 'egyptian-middle', 'elmolo', 'gawwada', 'gedeo', 'geez', 'hadiyya', 'hausa', 'hdi', 'hebrew', 'iraqw', 'kambaata', 'kemant', 'khamtanga', 'koorete', 'maale', 'mubi', 'oromo', 'rendille', 'saho', 'shinassha', 'sidaama', 'somali', 'syriac', 'tsamakko', 'wolaytta', 'yaaku', 'yemsa')
with open('AAMA-subfam.json') as f:
subfams = f.read()
repDict = json.loads(subfams)
for lang in languagenames:
print(str('LANG: ' + lang))
lfile = str('../aama-data/data/' + lang + '/' + lang + '-pdgms.json')
bckfile = str('../aama-data/data/' + lang + '/' + lang + '-pdgms-bck.json')
shutil.copy(lfile, bckfile)
jdata = json.load(open(lfile))
oldfam = jdata['subfamily']
print(str('old subfamily = ' + oldfam))
#lfile.close
newfam = repDict[oldfam]
print(str('new subfamily = ' + newfam))
with open(lfile) as f:
ftext = f.read()
ftext2 = ftext.replace(oldfam, newfam)
#print(str(ftext2))
file = open(lfile, "w")
file.write(ftext2)
file.close
#f.write(str(ftext2))
#f.close()