| 1 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 |
;;; ;; |
| 3 |
;;; Centre for Speech Technology Research ;; |
| 4 |
;;; University of Edinburgh, UK ;; |
| 5 |
;;; Copyright (c) 1998 ;; |
| 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 |
;;; THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 |
;;; |
| 34 |
;;; |
| 35 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 36 |
;;; |
| 37 |
;;; Copyright (C) 2009-2011 Antonio Bonafonte |
| 38 |
;;; Universitat Politècnica de Catalunya, Barcelona, Spain |
| 39 |
;;; |
| 40 |
;;; This script is free software; you can redistribute it and/or |
| 41 |
;;; modify it under the terms of the GNU Lesser General Public |
| 42 |
;;; License as published by the Free Software Foundation, |
| 43 |
;;; version 2.1 of the License. |
| 44 |
;;; |
| 45 |
;;; This library is distributed in the hope that it will be useful, |
| 46 |
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 47 |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 48 |
;;; Lesser General Public License for more details. |
| 49 |
;;; |
| 50 |
;;; You should have received a copy of the GNU Lesser General Public |
| 51 |
;;; License along with this library; if not, write to the Free Software |
| 52 |
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 53 |
|
| 54 |
|
| 55 |
;;; Because this is a --script type file I have to explicitly |
| 56 |
;;; load the initfiles: init.scm and user's .festivalrc |
| 57 |
(load (path-append (if (symbol-bound? 'datadir) datadir libdir) "init.scm")) |
| 58 |
|
| 59 |
|
| 60 |
(define (reduce_lexicon2 entryfile exceptionfile lts_function mylogfile) |
| 61 |
"(reduce_lexicon2 entryfile exceptionfile lts_function) |
| 62 |
Look up each word in entryfile using the current lexicon, if the entry |
| 63 |
doesn't match save it in the exception file. This is a way of reducing |
| 64 |
the lexicon based on a letter to sound model (and lexical stress |
| 65 |
model, if appropriate)." |
| 66 |
(let ((fd (fopen entryfile "r")) |
| 67 |
(ofd (fopen exceptionfile "w")) |
| 68 |
(mylog (fopen mylogfile "w")) ; added |
| 69 |
(entry) |
| 70 |
(wordcount 0) |
| 71 |
(correctwords 0)) |
| 72 |
(format ofd "MNCL\n") ; Header |
| 73 |
(while (not (equal? (set! entry (readfp fd)) (eof-val))) |
| 74 |
(if (and (consp entry) |
| 75 |
(> (length entry) 1)) |
| 76 |
(let ((lts (lts_function (car entry) (car (cdr entry)))) |
| 77 |
(encount (lex.entrycount (car entry)))) |
| 78 |
(set! wordcount (+ 1 wordcount)) |
| 79 |
(if (and (equal? (nth 2 entry) (nth 2 lts)) |
| 80 |
(< encount 2)) |
| 81 |
(set! correctwords (+ 1 correctwords)) |
| 82 |
(begin |
| 83 |
(format ofd "%l\n" entry) |
| 84 |
(format mylog "Count: %d\n Entry: %l\nPredicted: %l\n\n" encount entry lts) ; added |
| 85 |
)) |
| 86 |
))) |
| 87 |
(fclose fd) |
| 88 |
(fclose ofd) |
| 89 |
(format t "words %d correct %d (%2.2f)\n" |
| 90 |
wordcount correctwords (/ (* correctwords 100) wordcount)) |
| 91 |
)) |
| 92 |
|
| 93 |
(set! workdir (car argv)) |
| 94 |
(set! upc_catalan::dialect (car (cdr argv))) ; unused right now. FIXME! |
| 95 |
|
| 96 |
(set! upclexdir (path-append (pwd) workdir)) |
| 97 |
|
| 98 |
(if (not (member_string upclexdir load-path)) |
| 99 |
(set! load-path (cons upclexdir load-path))) |
| 100 |
|
| 101 |
(require 'lts_build) |
| 102 |
(require 'upclex_catalan) |
| 103 |
|
| 104 |
(set! entryfile (path-append workdir (string-append "upcdict_catalan-1.0-" upc_catalan::dialect ".out"))) |
| 105 |
(set! exceptionfile (path-append workdir "upcdict_catalan.out")) |
| 106 |
(set! mylogfile (path-append workdir "upcdict_catalan.log")) |
| 107 |
(upc_catalan_lex_select_dialect upc_catalan::dialect) |
| 108 |
(set! lts_function upc_catalan_lts_function) |
| 109 |
(reduce_lexicon2 entryfile exceptionfile lts_function mylogfile) |