forked from skely/Sign-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary_manual_edit.py
More file actions
72 lines (63 loc) · 3.18 KB
/
dictionary_manual_edit.py
File metadata and controls
72 lines (63 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from lib import SL_dict
import os
import datetime
if __name__ == '__main__':
"""
Program allows manual change of any sign. Saves changes to new dictionary. Name of new dictionary is based on time of change.
"""
work_path = '/home/jedle/data/Sign-Language/_source_clean/'
dict_file_name = 'ultimate_dictionary2.txt'
orig_dict_file = os.path.join(work_path, dict_file_name)
akt_time = datetime.datetime.now()
new_file_name = '{}_manual_changed_{}-{}-{}-{}-{}.txt'.format(os.path.splitext(dict_file_name)[0], akt_time.year, akt_time.month, akt_time.day, akt_time.hour, akt_time.minute)
changed_dict_file = os.path.join(work_path, new_file_name)
dictionary_types = ['dictionary_takes', 'dictionary_items']
# dictionary = SL_dict.read_dictionary(new_dict_file, dictionary_type)
dict_selection = int(input('Select dictionary type: [0] dictionary, [1] takes :'))
dictionary_type = dictionary_types[dict_selection]
searched_sign = input('Select sign (or part of sign): ')
matches = []
if dictionary_type == 'dictionary_takes':
matches = SL_dict.search_take_sign(orig_dict_file, searched_sign, _pattern=True)
else:
matches = SL_dict.search_dict_sign(orig_dict_file, searched_sign, _pattern=True)
if len(matches) != 0:
for i, m in enumerate(matches):
print('[{}] {}'.format(i, m))
selected_edit = input('Select item to edit or [q] to quit: ')
if selected_edit != 'q':
tmp_item = matches[int(selected_edit)]
print(tmp_item)
kee_list = []
for i, kee in enumerate(tmp_item):
kee_list.append(kee)
print('[{}] {:<28} : {}'.format(i, kee, tmp_item[kee]))
selected_key = int(input('Select key to change: '))
old_value = tmp_item[kee_list[selected_key]]
if type(old_value) is not list:
new_value = input('Enter new value: ')
print('Do you want to change: {}'.format(kee_list[selected_key]))
print('from : {}'.format(old_value))
print('to: {}'.format(new_value))
confirm = input('Are you sure to commit change? (yes)')
if confirm == 'yes':
print('Changed')
new_item = tmp_item.copy()
new_item[kee_list[selected_key]] = new_value
dictionary = SL_dict.read_raw(orig_dict_file)
for i, item in enumerate(dictionary[dictionary_type]):
if item == tmp_item:
print(item)
dictionary[dictionary_type][i] = new_item
print(dictionary[dictionary_type][i])
SL_dict.save_dict(changed_dict_file, dictionary)
print('Saved to file: {}'.format(new_file_name))
else:
print('Change aborted.')
else:
print('This value cannot be changed! (changes in list variables not implemented (yet :D)).')
else:
print('Quitting')
else:
print('There is no match for: {}'.format(searched_sign))
print('Quitting')