| | 1 | #include <tads.h> |
| | 2 | #include <strcomp.h> |
| | 3 | #include <dict.h> |
| | 4 | |
| | 5 | dictionary cmdDict; |
| | 6 | |
| | 7 | main(args) |
| | 8 | { |
| | 9 | "Hello, world!\n"; |
| | 10 | cmdDict.addWord(test, 'test', &noun); |
| | 11 | cmdDict.addWord(test, 'init', &adjective); |
| | 12 | |
| | 13 | local x = cmdDict.findWord('test'); |
| | 14 | } |
| | 15 | |
| | 16 | test: InitObject |
| | 17 | execute() { |
| | 18 | // This works when we use StringComparator |
| | 19 | // instead of SoundexStringComparator here: |
| | 20 | local cmpObj = |
| | 21 | new SoundexStringComparator(0, nil, [['a','a',0,0]]); |
| | 22 | cmdDict.setComparator(cmpObj); |
| | 23 | "...done with init...\n"; |
| | 24 | } |
| | 25 | ; |
| | 26 | |
| | 27 | class SoundexStringComparator: object |
| | 28 | cmp = nil |
| | 29 | construct(truncLen, caseSensitive, mappings) { |
| | 30 | cmp = |
| | 31 | new StringComparator(truncLen, caseSensitive, mappings); |
| | 32 | } |
| | 33 | calcHash(str) { "...calcHash...\n"; return cmp.calcHash(canonicalize(str)); } |
| | 34 | matchValues(inputStr, dictStr) { |
| | 35 | "...matchValues...\n"; |
| | 36 | return cmp.matchValues(canonicalize(inputStr), |
| | 37 | canonicalize(dictStr)); |
| | 38 | } |
| | 39 | canonicalize(str) { |
| | 40 | return str; //soundex(str); |
| | 41 | } |
| | 42 | ; |
| | 43 | |