Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Abbreviations-automatic/Red/abbreviations-automatic.red
Normal file
30
Task/Abbreviations-automatic/Red/abbreviations-automatic.red
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Red []
|
||||
;; read and convert data to a string - to char conversion is neccessary to avoid
|
||||
;; illegal utf8 encoding error....
|
||||
|
||||
data: collect/into [foreach b read/binary %abbrev.txt [keep to-char b ]] ""
|
||||
;; data: read %abbrev.txt - would work, if file was utf-8 encoded ...
|
||||
foreach line split data newline [ ;; split data in lines at carriage return & line feed:
|
||||
|
||||
if empty? trim line [ continue ] ;; continues at head of loop
|
||||
|
||||
arr: split line space ;; now split line in words ; accumulate in array / series
|
||||
|
||||
min: 1 ;; preset min length
|
||||
until [
|
||||
;; head is the first position of series
|
||||
if head? arr [m: make map! [] ] ;; define an empty map (key -value store)
|
||||
|
||||
abbr: copy/part first arr min ;; copy/part ~ leftstr of first word with length min
|
||||
|
||||
arr: either m/:abbr [ ;; abbreviation already exists ?
|
||||
min: min + 1
|
||||
head arr ;; reset series position to head
|
||||
][ ;; otherwise ....
|
||||
m/:abbr: true ;; mark abreviation in map as existent
|
||||
next arr ;; set series position to next word
|
||||
]
|
||||
tail? arr ;; this is the until condition , end /tail of series reached ?
|
||||
]
|
||||
print [min line] ;; print automatically reduces all words in block
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue