texdict/todo.md: add
This commit is contained in:
parent
18ef47c536
commit
52f4d78fa3
@ -10,11 +10,11 @@ parser = argparse.ArgumentParser(
|
|||||||
|
|
||||||
parser.add_argument('file', help='input file')
|
parser.add_argument('file', help='input file')
|
||||||
parser.add_argument('-i', '--input', choices=('json', 'tex'), help='input format: json, tex, sqlite (default: file extension')
|
parser.add_argument('-i', '--input', choices=('json', 'tex'), help='input format: json, tex, sqlite (default: file extension')
|
||||||
#parser.add_argument('-e', '--entry', help='add a entry to a file')
|
|
||||||
#parser.add_argument('-w', '--write', action='store_true', required=False, help='overwrite input file')
|
|
||||||
parser.add_argument('-f', '--format', choices=('json', 'tex'), help='choose output format: json, tex, sqlite (default: json)')
|
parser.add_argument('-f', '--format', choices=('json', 'tex'), help='choose output format: json, tex, sqlite (default: json)')
|
||||||
#parser.add_argument('-o', '--output', help='write dictionary file to file')
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', help='boolean verbose switch (default: false)')
|
parser.add_argument('-v', '--verbose', action='store_true', help='boolean verbose switch (default: false)')
|
||||||
|
#parser.add_argument('-e', '--entry', help='add a entry to a file')
|
||||||
|
#parser.add_argument('-o', '--output', help='write dictionary file to file')
|
||||||
|
#parser.add_argument('-w', '--write', action='store_true', required=False, help='overwrite input file')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
# verboseprint https://stackoverflow.com/a/5980173
|
# verboseprint https://stackoverflow.com/a/5980173
|
||||||
@ -30,22 +30,6 @@ if args.format:
|
|||||||
outformat=args.format
|
outformat=args.format
|
||||||
verboseprint("output file format:", outformat)
|
verboseprint("output file format:", outformat)
|
||||||
|
|
||||||
|
|
||||||
#example= '''{
|
|
||||||
# "entry" : "asɛm",
|
|
||||||
# "key": "asem",
|
|
||||||
# "meanings": [
|
|
||||||
# {
|
|
||||||
# "type" : "noun",
|
|
||||||
# "description" : "word",
|
|
||||||
# "examples" : ["Wonim saa asɛm yi?"]
|
|
||||||
# },{
|
|
||||||
# "type": "noun",
|
|
||||||
# "description": "news",
|
|
||||||
# "examples" : []
|
|
||||||
# }
|
|
||||||
# ]
|
|
||||||
#}'''
|
|
||||||
# KNOWN WORD TYPES
|
# KNOWN WORD TYPES
|
||||||
shorttypes={
|
shorttypes={
|
||||||
'noun':'n'
|
'noun':'n'
|
||||||
@ -59,7 +43,6 @@ def get_data_from_jsonfile(filename):
|
|||||||
with open(filename) as infile:
|
with open(filename) as infile:
|
||||||
data = json.load(infile)
|
data = json.load(infile)
|
||||||
verboseprint(json.dumps(data, ensure_ascii=False))
|
verboseprint(json.dumps(data, ensure_ascii=False))
|
||||||
# print( json.dumps(data, ensure_ascii=False))
|
|
||||||
return json.dumps(data, ensure_ascii=False)
|
return json.dumps(data, ensure_ascii=False)
|
||||||
|
|
||||||
# READ TEX FILE
|
# READ TEX FILE
|
||||||
@ -68,23 +51,23 @@ def get_data_from_texfile(filename):
|
|||||||
with open(filename) as infile:
|
with open(filename) as infile:
|
||||||
for line in infile:
|
for line in infile:
|
||||||
jsonstring='{"entry": "'
|
jsonstring='{"entry": "'
|
||||||
#entry
|
#ENTRY
|
||||||
jsonstring+=line.split('{')[1].split('}')[0]+'", '
|
jsonstring+=line.split('{')[1].split('}')[0]+'", '
|
||||||
#key
|
#KEY
|
||||||
jsonstring+='"key": "'
|
jsonstring+='"key": "'
|
||||||
jsonstring+=line.split('{')[2].split('}')[0]+'", '
|
jsonstring+=line.split('{')[2].split('}')[0]+'", '
|
||||||
#meanings
|
#MEANINGS
|
||||||
number_of_meanings=line.count('\m')
|
number_of_meanings=line.count('\m')
|
||||||
verboseprint("Meanings found:", number_of_meanings)
|
verboseprint("Meanings found:", number_of_meanings)
|
||||||
jsonstring+='"meanings": [ '
|
jsonstring+='"meanings": [ '
|
||||||
for i in range(number_of_meanings):
|
for i in range(number_of_meanings):
|
||||||
#meaning
|
#MEANING
|
||||||
verboseprint(i)
|
verboseprint(i)
|
||||||
meaning=line.split("\m")[i+1][1:]
|
meaning=line.split("\m")[i+1][1:]
|
||||||
if i == (number_of_meanings-1):
|
if i == (number_of_meanings-1):
|
||||||
meaning=meaning[:-2]
|
meaning=meaning[:-2]
|
||||||
verboseprint("Meaning:",meaning)
|
verboseprint("Meaning:",meaning)
|
||||||
#type
|
#TYPE
|
||||||
#todo what if no type
|
#todo what if no type
|
||||||
if i == 0:
|
if i == 0:
|
||||||
jsonstring+='{ "type": "'
|
jsonstring+='{ "type": "'
|
||||||
@ -93,10 +76,10 @@ def get_data_from_texfile(filename):
|
|||||||
short_wordtype=meaning.split("(")[1].split(")")[0]
|
short_wordtype=meaning.split("(")[1].split(")")[0]
|
||||||
wordtype=shorttypes_inversed[short_wordtype]
|
wordtype=shorttypes_inversed[short_wordtype]
|
||||||
jsonstring+=wordtype+'", '
|
jsonstring+=wordtype+'", '
|
||||||
#description
|
#DESCRIPTION
|
||||||
jsonstring+='"description": "'
|
jsonstring+='"description": "'
|
||||||
jsonstring+=meaning.split(") ")[1].split(' ;')[0]+'"'
|
jsonstring+=meaning.split(") ")[1].split(' ;')[0]+'"'
|
||||||
#examples
|
#EXAMPLES
|
||||||
jsonstring+=', "examples": ['
|
jsonstring+=', "examples": ['
|
||||||
if ';' in meaning:
|
if ';' in meaning:
|
||||||
examples=meaning.split('; ')[1]
|
examples=meaning.split('; ')[1]
|
||||||
@ -110,7 +93,7 @@ def get_data_from_texfile(filename):
|
|||||||
else:
|
else:
|
||||||
jsonstring+='"'+example+'", '
|
jsonstring+='"'+example+'", '
|
||||||
jsonstring+=' ]'
|
jsonstring+=' ]'
|
||||||
#close meaning
|
#CLOSE MEANING
|
||||||
jsonstring+='}'
|
jsonstring+='}'
|
||||||
jsonstring+=' ] }'
|
jsonstring+=' ] }'
|
||||||
return jsonstring
|
return jsonstring
|
||||||
@ -119,16 +102,16 @@ def json2tex(entry):
|
|||||||
entry_json=json.loads(entry)
|
entry_json=json.loads(entry)
|
||||||
entry_tex='\dictentrysorted{'+entry_json['entry']+'}{'+entry_json['key']+'}{'
|
entry_tex='\dictentrysorted{'+entry_json['entry']+'}{'+entry_json['key']+'}{'
|
||||||
for meaning in entry_json['meanings']:
|
for meaning in entry_json['meanings']:
|
||||||
#type
|
#TYPE
|
||||||
wordtype=meaning['type']
|
wordtype=meaning['type']
|
||||||
if wordtype in shorttypes:
|
if wordtype in shorttypes:
|
||||||
wordtype=shorttypes[wordtype]
|
wordtype=shorttypes[wordtype]
|
||||||
else:
|
else:
|
||||||
print("VERBOSE: stderr: "+wordtype+" is not in the the known word type list!")
|
print("VERBOSE: stderr: "+wordtype+" is not in the the known word type list!")
|
||||||
entry_tex+='\m ('+wordtype+') '
|
entry_tex+='\m ('+wordtype+') '
|
||||||
#description
|
#DESCRIPTION
|
||||||
entry_tex+=meaning['description']+' '
|
entry_tex+=meaning['description']+' '
|
||||||
#examples
|
#EXAMPLES
|
||||||
verboseprint(meaning)
|
verboseprint(meaning)
|
||||||
if len(meaning['examples']) != 0:
|
if len(meaning['examples']) != 0:
|
||||||
for example in meaning['examples']:
|
for example in meaning['examples']:
|
||||||
|
2
texdict/todo.md
Normal file
2
texdict/todo.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# TODO:
|
||||||
|
- change such that two entries can be converted
|
Loading…
Reference in New Issue
Block a user