[REBOL] Re: I miss ..., bug in to-local-file ...
From: agem:crosswinds at: 8-Jun-2001 21:28
{
Hi Scott!
not really sure if this is usefull (now, after coding..).
but to illustrate the idea..
if you (all) think its worth some more work, tell me..
-Volker
}
[rebol [title: "sort-mapper" file: %czech0.r
purpose: {
to make it easier to generate sort-mappings for foreign
languages. protoprototype.
}
usage: {
look for
;CHANGE BASE-MAP.
add your mapping/ordering changes.
;PATCH PARSE-ORDER
to tell parse first look for "ch", then for "c"
(longer before shorter)
;SORT-DEMO
look here to sort a bit
}
comment: {
slow. encodes ~15k/sec on 350mhz (10 * 3k)
(without map generation)
speedup with charsets possible?
simple lookup-table for single chars should be best for
speed i expect.
-
upper/lowercase makes problems with "ch" and that
("ch" "Ch" "cH" "CH" ..)
need some kind of partly-mixed-case-parse..
at least for ä ..
-
chars > 127 throw error, except chars explicit inserted.
can be changed.
}
]
;protect-system
???: func ['word value] [
print [mold :word " : " mold :value] word :value
]
;generate base map
;---
base-map: copy [] ;some[+ "" | = "" ]
repeat i 127 [
append base-map compose [+ (to string! to char! i)]
]
;CHANGE BASE-MAP.
;---
; todo: swap somehow upper & lowercase..
p: find/case/tail base-map "h"
; '= means same priority, '+ means new char
insert p [+ "ch" = "CH" = "Ch" = "cH"]
p: find/case/tail base-map "a" ;some german ;)
insert p [+ "ä" = "ae"]
;? base-map
;calculate codes
;---
explicit-map: copy [] ;some[find-string new-code]
next-char: to char! 0
forskip base-map 2 [
if '+ = base-map/1 [next-char: next-char + 1]
repend explicit-map [base-map/2 next-char]
]
;and restructuring. we need to be able to parse
;"ch" before "c", "ae" before "a"..
;without changing code
;---
to-tail: func ["move string to end of explicit-map"
s
/local p
] [
p: find/case explicit-map s
append p copy/part p 2
remove/part p 2
]
;PATCH PARSE-ORDER
;---
to-tail "c" to tail "C"
to-tail "a" to-tail "&"
;? explicit-map
;generate rule
;---
step-rule: copy []
forskip explicit-map 2 [
append step-rule compose [
;hacky line
| (explicit-map/1) (
to paren! compose [
append out (explicit-map/2)])
]
]
step-rule: next step-rule
;? step-rule
;encode-func
;---
out: none
encode: func [s] [
out: copy ""
if not parse/all/case s [some [here: step-rule]] [
throw make error! mold copy/part skip here -10 100
]
out
]
;SORT-DEMO
;---
strings: [
{achz} x
{ch} x
{ahz} x
{aiz} x
]
s: strings
forskip s 2 [s/2: encode s/1]
? strings
sort/skip/compare strings 2 2
? strings
;---benchmark
;---
print "---benchmarking encode-rate"
dat: read %czech0.r
probe length? dat
start: now/precise/time
loop 10 [encode dat]
probe time: now/precise/time - start
print [10 * (length? dat) / to decimal! time "bytes/sec"]
print "done"
]
>>>>>>>>>>>>>>>>>> Ursprüngliche Nachricht <<<<<<<<<<<<<<<<<<
Am 08.06.01, 19:48:03, schrieb Volker Nitsch <[agem--crosswinds--net]> zum
Thema [REBOL] Re: I miss ..., bug in to-local-file ...: