-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate_voynich.py
More file actions
318 lines (274 loc) · 10.6 KB
/
Copy pathtranslate_voynich.py
File metadata and controls
318 lines (274 loc) · 10.6 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/usr/bin/env python3
"""
Voynich Manuscript — Structural Translation Engine
Based on proprietary frequency and positional analysis + distributional semantics
Translates EVA transcription into English structural glosses
using the decoded grammar, case system, and semantic root mappings.
"""
import sys
from collections import Counter
SUFFIXES = ['c89', 'C89', 'c79', 'c9', 'C9', '89', '79', 'am', 'an', 'ae', 'ay', 'oe', 'oy', '9']
CASES = {'an', 'am', 'ae', 'ay', 'oe', 'oy'}
# ── Semantic mappings ──────────────────────────────────────────────────
NOUNS = {
# h-class (organic/animate)
'h': 'body',
'oh': 'plant',
'oeh': 'blood/humor',
'ohc': 'tissue',
'oh1': 'herb',
'1oh': 'cultivated-plant',
'ohae': 'constitution',
'ohcc': 'flesh',
'ohC': 'skin',
'ohc7': 'joint',
'ohc8': 'bone',
# k-class (material/inanimate)
'k': 'vessel',
'ok': 'remedy',
'okc': 'compound',
'okco': 'decoction',
'1ok': 'solution',
# Classless — substances
'8': 'substance', # herb-dominant, ACC-heavy → raw material
'7': 'portion', # herb-dominant → measured part/dose
'9k': 'mineral-salt', # herb+astr → mineral component
'9h': 'liquid', # herb-dominant, INST → water/fluid medium
'o8': 'extract', # herb-dominant, ACC → extracted essence
'1h': 'tincture', # recipe-dominant → alcohol/oil extract
'y': 'preparation', # recipe-dominant → processed form
'eh': 'ingredient', # recipe-specific → raw material for compounding
# Classless — qualities/locations
'1c': 'condition', # LOC+GEN heavy → state/property of body
'2c': 'property', # LOC+GEN → quality
'e': 'nature', # LOC+GEN → inherent quality
'ae': 'sign', # astr+universal → observable indication
'K': 'pot', # herb 89% → cooking/preparation vessel
'4': 'site', # bio 62%, LOC 89% → anatomical location
'1c8': 'mortar', # recipe 72%, INST → grinding tool
'18': 'pestle', # recipe → pounding instrument
's': 'dose', # universal → measured amount
'oe': 'source', # location/origin
}
VERBS = {
# Primary actions (high finite rate = main clause verbs)
'1H': 'administer', # universal, finite 70% → give/apply treatment
'1K': 'measure', # universal, finite 79% → measure/weigh dose
'1': 'prepare', # universal, auxiliary → general making
'2': 'apply', # universal → put on/administer to body
# Therapeutic (bio-dominant)
'5': 'heal', # bio 62% → restore/cure
'e1': 'examine', # bio 54% → inspect/observe patient
'oe1': 'diagnose', # bio 56% → determine illness
'e2': 'test', # bio → check/verify result
'3': 'combine', # bio 41% → mix ingredients
# Preparation (herb-dominant)
'h1': 'extract', # herb 53% → draw out essence
'k1': 'grind', # herb 56% → crush/powder
'ok1': 'prepare', # herb 52% → make ready
'oh1': 'harvest', # herb → gather from plant
'1o': 'infuse', # herb 66% → soak/steep in liquid
'H': 'steep', # herb 72% → soak in hot liquid
# Compounding (recipe-dominant)
'hc': 'transform', # recipe 47% → change form/state
'hC': 'purify', # recipe 54% → remove impurities
'okc': 'compound', # recipe 53% → combine into medicine
'kc': 'process', # recipe 46% → subject to procedure
'g1': 'distill', # recipe 61% → heat and collect vapor
'og1': 'filter', # recipe → strain through cloth
'1co': 'dissolve', # recipe → melt/dissolve in liquid
'1ch': 'refine', # recipe → improve purity
'1ck': 'temper', # recipe → adjust temperature/strength
'2H': 'place', # → put into vessel
'2cH': 'soak', # → immerse in liquid
'1cH': 'activate', # → start process/fermentation
'1cK': 'regulate', # → control temperature/timing
# Roots that act as both noun and verb
'h': 'treat',
'oh': 'nourish',
'ok': 'medicate',
'k': 'contain',
'oeh': 'circulate',
'eh': 'incorporate',
'ohc': 'condition',
'8': 'process',
'9k': 'calcify',
'9h': 'moisten',
'K': 'contain',
'o': 'convey',
# Less common verbs
'j1': 'pour',
'oj1': 'decant',
'1e': 'inspect',
'e': 'observe',
'Ah': 'invigorate',
'2o': 'blend',
# Fallbacks
'1c': 'prepare',
'2c': 'treat',
}
CASE_PREP = {
'an': '', # nominative — no preposition
'am': '', # accusative — direct object
'ae': 'for', # dative
'ay': 'with', # instrumental
'oe': 'in', # locative
'oy': 'of', # genitive
}
PARTICLES = {
# Connectives
'am': 'and', 'oe': 'and', 'e': 'and', 'y': 'and', 'an': 'and',
# Clause-final
'eoe': '[END]', 'ap': '[DO]', '8ap': '[DO!]', 'oe9': '[thus]',
'ay9': '[thus]', 'oy9': '[so]', 'e9': '[done]',
# Bare case words (standalone, no suffix)
'ay': 'with-it', 'ae': 'for-it', 'oy': 'of-it',
# Bare noun roots (standalone)
'h': 'body', 'k': 'vessel', 'o': 'it', 's': 'dose',
'K': 'pot', 'H': 'steep',
# Bare verb roots (standalone = imperative)
'1': 'prepare!', '2': 'apply!', '3': 'combine!', '5': 'heal!',
# Short determiner-like words
'oh': 'plant', 'ok': 'remedy', 'eh': 'ingredient',
'4o': 'the', 'oeh': 'blood',
# Misc frequent standalone
'9k': 'mineral', '9h': 'liquid', '1o': 'infuse!',
'1ap': 'prepare! [DO]', '2ap': 'apply! [DO]',
'1oe': 'in-preparation', '2oe': 'in-treatment',
'1co': 'dissolve!', 'G': 'steep!', 'S': 'measure!',
}
def get_suffix(w):
for s in sorted(SUFFIXES, key=len, reverse=True):
if w.endswith(s) and len(w) > len(s):
return s
return None
def translate_word(w):
# Particles
if w in PARTICLES:
return PARTICLES[w]
# Demonstrative determiners
if w.startswith('s') and len(w) <= 4 and w[1:] in CASES:
return 'this'
suf = get_suffix(w)
if not suf:
return f'[{w}]'
root = w[:-len(suf)]
# Article
article = ''
if root.startswith('4o') and len(root) > 2:
article = 'the '
root = root[2:]
# Noun or verb?
if suf in CASES:
# Find noun meaning
noun = None
for key in sorted(NOUNS.keys(), key=len, reverse=True):
if root == key or root.startswith(key):
noun = NOUNS[key]
break
if not noun:
noun = f'[{root}]'
prep = CASE_PREP.get(suf, '')
if prep:
return f'{prep} {article}{noun}'
else:
return f'{article}{noun}'
else:
# Verb
verb = None
for key in sorted(VERBS.keys(), key=len, reverse=True):
if root == key or root.startswith(key):
verb = VERBS[key]
break
if not verb:
verb = f'[{root}]'
if suf == '9':
return f'{verb}.'
elif suf in ('c89', 'C89'):
return f'having {verb}ed,'
elif suf in ('c9', 'C9'):
return f'{verb}ing'
elif suf == 'c79':
return f'{verb}ing'
elif suf == '89':
return f'{verb}ed'
elif suf == '79':
return f'was {verb}ing'
else:
return f'{verb}[{suf}]'
def translate_line(words):
return ' '.join(translate_word(w) for w in words)
def clean_translation(text):
text = text.replace(' .', '.')
text = text.replace(' ,', ',')
text = text.replace(' ', ' ')
# Capitalize after periods
result = []
cap_next = True
for c in text:
if cap_next and c.isalpha():
result.append(c.upper())
cap_next = False
else:
result.append(c)
if c == '.':
cap_next = True
return ''.join(result)
def load_and_translate(path, section_name):
with open(path) as f:
text = f.read()
output = []
output.append(f'{"="*70}')
output.append(f' {section_name}')
output.append(f'{"="*70}')
output.append('')
current_folio = ''
for line in text.split('\n'):
line = line.strip()
if not line:
continue
# Extract folio
folio = ''
if line.startswith('<'):
marker = line.split('>')[0].lstrip('<')
folio = marker.split('.')[0]
line_num = marker.split('.')[-1] if '.' in marker else ''
words = []
for part in line.split('.'):
part = part.strip().rstrip('-')
if '<' in part or '>' in part or '=' in part or '$' in part:
continue
if not part or not any(c.isalpha() for c in part):
continue
words.append(part)
if not words:
continue
if folio and folio != current_folio:
output.append(f'\n--- Folio {folio} ---\n')
current_folio = folio
translated = translate_line(words)
translated = clean_translation(translated)
output.append(f' {translated}')
return '\n'.join(output)
# ── Main ──────────────────────────────────────────────────────────────
import os
VDIR = os.environ.get("VOYNICH_EVA_DIR", ".")
sections = [
('section_herbal_a.txt', 'HERBAL SECTION A — Pharmacopeia'),
('section_herbal_b.txt', 'HERBAL SECTION B — Pharmacopeia (continued)'),
('section_biological.txt', 'BIOLOGICAL SECTION — Anatomy & Treatment'),
('section_astronomical.txt', 'ASTRONOMICAL SECTION — Medical Astrology'),
('section_recipe_stars.txt', 'RECIPE SECTION — Compounding Procedures'),
]
if __name__ == '__main__':
print('='*70)
print(' VOYNICH MANUSCRIPT — STRUCTURAL TRANSLATION')
print(' Decoded via computational structural analysis')
print(' Language: Dravidian-type, featural abugida script')
print(' Content: Siddha medical handbook')
print('='*70)
print()
for fname, title in sections:
result = load_and_translate(f'{VDIR}/{fname}', title)
print(result)
print()