| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 |
;;; ;;; |
| 3 |
;;; Language Technologies Institute ;;; |
| 4 |
;;; Carnegie Mellon University ;;; |
| 5 |
;;; Copyright (c) 2000 ;;; |
| 6 |
;;; All Rights Reserved. ;;; |
| 7 |
;;; ;;; |
| 8 |
;;; Permission is hereby granted, free of charge, to use and distribute ;;; |
| 9 |
;;; this software and its documentation without restriction, including ;;; |
| 10 |
;;; without limitation the rights to use, copy, modify, merge, publish, ;;; |
| 11 |
;;; distribute, sublicense, and/or sell copies of this work, and to ;;; |
| 12 |
;;; permit persons to whom this work is furnished to do so, subject to ;;; |
| 13 |
;;; the following conditions: ;;; |
| 14 |
;;; 1. The code must retain the above copyright notice, this list of ;;; |
| 15 |
;;; conditions and the following disclaimer. ;;; |
| 16 |
;;; 2. Any modifications must be clearly marked as such. ;;; |
| 17 |
;;; 3. Original authors' names are not deleted. ;;; |
| 18 |
;;; 4. The authors' names are not used to endorse or promote products ;;; |
| 19 |
;;; derived from this software without specific prior written ;;; |
| 20 |
;;; permission. ;;; |
| 21 |
;;; ;;; |
| 22 |
;;; CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ;;; |
| 23 |
;;; DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ;;; |
| 24 |
;;; ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ;;; |
| 25 |
;;; SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ;;; |
| 26 |
;;; FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;;; |
| 27 |
;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ;;; |
| 28 |
;;; AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ;;; |
| 29 |
;;; ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ;;; |
| 30 |
;;; THIS SOFTWARE. ;;; |
| 31 |
;;; ;;; |
| 32 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 33 |
;;; Author: Alan W Black ([email protected]) ;;; |
| 34 |
;;; Date: December 2000 ;;; |
| 35 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 36 |
;;; ;;; |
| 37 |
;;; Convert a phoneset to a C compilable structure ;;; |
| 38 |
;;; ;;; |
| 39 |
;;; (phonesettoC "cmu_klingon" (car (load "cmu_klingon_worf_phoneset.scm" t)) "pau" ".") |
| 40 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 41 |
|
| 42 |
(defvar featval_ids nil) |
| 43 |
|
| 44 |
(define (phonesettoC name phonesetdef silence odir) |
| 45 |
"(phonesettoC name phonesetdef ODIR) |
| 46 |
Convert a Phoneset definition to a C structure in ODIR/NAME_phoneset.c." |
| 47 |
(let |
| 48 |
((ofdc (fopen (path-append odir (string-append name "_phoneset.c")) "w")) |
| 49 |
(i 0)) |
| 50 |
(format ofdc "/*******************************************************/\n") |
| 51 |
(format ofdc "/** Autogenerated phoneset trees for %s */\n" name) |
| 52 |
(format ofdc "/*******************************************************/\n") |
| 53 |
(format ofdc "\n") |
| 54 |
(format ofdc "#include \"cst_string.h\"\n") |
| 55 |
(format ofdc "#include \"cst_phoneset.h\"\n") |
| 56 |
(format ofdc "extern const cst_phoneset %s_phoneset;\n" name) |
| 57 |
|
| 58 |
(set! featval_ids nil) |
| 59 |
(format ofdc "\n\n") |
| 60 |
;;; feature names |
| 61 |
(format ofdc "static const char * const %s_featnames[] = {\n" name) |
| 62 |
(mapcar |
| 63 |
(lambda (fn) (format ofdc " \"%s\",\n" fn)) |
| 64 |
(mapcar car (caddr phonesetdef))) |
| 65 |
(format ofdc " NULL };\n\n") |
| 66 |
|
| 67 |
;;; Phone names |
| 68 |
(format ofdc "static const char * const %s_phonenames[] = {\n" name) |
| 69 |
(mapcar |
| 70 |
(lambda (pn) (format ofdc " \"%s\",\n" pn)) |
| 71 |
(mapcar car (caddr (cdr phonesetdef)))) |
| 72 |
(format ofdc " NULL };\n\n") |
| 73 |
(set! num_phones (length (caddr (cdr phonesetdef)))) |
| 74 |
|
| 75 |
;;; Feature table (do values afterwards) |
| 76 |
(set! i 0) |
| 77 |
(mapcar |
| 78 |
(lambda (pdef) |
| 79 |
(format ofdc "static const int %s_fv_%03d[] = { " name i) |
| 80 |
(mapcar |
| 81 |
(lambda (fv) |
| 82 |
(format ofdc "%d, " (phonesettoC_featval_id fv))) |
| 83 |
(cdr pdef)) |
| 84 |
(set! i (+ i 1)) |
| 85 |
(format ofdc " -1 };\n")) |
| 86 |
(caddr (cdr phonesetdef))) |
| 87 |
(format ofdc "static const int %s_fv_%03d[] = { 0 };\n\n" name i) |
| 88 |
|
| 89 |
(set! i 0) |
| 90 |
(format ofdc "static const int * const %s_fvtable[] = {\n" name ) |
| 91 |
(mapcar |
| 92 |
(lambda (pdef) |
| 93 |
(format ofdc " %s_fv_%03d, \n" name i) |
| 94 |
(set! i (+ i 1))) |
| 95 |
(caddr (cdr phonesetdef))) |
| 96 |
(format ofdc " %s_fv_%03d };\n\n" name i) |
| 97 |
|
| 98 |
;;; Feature values |
| 99 |
(set! i 0) |
| 100 |
(mapcar |
| 101 |
(lambda (fv) |
| 102 |
(format ofdc "DEF_STATIC_CONST_VAL_STRING(featval_%d,\"%s\");\n" i fv) |
| 103 |
(set! i (+ i 1))) |
| 104 |
(mapcar car (reverse featval_ids))) |
| 105 |
(format ofdc "\n") |
| 106 |
|
| 107 |
(format ofdc "static const cst_val * const %s_featvals[] = {\n" name) |
| 108 |
(set! i 0) |
| 109 |
(mapcar |
| 110 |
(lambda (fv) |
| 111 |
(format ofdc " (cst_val *)&featval_%d,\n" i) |
| 112 |
(set! i (+ i 1))) |
| 113 |
(mapcar car (reverse featval_ids))) |
| 114 |
(format ofdc " NULL };\n\n") |
| 115 |
|
| 116 |
(format ofdc "const cst_phoneset %s_phoneset = {\n" name) |
| 117 |
(format ofdc " \"%s\",\n" name) |
| 118 |
(format ofdc " %s_featnames,\n" name) |
| 119 |
(format ofdc " %s_featvals,\n" name) |
| 120 |
(format ofdc " %s_phonenames,\n" name) |
| 121 |
(format ofdc " \"%s\",\n" silence) |
| 122 |
(format ofdc " %d,\n" num_phones) |
| 123 |
(format ofdc " %s_fvtable,\n" name) |
| 124 |
(format ofdc " 0 /* not freeable */\n") |
| 125 |
(format ofdc "};\n") |
| 126 |
|
| 127 |
(fclose ofdc) |
| 128 |
)) |
| 129 |
|
| 130 |
(define (phonesettoC_featval_id f) |
| 131 |
(let ((fn (assoc_string f featval_ids))) |
| 132 |
(cond |
| 133 |
(fn |
| 134 |
(cadr fn)) |
| 135 |
(t |
| 136 |
(set! featval_ids |
| 137 |
(cons (list f (length featval_ids)) |
| 138 |
featval_ids)) |
| 139 |
(phonesettoC_featval_id f))))) |
| 140 |
|
| 141 |
(provide 'make_phoneset) |