-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorphonemic.fs
69 lines (66 loc) · 2.48 KB
/
morphonemic.fs
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
require rules.fs
: morphonemic-get-rules ( addr u -- rule )
0 { rule-sum }
BEGIN DUP 0> WHILE ( addr' u' )
\ ." At: " 2dup type ." rule-sum: " rule-sum >NAME ?DUP-IF .ID ELSE ." 0" THEN CR
2DUP morphoneme-find IF ( addr' u' xt )
\ ." FOUND " dup >NAME .ID ~~ CR
morphoneme-rule rule-sum rule+ TO rule-sum
\ ." ADVANCING " ~~
2DUP morphoneme-width /STRING
\ ." TO " 2dup type CR
ELSE
+X/STRING
THEN
REPEAT 2DROP rule-sum ;
: morphonemic-sstr-prepare { capacity len -- sstr }
len 1+ 1 INVERT AND TO len
capacity len 1+ * 1- { buf-len }
buf-len sstr-create { sstr }
sstr cstr-get BLANK
capacity sstr sstr-count !
sstr sstr-allocate-arr
sstr sstr-arr @ sstr cstr-ptr @ ( arr-ptr start )
capacity 0 DO { arr-ptr start } ( )
start arr-ptr cstr-ptr !
0 arr-ptr cstr-len !
arr-ptr cstr% %SIZE + ( arr-ptr' )
start len + 1+ ( arr-ptr' start' )
LOOP 2DROP sstr ;
: morphonemic-to-sstr-and-rule ( addr u -- sstr rule )
\ ." morphonemic-to-sstr-and-rule:in " 2dup type cr
DUP { len }
len 0= IF 2DROP 0 0 EXIT THEN
2DUP morphonemic-get-rules { rule-sum }
\ ." rule-sum: " rule-sum >NAME ?DUP-IF .NAME THEN
rule-sum rule-capacity { capacity }
capacity len morphonemic-sstr-prepare { sstr }
BEGIN DUP 0> WHILE ( addr' u' )
\ ." at " 2dup type ." >"
2DUP morphoneme-find IF { xt }
\ ." FOUND " xt >NAME .ID CR
xt morphoneme-rule { rule }
\ ." RULE " rule >NAME .ID CR
sstr sstr-arr @ ( addr' u' arr-ptr )
capacity 0 DO { arr-ptr } ( addr' u' )
\ ." VARIANT " I . ." arr-ptr: " arr-ptr HEX. CR
xt I rule-sum rule rule-index-convert morphoneme-choose-variant { xc }
\ ." XC " xc HEX. xc xemit CR
xc [CHAR] 0 <> IF xc arr-ptr cstr-append-xc THEN
\ ." arr-ptr" arr-ptr .cstr cr
arr-ptr cstr% %SIZE + ( arr-ptr' )
LOOP DROP ( addr' u' )
morphoneme-skip ( addr'' u'' )
ELSE
OVER XC@ { xc }
sstr sstr-arr @ ( addr' u' arr-ptr )
capacity 0 DO { arr-ptr } ( addr' u' )
xc arr-ptr cstr-append-xc
arr-ptr cstr% %SIZE + ( arr-ptr' )
LOOP DROP ( addr' u' )
xc XC-SIZE /STRING ( addr'' u'' )
THEN
REPEAT
2DROP sstr rule-sum
\ ." morphonemic-to-sstr:out " over .sstr dup if dup >name .id else 0 . then cr
;