renamed files

worked on program
int and str is a problem
list comprehension is a different thing while working with json
main
onebigear 2 years ago
parent ca656ecf35
commit d83167c953

@ -1,30 +0,0 @@
[
{
"letter": "silk-1",
"radical": "silk",
"numeral": "1"
},
{
"letter": "silk-2",
"radical": "silk",
"numeral": "2"
},
{
"letter": "silk-3",
"radical": "silk",
"numeral": "3"
},
{
"letter": "earth-1",
"radical": "earth",
"numeral": "4"
}
]

@ -1,37 +1,82 @@
# prototype to translate a system to text into dictionary
# as a type of structured text
'''
Development Notes
JSON is a common format used to represent structured text.
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.
When the rule is disrupted, when I query the dictionary again,
the message is disrupted.
The rule is disrupted by linear arithemetic operation,
are there more disruptive and complex rules?
Prototype to translate a system to text into dictionary
as a type of structured text
str int conversion is important to debug the program
why is it that noise is perceived as adverse?
'''
import numpy as np
import json
# what is the proper way to store radicals with dictionary?
# use json
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
# perform message decryption process via this mini corpus
# "no" field is similar to ascii/morse code/unicode coding protocols
# original message identified by "no" field, no 2 & 3
# first wrd
data = json.load(open('dict.json', 'r'))
# disrupted message idenfified by "no" field
# 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
data = json.load(open('seed.json', 'r'))
print("before disrupting, the message is: ")
for i in data:
print(i)
if i["no"] == "2":
print(i["glyph"] + " " + i["radical"] )
if i["no"] == "3":
print(i["glyph"] + " " + i["radical"] )
# write as a function, input are codes, output are a {} of glyphs
noise = np.random.randint(1,3)
for i in data:
i["numeral"] = int(i["numeral"])
i["numeral"] += noise
i["no"] = int(i["no"])
i["no"] += noise
# write to a new json file
with open('new.json','w') as w_file:
with open('noised.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!
print("after disrupting, the message is: ")
# current rule
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
# use noised json to decrypt
# then when i query the dictionary again,
# the rule is disrupted, the message is disrupted
# the rule is disrupted by adding a simple number
# are there more disruptive and complex rules?
noise_data = json.load(open('noised.json','r'))
for i in noise_data:
print(i)
print(type(i["no"]))
# comparing integers, the noise_data no fields are previously
# dumped as integers
if i["no"] == 2:
print(i["glyph"] + " " + i["radical"] )
if i["no"] == 3:
print(i["glyph"] + " " + i["radical"] )
# at this point the interferences are not so apparent
# test with a large corpus
# try with corpuses of different language
# try a chinese dictionary and a latin dictionary
# next step is to investigate json files themselves
# and any other types of dictionary structures, remix!

@ -1,22 +0,0 @@
[
{
"letter": "silk-1",
"radical": "silk",
"numeral": 2
},
{
"letter": "silk-2",
"radical": "silk",
"numeral": 3
},
{
"letter": "silk-3",
"radical": "silk",
"numeral": 4
},
{
"letter": "earth-1",
"radical": "earth",
"numeral": 5
}
]

@ -0,0 +1,26 @@
[
{
"glyph": "hong",
"dept-no": "silk-1",
"radical": "silk",
"no": 2
},
{
"glyph": "jiao",
"dept-no": "silk-2",
"radical": "silk",
"no": 3
},
{
"glyph": "zhu",
"dept-no": "silk-3",
"radical": "silk",
"no": 4
},
{
"glyph": "du",
"dept-no": "earth-1",
"radical": "earth",
"no": 5
}
]

@ -0,0 +1,30 @@
[
{
"glyph": "hong",
"dept-no": "silk-1",
"radical": "silk",
"no": "1"
},
{
"glyph": "jiao",
"dept-no": "silk-2",
"radical": "silk",
"no": "2"
},
{
"glyph": "zhu",
"dept-no": "silk-3",
"radical": "silk",
"no": "3"
},
{
"glyph": "du",
"dept-no": "earth-1",
"radical": "earth",
"no": "4"
}
]
Loading…
Cancel
Save