Repository navigation
Expand file tree
/
Copy pathabv-layout.el
More file actions
610 lines (529 loc) · 26.9 KB
/
Copy pathabv-layout.el
File metadata and controls
610 lines (529 loc) · 26.9 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
;;; abv-layout.el --- Abbrev layout objects and APIs -*- lexical-binding: t; -*-
;;; Code:
(require 'eieio)
(require 'eieio-base)
(require 'cl-lib)
(require 'abv-weights)
(require 'abv-runtime-state)
;; Classes defining the following slots live in files that
;; cannot be required from here (circular dependency);
;; registering the names lets the byte compiler's slot
;; checks recognize them (see `eieio--known-slot-name-p').
(eval-when-compile
(dolist (slot '(prefix-table suffix-table infix-table root-table))
(put slot 'slot-name t)))
(defun abv--alist-to-hash (alist)
"Convert ALIST into an `equal'-tested hash table."
(let ((hash (make-hash-table :test 'equal)))
(pcase-dolist (`(,key . ,value) alist)
(puthash key value hash))
hash))
(defun abv-int-triple-p (x)
"Return non-nil if X is a coordinate triple of integers (LAYER ROW COL).
If function daselt-coords-p is available, it must also return non-nil
for X. This predicate accepts only lists of length 3."
(and (listp x) (= (length x) 3) (cl-every #'integerp x)))
(defun abv-placeval-p (x)
"Return non-nil if X is a cons cell of the form ((L R C) . STRING).
The car must be an integer triple acceptable to abv-int-triple-p.
The cdr must be a string representing the symbol value."
(and (consp x) (abv-int-triple-p (car x)) (stringp (cdr x))))
(defun abv-placeval-alist-p (x)
"Return non-nil if X is an alist of placevals.
Each element must be a cons ((L R C) . STRING)."
(and (listp x) (cl-every #'abv-placeval-p x)))
(defun abv-layer-pairs-p (x)
"Return non-nil if X is a list of cons cells (LOWER . UPPER).
Both LOWER and UPPER must be integers."
(and (listp x)
(cl-every (lambda (p) (and (consp p) (integerp (car p)) (integerp (cdr p)))) x)))
(defclass abv-layout-runtime-state (abv-runtime-state)
((symbol-sequence-cache :initarg :symbol-sequence-cache :initform nil
:type list
:documentation "Cache alist of (PATTERN . SEQS)
of enumerated placeval sequences, managed by
`abv-layout-generate-symbol-sequence-cache'."))
:documentation "Runtime data of an `abv-layout'. Holds the
enumeration cache; regenerable on demand and dropped from saves.")
(defclass abv-layout-placevals ()
((single-symbol-placevals :initarg :single-symbol-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(prefix-placevals :initarg :prefix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(lower-paired-prefix-placevals :initarg :lower-paired-prefix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(suffix-placevals :initarg :suffix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(lower-paired-suffix-placevals :initarg :lower-paired-suffix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(infix-placevals :initarg :infix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(lower-paired-infix-placevals :initarg :lower-paired-infix-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(root-placevals :initarg :root-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(lower-paired-root-placevals :initarg :lower-paired-root-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(standalone-placevals :initarg :standalone-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(separator-placevals :initarg :separator-placevals
:initform nil
:type (satisfies abv-placeval-alist-p))
(standard-placevals :initarg :standard-placevals
:initform nil
:type (satisfies abv-placeval-alist-p)))
:documentation "All placeval assignments of an `abv-layout' in one
object: the assignable positions per symbol class (prefix, suffix,
infix, root, standalone, separator, standard) with their
lower-paired variants. Lives in the layout's `placevals' slot.")
(defclass abv-layout-options ()
((enum-max-repeats :initarg :enum-max-repeats :initform 2 :type integer
:documentation "Max repeats for + and * in pattern
enumeration.")
(enum-max-results :initarg :enum-max-results :initform 8192 :type integer
:documentation "Max sequences to return from
enumeration."))
:documentation "Options of an `abv-layout' governing pattern
enumeration. Lives in the layout's `options' slot; layout
subclasses add their own options through subclasses of this
class.")
(defclass abv-layout ()
((name :initarg :name :initform "default" :type string
:documentation "Human-readable layout name.")
(layer-pairs :initarg :layer-pairs :initform nil :type (satisfies abv-layer-pairs-p))
(save-file :initarg :save-file :initform nil :type (or null string))
(placevals :initarg :placevals
:initform (make-instance 'abv-layout-placevals)
:type abv-layout-placevals
:documentation "All placeval assignments; see
`abv-layout-placevals'.")
(runtime-state :initarg :runtime-state
:initform (make-instance 'abv-layout-runtime-state)
:type abv-layout-runtime-state
:documentation "Runtime data of this layout; see
`abv-layout-runtime-state'.")
(options :initarg :options
:initform (make-instance 'abv-layout-options)
:type abv-layout-options
:documentation "Enumeration options; see
`abv-layout-options'."))
:documentation "Abv layout instance and mapping state.")
(cl-defmethod eieio-persistent-save :around ((layout abv-layout))
"Save LAYOUT, dropping the runtime symbol-sequence cache."
(let* ((print-level nil)
(print-length nil))
(oset (oref layout runtime-state) symbol-sequence-cache nil)
(cl-call-next-method)))
(defvar abv-layout--legacy-slots
'((symbol-sequence-cache runtime-state symbol-sequence-cache)
(single-symbol-placevals placevals single-symbol-placevals)
(prefix-placevals placevals prefix-placevals)
(lower-paired-prefix-placevals placevals lower-paired-prefix-placevals)
(suffix-placevals placevals suffix-placevals)
(lower-paired-suffix-placevals placevals lower-paired-suffix-placevals)
(infix-placevals placevals infix-placevals)
(lower-paired-infix-placevals placevals lower-paired-infix-placevals)
(root-placevals placevals root-placevals)
(lower-paired-root-placevals placevals lower-paired-root-placevals)
(standalone-placevals placevals standalone-placevals)
(separator-placevals placevals separator-placevals)
(standard-placevals placevals standard-placevals)
(enum-max-repeats options enum-max-repeats)
(enum-max-results options enum-max-results)
(prefer-first-up-to options prefer-first-up-to))
"Legacy flat slots of `abv-layout' and subclasses.
Maps each former slot to the (SUBOBJECT-SLOT OPTION-SLOT) pair
that owns the value since the runtime data moved into the
`runtime-state' subobject. Used by `slot-missing' so saves and
callers written against the flat slot keep working.")
(cl-defmethod slot-missing ((layout abv-layout) slot-name operation
&optional new-value)
"Redirect legacy flat slot accesses on LAYOUT to the runtime state.
See `abv-layout--legacy-slots' and `abv--legacy-slot-redirect';
uncovered names fall through to the default error."
(let ((res (abv--legacy-slot-redirect layout slot-name operation
new-value
abv-layout--legacy-slots)))
(if res (cdr res) (cl-call-next-method))))
(defclass abv-layout-file (abv-layout eieio-persistent)
((file :initarg :file :initform (concat abv-directory "layouts")
:type string
:documentation "File to save in."))
:documentation "`abv-layout'-object with file.")
(cl-defgeneric abv-layout-assign-affixes (layout affixes frequencies table-id)
"Assign AFFIXES into TABLE-ID using FREQUENCIES.")
(cl-defgeneric abv-layout-visualize-layer (layout table-id layer)
"Visualize one LAYER of TABLE-ID.")
(cl-defgeneric abv-layout-lookup-affix (layout table-id affix)
"Lookup AFFIX in TABLE-ID and return coordinates or nil.")
(cl-defgeneric abv-layout-lookup-root (layout root)
"Lookup ROOT in =root-table'.")
(cl-defgeneric abv-layout-save (layout &optional file)
"Persist mapping tables into FILE or =save-file'.")
(cl-defgeneric abv-layout-load (_layout &optional file)
"Load mapping tables from FILE or =save-file'.")
(cl-defgeneric abv-layout-string (_layout value)
"Return the string corresponding to VALUE in the layout.
This is so layouts can use representations other than strings for typings.
VALUE can be anything, like Daselt-coordinates.
By default it is assumed to be a string, which is returned unchanged."
value)
(defun abv--hash-to-alist (ht)
"Convert hash table HT to an alist sorted by key in ascending order.
Return a new list of cons cells (KEY . VALUE). Keys are compared using
string<."
(let (pairs) (maphash (lambda (k v) (push (cons k v) pairs)) ht)
(cl-sort pairs (lambda (a b) (string< (car a) (car b))))))
(defun abv-layout-alist->hash (alist &optional key-fn)
"Convert ALIST to a string-keyed hash-table.
If KEY-FN is non-nil, it is applied to each car of ALIST before insertion. The
resulting hash-table uses `equal' as test."
(let ((ht (make-hash-table :test 'equal)))
(dolist (kv alist ht)
(let ((k (if key-fn (funcall key-fn (car kv)) (car kv)))
(v (cdr kv)))
(puthash k v ht)))))
(cl-defmethod abv-layout-save ((layout abv-layout) &optional file)
"Persist mapping tables for LAYOUT to FILE or to the save-file slot.
Implementations should serialize the prefix, suffix, infix, and root
mapping tables. Return the destination file name or a method-defined
value. Signal an error if no destination is available."
(let ((outfile (or file (oref layout save-file))))
(unless outfile (error "No save-file set on this layout"))
(let ((dir (file-name-directory outfile))) (when dir (ignore-errors (make-directory dir t))))
(with-temp-file outfile
(let ((print-length nil) (print-level nil))
(prin1 (list :prefix (abv--hash-to-alist (oref layout prefix-table))
:suffix (abv--hash-to-alist (oref layout suffix-table))
:infix (abv--hash-to-alist (oref layout infix-table))
:root (abv--hash-to-alist (oref layout root-table)))
(current-buffer))))
outfile))
(cl-defmethod abv-layout-load ((layout abv-layout) &optional file)
"Load mapping tables for LAYOUT from FILE or from the save-file slot.
Implementations should restore the prefix, suffix, infix, and root
mapping tables. Return LAYOUT or a method-defined value. Signal an error
on unreadable files or invalid content."
(let ((infile (or file (oref layout save-file))))
(unless (and (stringp infile) (file-readable-p infile))
(error "Cannot read layout file %S" infile))
(with-temp-buffer
(insert-file-contents infile)
(goto-char (point-min))
(pcase (read (current-buffer))
(`(:prefix ,p :suffix ,s :infix ,i :root ,r)
(oset layout prefix-table (abv--alist-to-hash p))
(oset layout suffix-table (abv--alist-to-hash s))
(oset layout infix-table (abv--alist-to-hash i))
(oset layout root-table (abv--alist-to-hash r))
layout)
(_ (error "Invalid layout file format: %S" infile))))))
;; Collection construction
(cl-defgeneric abv-layout-collection (layout)
"Return a new collection object for LAYOUT.
The default method produces a collection with the layout set to LAYOUT
and no tables. Specializations may return a pre populated collection.")
(cl-defmethod abv-layout-collection ((layout abv-layout))
"Return a new abv-collection with LAYOUT and no tables."
(make-instance 'abv-collection :layout layout :tables nil))
;; Scoring/computation generics to be implemented by specializations
(cl-defgeneric abv-layout-ease (layout seq weights)
"Return ergonomic score for SEQ under LAYOUT using WEIGHTS.")
(cl-defmethod abv-layout-ease ((_layout abv-layout) _seq _weights)
"Default ergonomic score: no preference.
Layouts without an ergonomic model score nil so candidate
enumeration order decides, exactly as before this generic
existed."
nil)
(cl-defgeneric abv-compute-root-placevals (layout)
"Compute valid root placevals for LAYOUT.")
(cl-defgeneric abv-layout-generate-deep-structure-for-root
(layout root weights &optional no-overwrite shared-matrix)
"Compute and assign deep structure for ROOT in LAYOUT.")
;; Enumeration API and cache
(defun abv-layout--cache-get (layout pattern)
"Get cached sequences for PATTERN from LAYOUT.
Return nil when no cache entry exists. PATTERN is the literal pattern
string passed to enumeration."
(alist-get pattern
(oref (oref layout runtime-state) symbol-sequence-cache)
nil nil #'equal))
(defun abv-layout--cache-put (layout pattern seqs)
"Store SEQS as the enumeration cache for PATTERN in LAYOUT.
Return SEQS."
(let* ((rs (oref layout runtime-state))
(alist (oref rs symbol-sequence-cache)))
(setf (alist-get pattern alist nil nil #'equal) seqs)
(oset rs symbol-sequence-cache alist)
seqs))
(defun abv-layout--class-placevals (layout ch)
"Return the placeval set for class character CH in LAYOUT.
Recognized classes are r for roots, p for prefixes, s for suffixes,
and i for infixes, S for standalone and Z for separator-placevals.
Return nil for unknown classes."
(pcase ch
(?r (oref (oref layout placevals) root-placevals))
(?p (oref (oref layout placevals) prefix-placevals))
(?s (oref (oref layout placevals) suffix-placevals))
(?i (oref (oref layout placevals) infix-placevals))
(?S (oref (oref layout placevals) standalone-placevals))
(?Z (oref (oref layout placevals) separator-placevals))
(?T (oref (oref layout placevals) standard-placevals))
(_ nil)))
(defun abv-layout--parse-pattern (layout string)
"Parse pattern STRING for LAYOUT into a list of atoms.
Each atom is a list (SET MIN MAX) where SET is a list of placevals and
MIN and MAX are repeat bounds derived from quantifiers. See
`abv-layout--class-placevals' for which classes are available."
(let ((i 0) (n (length string)) (atoms '()))
(cl-labels
((next () (prog1 (and (< i n) (aref string i)) (setq i (1+ i))))
(peek () (and (< i n) (aref string i)))
(emit (set min max) (push (list set min max) atoms)))
(while (< i n)
(let ((c (next)))
(cond
((= c ?\[)
(let ((set '()) (done nil))
(while (and (< i n) (not done))
(let ((d (next)))
(cond
((= d ?\]) (setq done t))
(t (setq set (append set (abv-layout--class-placevals layout d)))))))
(let ((q (peek)) (min 1) (max 1))
(when (memq q '(?* ?+ ??
))
(ignore (next))
(pcase q
(?* (setq min 0 max (oref (oref layout options) enum-max-repeats)))
(?+ (setq min 1 max (oref (oref layout options) enum-max-repeats)))
(?? (setq min 0 max 1))))
(emit set min max))))
((memq c '(?r ?p ?s ?i ?S ?Z ?T))
(let ((set (abv-layout--class-placevals layout c))
(q (peek)) (min 1) (max 1))
(when (memq q '(?* ?+ ??
))
(ignore (next))
(pcase q
(?* (setq min 0 max (oref (oref layout options) enum-max-repeats)))
(?+ (setq min 1 max (oref (oref layout options) enum-max-repeats)))
(?? (setq min 0 max 1))))
(emit set min max)))
(t
;; ignore unknown chars
))))
(nreverse atoms))))
(defun abv-layout--expand-repeats (atoms)
"Expand atoms into concrete repetition shapes.
ATOMS is a list of (SET MIN MAX). Return a list of shapes. Each shape is
a list of SETs after choosing a repeat count between MIN and MAX for
each atom."
(cl-labels
((replicate (set k) (let (out) (dotimes (_ k) (push set out)) (nreverse out)))
(choose (min max)
(let (ks) (dotimes (k (1+ max)) (when (>= k min) (push k ks))) (nreverse ks)))
(walk (rest acc)
(if (null rest)
(list acc)
(cl-loop with head = (car rest)
with tail = (cdr rest)
for k in (choose (nth 1 head) (nth 2 head))
append (walk tail (nconc (copy-sequence acc)
(replicate (car head) k)))))))
(walk atoms '())))
(defun abv-layout--product2 (xs ys)
"Return the cartesian product of XS and YS.
Each element of XS is a partial sequence. Each element of YS is a set.
The result appends each element of YS to each element of XS."
(cl-loop for x in xs append (cl-loop for y in ys collect (append x (list y)))))
(defun abv-layout--product (lists)
"Return the cartesian product of LISTS of sets.
LISTS is a list of sets. The result is a list of sequences, one element
chosen from each set in order."
(let ((acc (list '())))
(dolist (set lists acc)
(setq acc (abv-layout--product2 acc set)))))
(cl-defgeneric abv-layout-neighbors (layout coords &key layers sortfun)
"Return nearby coordinates around a position
Candidates are sorted by SORTFUN or a default.
If LAYERS is given, restrict to those layers.")
;;;###autoload
(cl-defun abv-layout-generate-symbol-sequence-cache (layout pattern &key refresh)
"Generate symbol sequences for PATTERN using LAYOUT.
Return and cache an unsorted xlist of sequences of placevals.
Pattern grammar for PATTERN
The pattern is a flat string. Atoms are symbol-classes:
r root class; uses `root-placevals'.
p prefix class; uses `prefix-placevals'.
s suffix class; uses `suffix-placevals'.
i infix class; uses `infix-placevals'.
S standalone class; uses `standalone-placevals'.
Z separator class; uses `separator-placevals'.
T standard class; uses `standard-placevals'.
A bracket group like \"[rps]\" unions those classes.
After an atom or group, a quantifier may follow:
? optional, 0 or 1 occurrence.
+ 1..N occurrences, where N is `enum-max-repeats'.
* 0..N occurrences, where N is `enum-max-repeats'.
The parser expands repeats into shapes. For each shape, the cartesian
product enumerates all sequences of placevals. A hard cap
`enum-max-results' bounds enumeration."
(or (and (not refresh)
(abv-layout--cache-get layout pattern))
(let ((atoms (abv-layout--parse-pattern layout pattern))
(seqs '()) (cap (oref (oref layout options) enum-max-results)))
(dolist (shape (abv-layout--expand-repeats atoms))
(let ((prod (abv-layout--product shape)))
(dolist (row prod)
(when (> cap 0)
(cl-pushnew row seqs)
(setq cap (1- cap))))))
(setq seqs (nreverse seqs))
(abv-layout--cache-put layout pattern seqs))))
;;;###autoload
(defun abv-layout-generate-deep-structure-batch (layout roots freq-alist
&optional no-overwrite
wobj shared-matrix)
"Generate deep structures for ROOTS on LAYOUT in frequency order.
FREQ-ALIST maps roots to counts and is used to process more frequent roots first
\(ties are broken lexicographically). If NO-OVERWRITE is non-nil, keep existing
mappings. WOBJ and SHARED-MATRIX are passed to the scorer as in
`abv-layout-generate-deep-structure-for-root'.
Return LAYOUT's root-table."
(let* ((wobj (or wobj (abv-weights)))
(freq (abv-layout-alist->hash freq-alist))
(ordered (sort roots
:lessp (lambda (a b)
(let ((fa (gethash a freq 0)) (fb (gethash b freq 0)))
(if (/= fa fb) (> fa fb) (string< a b)))))))
(dolist (r ordered)
(abv-layout-generate-deep-structure-for-root layout r no-overwrite wobj shared-matrix))
(oref layout root-table)))
(cl-defgeneric abv-layout-char-placeval (layout char)
"Return placeval in LAYOUT whose cdr equals CHAR, or nil.")
(cl-defmethod abv-layout-char-placeval ((layout abv-layout) char)
"Find the single-symbol placeval whose literal char equals CHAR."
(let* ((alist (oref (oref layout placevals) single-symbol-placevals)))
(cl-find-if (lambda (pv)
(let ((str (cdr pv)))
(and (stringp str) (> (length str) 0)
(= (aref str 0) char))))
alist)))
(cl-defgeneric abv-layout-corresponding-lower-char (layout char)
"Return lower-layer corresponding char for CHAR in LAYOUT when paired.")
(cl-defmethod abv-layout-corresponding-lower-char ((layout abv-layout) char)
"If CHAR's placeval layer is a member of a pair (LOWER . UPPER),
try to find a placeval at the same row/col in the LOWER layer.
Return its char when found."
(and-let* ((pv (abv-layout-char-placeval layout char))
(coords (and pv (car pv)))
(str (and pv (cdr pv)))
(layer (and coords (nth 0 coords)))
(row (and coords (nth 1 coords)))
(col (and coords (nth 2 coords)))
(pairs (oref layout layer-pairs))
(lower (cl-loop for pr in pairs
when (= (cdr pr) layer) return (car pr)))
(alist (oref (oref layout placevals) single-symbol-placevals)))
(when lower
(let* ((target (list lower row col))
(other (cl-find-if (lambda (cell)
(and (equal (car cell) target)))
alist)))
(when other
(let ((os (cdr other)))
(and (stringp os) (> (length os) 0) (aref os 0))))))))
(cl-defgeneric abv-layout-inflection-info (layout type data &optional language)
"Return inflection data for `abv-syntax-inflect' based on DATA.
LAYOUT is the `abv-layout' instance. TYPE is the word type symbol.
DATA is the syntax string from the parse. LANGUAGE is the optional
`abv-language' instance; when t or nil, language-specific methods
should use a sensible default.
Default method returns nil. Word types that do not inflect
\(e.g., prepositions, conjunctions, interjections) need no
layout-specific methods.")
(cl-defmethod abv-layout-inflection-info ((_layout abv-layout) _type _data
&optional _language)
"Default: return nil (no layout-encoded inflection info)."
nil)
(cl-defgeneric abv-layout-word-type-from-string (layout string &optional language)
"Return a word type symbol decoded from STRING on LAYOUT.
STRING is the word-type-data extracted from the parse (between
word-type-separator and syntax-separator). LANGUAGE is the optional
`abv-language' instance for language-dependent mapping.
Default method returns nil. Layout specializations should map
single-character strings to word types.")
(cl-defmethod abv-layout-word-type-from-string ((_layout abv-layout) _string
&optional _language)
"Default: return nil (no layout-specific word-type mapping)."
nil)
;; Generic with from-type parameter for context-dependent decoding.
(cl-defgeneric abv-layout-conversion-method-from-string
(layout string &optional language from-type conversion-default)
"Return a conversion method suffix decoded from STRING on LAYOUT.
STRING is one character from the word-type-data. LANGUAGE is optional.
FROM-TYPE is the source word type symbol (e.g., `verb'), needed because
the same target-type column may have different suffixes depending on
the source type. CONVERSION-DEFAULT, when non-nil, is the word's
stored conversion default for the decoded target type; layouts whose
keys can request the word's default (e.g. first-layer keys) may return
it instead of decoding an explicit affix. Return a suffix string
\(e.g., \"-ment\"), or nil. A nil return means no layout-decoded
method; callers should then try the language's regex-based
conversion methods (`abv-language-conversion-suffix-match') and the
position-encoded affix (`abv-layout-position-affix-from-string')
before falling back to `abv-syntax-convert-word'.")
(cl-defmethod abv-layout-conversion-method-from-string
((_layout abv-layout) _string &optional _language _from-type
_conversion-default)
"Default: return nil."
nil)
(cl-defgeneric abv-layout-position-affix-from-string
(layout string &optional language from-type)
"Return the position-encoded conversion affix for STRING on LAYOUT.
STRING is one character from the word-type-data. LANGUAGE is the
optional `abv-language'; FROM-TYPE is the source word type symbol.
The affix is decoded purely from the key's position (row and layer
within its layer pair), ignoring any stored conversion default:
every key that supports a conversion returns its position affix
here, including keys whose `abv-layout-conversion-method-from-string'
prefers the word's stored default or returns nil. Return a suffix
string, or nil when the position encodes no affix. Note that
`abv-syntax--effective-conversion-method' treats this affix as a
last resort: it applies only when the language's own conversion
has no answer, since a positional guess must not preempt a
\(e.g. dictionary-validated) language conversion.")
(cl-defmethod abv-layout-position-affix-from-string
((_layout abv-layout) _string &optional _language _from-type)
"Default: no position-encoded affix."
nil)
(provide 'abv-layout)
;;; abv-layout.el ends here
;; Local Variables:
;; read-symbol-shorthands: (("lt-" . "abv-language-table-")
;; ("lng-" . "abv-language-")
;; ("st-" . "abv-sublingual-table-")
;; ("tl-" . "abv-typed-layout-")
;; ("coll-" . "abv-collection-")
;; ("pt-" . "abv-programming-table-")
;; ("elmt-" . "abv-emacs-lisp-mode-table-")
;; ("lmt-" . "abv-LaTeX-mode-table-")
;; ("mo-" . "abv-morph-")
;; ("scr-" . "abv-script-")
;; ("ic-" . "abv-icicles-")
;; ("ti-" . "abv-table-integrate-")
;; ("ev-" . "abv-english-verbs-")
;; ("cls-" . "abv-corpus-language-statistics-")
;; ("lcp-" . "abv-language-cache-persist-"))
;; End: