renamed files
worked on program int and str is a problem list comprehension is a different thing while working with jsonmain
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 numpy as np
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# what is the proper way to store radicals with dictionary?
|
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
|
||||||
# use json
|
|
||||||
|
# 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
|
data = json.load(open('seed.json', 'r'))
|
||||||
# the mapping relation of the dictionary.
|
|
||||||
# learning rules is also essential to machine learning, which
|
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)
|
noise = np.random.randint(1,3)
|
||||||
|
|
||||||
for i in data:
|
for i in data:
|
||||||
i["numeral"] = int(i["numeral"])
|
i["no"] = int(i["no"])
|
||||||
i["numeral"] += noise
|
i["no"] += noise
|
||||||
|
|
||||||
# write to a new json file
|
with open('noised.json','w') as w_file:
|
||||||
with open('new.json','w') as w_file:
|
|
||||||
json.dump(data,w_file, indent=4)
|
json.dump(data,w_file, indent=4)
|
||||||
|
|
||||||
# test with an existing corpus
|
print("after disrupting, the message is: ")
|
||||||
# try a chinese dictionary and a latin dictionary
|
|
||||||
# and any other types of dictionary structures, remix!
|
|
||||||
|
|
||||||
# current rule
|
# use noised json to decrypt
|
||||||
# 1 <= key <= 3, silk; 4 <= key <= 6, earth; 7 <= key <= 9, water
|
|
||||||
|
|
||||||
# then when i query the dictionary again,
|
noise_data = json.load(open('noised.json','r'))
|
||||||
# the rule is disrupted, the message is disrupted
|
for i in noise_data:
|
||||||
# the rule is disrupted by adding a simple number
|
print(i)
|
||||||
# are there more disruptive and complex rules?
|
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…
Reference in New Issue