continued to work with the json file

main
onebigear 2 years ago
parent 8b94ab0e3a
commit ba3e73e751

@ -11,38 +11,24 @@ data = json.load(open('dict.json', 'r'))
# the essence of the program is to introduce noise to disrupt
# the mapping relation of the dictionary.
# learning rules is also essential to machine learning, which
for i in data:
print(i["letter"])
# modify numeral for letter and update json file
i["numeral"] = "updated value nul"
print(i["numeral"])
for i in data:
print(i)
noise = np.random.randint(1,3)
# how to save to json file
for i in data:
i["numeral"] = int(i["numeral"])
i["numeral"] += noise
# the problem is, dictionary keys are saved as strings
# using numerical update can apply?
# write to a new json file
with open('new.json','w') as w_file:
json.dump(data,w_file, indent=4)
# test with an existing corpus
# try a chinese dictionary and a latin dictionary
# and any other types of dictionary structures, remix!
# current rule
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
# add noise to rule
# there is some noise
noise = np.random.randint(1,3)
# loop through keys, add noise to key value
# say noise is 2, every key adds 2
# dict = { '3':'silk-1', '4':'silk-2', '5':'silk-3',
# '6':'earth-1', '7':'earth-2', '8':'earth-3',
# '9':'water-1', '10':'water-2', '11':'water-3',
# }
# then when i query the dictionary again,
# the rule is disrupted, the message is disrupted
# the rule is disrupted by adding a simple number

Loading…
Cancel
Save