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('-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('-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('-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()
|
||||
# verboseprint https://stackoverflow.com/a/5980173
|
||||
@ -30,22 +30,6 @@ if args.format:
|
||||
outformat=args.format
|
||||
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
|
||||
shorttypes={
|
||||
'noun':'n'
|
||||
@ -59,7 +43,6 @@ def get_data_from_jsonfile(filename):
|
||||
with open(filename) as infile:
|
||||
data = json.load(infile)
|
||||
verboseprint(json.dumps(data, ensure_ascii=False))
|
||||
# print( json.dumps(data, ensure_ascii=False))
|
||||
return json.dumps(data, ensure_ascii=False)
|
||||
|
||||
# READ TEX FILE
|
||||
@ -68,23 +51,23 @@ def get_data_from_texfile(filename):
|
||||
with open(filename) as infile:
|
||||
for line in infile:
|
||||
jsonstring='{"entry": "'
|
||||
#entry
|
||||
#ENTRY
|
||||
jsonstring+=line.split('{')[1].split('}')[0]+'", '
|
||||
#key
|
||||
#KEY
|
||||
jsonstring+='"key": "'
|
||||
jsonstring+=line.split('{')[2].split('}')[0]+'", '
|
||||
#meanings
|
||||
#MEANINGS
|
||||
number_of_meanings=line.count('\m')
|
||||
verboseprint("Meanings found:", number_of_meanings)
|
||||
jsonstring+='"meanings": [ '
|
||||
for i in range(number_of_meanings):
|
||||
#meaning
|
||||
#MEANING
|
||||
verboseprint(i)
|
||||
meaning=line.split("\m")[i+1][1:]
|
||||
if i == (number_of_meanings-1):
|
||||
meaning=meaning[:-2]
|
||||
verboseprint("Meaning:",meaning)
|
||||
#type
|
||||
#TYPE
|
||||
#todo what if no type
|
||||
if i == 0:
|
||||
jsonstring+='{ "type": "'
|
||||
@ -93,10 +76,10 @@ def get_data_from_texfile(filename):
|
||||
short_wordtype=meaning.split("(")[1].split(")")[0]
|
||||
wordtype=shorttypes_inversed[short_wordtype]
|
||||
jsonstring+=wordtype+'", '
|
||||
#description
|
||||
#DESCRIPTION
|
||||
jsonstring+='"description": "'
|
||||
jsonstring+=meaning.split(") ")[1].split(' ;')[0]+'"'
|
||||
#examples
|
||||
#EXAMPLES
|
||||
jsonstring+=', "examples": ['
|
||||
if ';' in meaning:
|
||||
examples=meaning.split('; ')[1]
|
||||
@ -110,7 +93,7 @@ def get_data_from_texfile(filename):
|
||||
else:
|
||||
jsonstring+='"'+example+'", '
|
||||
jsonstring+=' ]'
|
||||
#close meaning
|
||||
#CLOSE MEANING
|
||||
jsonstring+='}'
|
||||
jsonstring+=' ] }'
|
||||
return jsonstring
|
||||
@ -119,16 +102,16 @@ def json2tex(entry):
|
||||
entry_json=json.loads(entry)
|
||||
entry_tex='\dictentrysorted{'+entry_json['entry']+'}{'+entry_json['key']+'}{'
|
||||
for meaning in entry_json['meanings']:
|
||||
#type
|
||||
#TYPE
|
||||
wordtype=meaning['type']
|
||||
if wordtype in shorttypes:
|
||||
wordtype=shorttypes[wordtype]
|
||||
else:
|
||||
print("VERBOSE: stderr: "+wordtype+" is not in the the known word type list!")
|
||||
entry_tex+='\m ('+wordtype+') '
|
||||
#description
|
||||
#DESCRIPTION
|
||||
entry_tex+=meaning['description']+' '
|
||||
#examples
|
||||
#EXAMPLES
|
||||
verboseprint(meaning)
|
||||
if len(meaning['examples']) != 0:
|
||||
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