omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / drafts / rosettacode / soundex.wiki
| 1 | =={{header|Omegese}}== |
| 2 | {{works with|omc|sha256 2c824805, aien-dev/omega-mv e5b32567, Linux AArch64}} |
| 3 | Omega has no imports, so the small output helpers (<code>emit</code> and friends) are part of the program. |
| 4 | <syntaxhighlight lang="text"> |
| 5 | om2 |
| 6 | text nl "\n" |
| 7 | text sp " " |
| 8 | note code of each letter a..z: 0 vowel (and y), 1..6 consonant groups, 7 h and w (ignored) |
| 9 | text codes "01230127022455012623017202" |
| 10 | text n0 "Robert" |
| 11 | text n1 "Rupert" |
| 12 | text n2 "Rubin" |
| 13 | text n3 "Ashcraft" |
| 14 | text n4 "Ashcroft" |
| 15 | text n5 "Tymczak" |
| 16 | text n6 "Pfister" |
| 17 | text n7 "Honeyman" |
| 18 | text n8 "Lee" |
| 19 | text n9 "Gutierrez" |
| 20 | text n10 "Jackson" |
| 21 | text n11 "VanDeusen" |
| 22 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 23 | fn emit a view uchar * to void |
| 24 | o = ulong 0 |
| 25 | while lt o len a bound 4096 |
| 26 | k = write 1 a o sub len a o |
| 27 | if le k 0 |
| 28 | exit 1 |
| 29 | end |
| 30 | o = add o ulong k |
| 31 | end |
| 32 | end |
| 33 | note American Soundex: keep the first letter, code the rest, drop repeats of the same code (h and w |
| 34 | note do not separate them, vowels do), pad with zeros to four characters |
| 35 | fn soundex a view uchar * to void |
| 36 | o = new uchar 4 48 |
| 37 | c = get a 0 |
| 38 | if ge c 97 |
| 39 | c = sub c 32 |
| 40 | end |
| 41 | put o 0 c |
| 42 | prev = get codes sub c 65 |
| 43 | k = ulong 1 |
| 44 | for i ulong sub len a 1 |
| 45 | x = get a add i 1 |
| 46 | if ge x 97 |
| 47 | x = sub x 32 |
| 48 | end |
| 49 | d = get codes sub x 65 |
| 50 | if eq d 48 |
| 51 | prev = d |
| 52 | else |
| 53 | if and ne d 55 ne d prev |
| 54 | if lt k 4 |
| 55 | put o k d |
| 56 | k = add k 1 |
| 57 | end |
| 58 | prev = d |
| 59 | end |
| 60 | end |
| 61 | end |
| 62 | emit a |
| 63 | emit sp |
| 64 | emit o |
| 65 | emit nl |
| 66 | end |
| 67 | fn main to int |
| 68 | soundex n0 |
| 69 | soundex n1 |
| 70 | soundex n2 |
| 71 | soundex n3 |
| 72 | soundex n4 |
| 73 | soundex n5 |
| 74 | soundex n6 |
| 75 | soundex n7 |
| 76 | soundex n8 |
| 77 | soundex n9 |
| 78 | soundex n10 |
| 79 | soundex n11 |
| 80 | ret 0 |
| 81 | end |
| 82 | </syntaxhighlight> |
| 83 | {{out}} |
| 84 | <pre> |
| 85 | Robert R163 |
| 86 | Rupert R163 |
| 87 | Rubin R150 |
| 88 | Ashcraft A261 |
| 89 | Ashcroft A261 |
| 90 | Tymczak T522 |
| 91 | Pfister P236 |
| 92 | Honeyman H555 |
| 93 | Lee L000 |
| 94 | Gutierrez G362 |
| 95 | Jackson J250 |
| 96 | VanDeusen V532 |
| 97 | </pre> |