-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHarri_numbers.py
More file actions
169 lines (137 loc) · 4.16 KB
/
Copy pathHarri_numbers.py
File metadata and controls
169 lines (137 loc) · 4.16 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""
Left hand = Activate Harri numbers
Right fingers = any two digit number
Right thumbs = stick up to three 0's on the end
"""
import re
LONGEST_KEY = 4
starter_chord = {
#Default numbers
"#" : {"prefix" : " ",
"suffix" : " "},
#KWR for sticking stuff, so no spacing
"#KWR" : {"prefix" : "{^",
"suffix" : "}"},
#KL for clock stuff
"#KHR" : {"prefix" : "{^:",
"suffix" : "}"},
#TWO for years 2000's
#TW for 20
#O for 00
"#TWO" : {"prefix" : "20",
"suffix" : " "},
#NO for years 1900's
#N for 19
#O for 00
"#TPHO" : {"prefix" : "19",
"suffix" : " "},
#Po for pound
"#PO" : {"prefix" : "£",
"suffix" : ""},
#DL for dollar
"#TKHRA" : {"prefix" : "$",
"suffix" : ""},
#P for point or pennies
"#P" : {"prefix" : "{^.",
"suffix" : " }"}
}
linker_chord = { #by linker, I mean collapsing a 100 with 23 to output 123 (two strokes)
#comment out the ones you want, or add more
#"#" : True,
#"#PO" : True,
#"#TKHRA" : True
}
primary_number = {
"" : "",
"R" : "1",
"RB" : "2",
"B" : "3",
"FR" : "4",
"FRPB": "5",
"PB" : "6",
"F" : "7",
"FP" : "8",
"P" : "9",
#everything else is zero
"FB" : "0",
"RP" : "0",
"FRP" : "0",
"FRB" : "0",
"FPB" : "0",
"RPB" : "0"
}
secondary_number = {
"" : "",
"G" : "1",
"GS" : "2",
"S" : "3",
"LG" : "4",
"LGTS": "5",
"TS" : "6",
"L" : "7",
"LT" : "8",
"T" : "9",
#everything else is zero
"LS" : "0",
"GT" : "0",
"LGT" : "0",
"LGS" : "0",
"LTS" : "0",
"GTS" : "0"
}
trailing_zeroes = {
"" : "",
"E" : "0",
"U" : "00",
"EU": ",000"
}
def end_zeros(string):
# How many zeroes at the end of a given string
count = len(string) - len(string.rstrip("0"))
return count
def lookup(strokes):
assert len(strokes) <= LONGEST_KEY, '%d/%d' % (len(strokes), LONGEST_KEY)
output_number= ''
for stroke_number in range(len(strokes)):
#make the raw steno use just letters
if any(single_digit_number in "0123456789" for single_digit_number in strokes[stroke_number]):
strokes=list(strokes)
strokes[stroke_number]= "#" + strokes[stroke_number].replace(
"0", "O").replace(
"1", "S").replace(
"2", "T").replace(
"3", "P").replace(
"4", "H").replace(
"5", "A").replace(
"6", "F").replace(
"7", "P").replace(
"8", "L").replace(
"9", "T")
match = re.fullmatch(r'(#?\^?S?T?K?P?W?H?R?A?O?\*?)-?([EU]*)([FRPB]*)([LGTS]*)', strokes[stroke_number])
#if it's not valid
if not match:
raise KeyError
# If there's no numbers
if not match[2]+match[3]+match[4]:
raise KeyError
if stroke_number==0:
if not (starter_chord[match[1]]):
raise KeyError
prefix = starter_chord[match[1]]['prefix']
suffix = starter_chord[match[1]]['suffix']
output_number+=(primary_number[match[3]]+
secondary_number[match[4]]+
trailing_zeroes[match[2]])
else:
if not (linker_chord[match[1]]):
raise KeyError
successive_numbers=(primary_number[match[3]]+
secondary_number[match[4]]+
trailing_zeroes[match[2]])
if len(successive_numbers) > end_zeros(output_number):
raise KeyError
output_number = (output_number[0:len(output_number)-len(successive_numbers)]+
successive_numbers)
return (prefix+
output_number +
suffix)