home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / fest-141.zip / festival / examples / addr-mode.scm next >
Lisp/Scheme  |  1999-05-30  |  13KB  |  362 lines

  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. ;;;  An address mode for reading lists of names, addresses and
  35. ;;;  telephone numbers.  Takes quite an aggressive view of the data.
  36. ;;;
  37. ;;;  This was used for the CSTR's entry in the evaluations at the
  38. ;;;  ESCA workshop on Speech Synthesis in Janolen Caves, Blue Mountains,
  39. ;;;  NSW, Australia.
  40. ;;;
  41. ;;;  This can read things like
  42. ;;;  Brown, Bill,  6023 Wiser Rd, Austin, TX 76313-2837,  817-229-7849 
  43. ;;;  Green, Bob,  3076 Wabash Ct, Fort Worth, TX 76709-1368,  (817)292-9015 
  44. ;;;  Smith, Bobbie Q,  3337 St Laurence St, Fort Worth, TX 71611-5484,  (817)839-3689
  45. ;;;  Jones, Billy,  5306 Dr Dana Lynn Dr, Fort Worth, TX 71637-2547,  817 845 6154 
  46. ;;;  Henderson, Bryan J,  5808 Sycamore Creek Rd Apt R, Fort Worth, TX 76134-1906,  (817)239-4634 
  47. ;;;  Black, Alan W, 130 S 18th St #3, Pittsburgh, PA 15205, (412)268-8189
  48. ;;;  Bowman, K,  2610 W Bowie St, El Paso, TX 76019-1712,  (817)268-7257 
  49. ;;;  Sydney, Aaron A,  1521 NW Ballard Way, Seattle, WA 91807-4712,  (206)783-8645
  50. ;;;  Anderson, A,  12012 Pinehurst Way NE, Seattle, NE 98125-5108,  (212)404-9988 
  51.  
  52. ;; New lines without trailing continuation punctuation signal EOU
  53. (defvar addr_eou_tree 
  54. '((n.whitespace matches ".*\n.*") ;; any new line
  55.   ((punc in ("," ":"))
  56.    ((0))
  57.    ((1)))))
  58.  
  59. (set! addr_phrase_cart_tree
  60. '
  61. ((pbreak is "B")
  62.  ((B))
  63.  ((pbreak is "BB")
  64.   ((BB))
  65.   ((lisp_token_end_punc in ("?" "." ":" "'" "\"" "," ";"))
  66.    ((B))
  67.    ((n.name is 0)  ;; end of utterance
  68.     ((BB))
  69.     ((NB)))))))
  70.  
  71. (define (addr_init_func)
  72.  "Called on starting addr text mode."
  73.  (Parameter.set 'Phrase_Method 'cart_tree)
  74.  (set! phrase_cart_tree addr_phrase_cart_tree)
  75.  (set! int_lr_params
  76.        '((target_f0_mean 105) (target_f0_std 12)
  77.      (model_f0_mean 170) (model_f0_std 34)))
  78.  (Parameter.set 'Duration_Stretch 1.1)
  79.  (set! addr_previous_t2w_func english_token_to_words)
  80.  (set! english_token_to_words addr_token_to_words)
  81.  (set! token_to_words addr_token_to_words)
  82.  (set! addr_previous_eou_tree eou_tree)
  83.  (set! eou_tree addr_eou_tree))
  84.  
  85. (define (addr_exit_func)
  86.  "Called on exit addr text mode."
  87.  (Parameter.set 'Duration_Stretch 1.0)
  88.  (set! token_to_words addr_previous_t2w_func)
  89.  (set! english_token_to_words addr_previous_t2w_func)
  90.  (set! eou_tree addr_previous_eou_tree))
  91.  
  92. (set! addr_regex_ZIPCODE2 "[0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")
  93.  
  94. (set! addr_regex_USPHONE3 "[0-9][0-9][0-9])[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")
  95. (set! addr_regex_USPHONE1 "[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")
  96.  
  97. (set! addr_tiny_break (list '(name "<break>") '(pbreak mB)))
  98. (set! addr_small_break (list '(name "<break>") '(pbreak B)))
  99. (set! addr_large_break (list '(name "<break>") '(pbreak BB)))
  100.  
  101. (define (addr_within_name_part token)
  102.   "(addr_within_name_part token)
  103. Heuristic guess if we are still in the name (i.e. pre-address)
  104. this is desgined to stop Mr W Smith becoming West."
  105.   (cond
  106.    ((addr_preceeding_number token)
  107.     ;; any preceeding token with a digit
  108.     nil)
  109.    (t
  110.     t)))
  111.  
  112. (define (addr_preceeding_number tok)
  113.   (cond
  114.    ((null tok) nil)
  115.    ((string-matches (item.name tok) ".*[0-9].*")
  116.     t)
  117.    (t (addr_preceeding_number (item.prev tok)))))
  118.  
  119. (define (addr_succeeding_non_number tok)
  120.   (cond
  121.    ((null tok) nil)
  122.    ((string-matches (item.name tok) ".*[A-Za-z].*")
  123.     t)
  124.    (t (addr_succeeding_non_number (item.next tok)))))
  125.  
  126. (define (addr_token_to_words token name)
  127.   "(addr_token_to_words token name)
  128. Address specific text reading mode.  Lots of address specific abbreviations
  129. and phrasing etc."
  130.   (set! utt_addr (item.get_utt token))
  131.   (let ((type (item.feat token "token_type")))
  132.     (cond
  133.      ((string-matches name "A")
  134.       (list (list '(name "a") '(pos nn))))
  135.      ((addr_within_name_part token)
  136.        (builtin_english_token_to_words token name)
  137.       )
  138.      ((string-matches name "\\([dD][Rr]\\|[Ss][tT]\\)")
  139.       (if (string-equal (item.feat token "token_pos") "street")
  140.       (if (string-matches name "[dD][rR]")
  141.           (list "drive")
  142.           (list "street"))
  143.       (if (string-matches name "[dD][rR]")  ;; default on title side
  144.           (list "doctor")
  145.           (list "saint"))))
  146.      ((string-matches name addr_regex_ZIPCODE2)
  147.       ;; Zip code 
  148.       (item.set_feat token "token_pos" "digits")
  149.       (append
  150.        (builtin_english_token_to_words token (string-before name "-"))
  151.        (list addr_small_break)
  152.        (builtin_english_token_to_words token (string-after name "-"))
  153.        (list addr_large_break)))
  154.      ((string-matches name addr_regex_USPHONE3)
  155.       (item.set_feat token "token_pos" "digits")
  156.       (append
  157.        (builtin_english_token_to_words token (string-before name ")"))
  158.        (list addr_small_break)
  159.        (builtin_english_token_to_words token 
  160.      (string-after (string-before name "-") ")"))
  161.        (list addr_small_break)
  162.        (builtin_english_token_to_words token (string-after name "-"))))
  163.      ((string-matches name addr_regex_USPHONE1)
  164.       (item.set_feat token "token_pos" "digits")
  165.       (append
  166.        (builtin_english_token_to_words token (string-before name "-"))
  167.        (list addr_small_break)
  168.        (builtin_english_token_to_words token 
  169.      (string-before (string-after name "-") "-"))
  170.        (list addr_small_break)
  171.        (builtin_english_token_to_words token 
  172.      (string-after (string-after name "-") "-"))))
  173.      ((string-equal name "NE")
  174.       (cond
  175.        ((string-matches (item.feat token "n.name") addr_regex_ZIPCODE2)
  176.     (list "Nebraska"))
  177.        ;; could check if there is a state following it
  178.        (t
  179.     (list "North" "East"))))
  180.      ((set! full (addr_undo_abbrev name addr_addr_abbrevs))
  181.       (cdr full))
  182.      ((string-matches name "#.*")
  183.       (cons
  184.        "number"
  185.        (builtin_english_token_to_words token (string-after name "#"))))
  186.      ((string-matches name "[0-9][0-9][0-9][0-9][0-9]+")
  187.       ;; long number
  188.       (item.set_feat token "token_pos" "digits")
  189.       (builtin_english_token_to_words token name))
  190.      ((or (string-matches name "[0-9]0[0-9][0-9]")
  191.       (string-matches name "[0-9][0-9]0[0-9]"))
  192.       (item.set_feat token "token_pos" "digits")
  193.       (mapcar
  194.        (lambda (a)
  195.      (if (string-equal a "zero")
  196.          "oh"
  197.          a))
  198.        (builtin_english_token_to_words token name)))
  199.      ((and
  200.        (addr_succeeding_non_number token)
  201.        (string-matches name "[0-9][0-9][0-9][0-9]"))
  202.       ;; four digit number 
  203.       (let (block number)
  204.     (item.set_feat token "token_pos" "number")
  205.     (set! block 
  206.           (builtin_english_token_to_words 
  207.            token (substring name 0 2)))
  208.     (if (string-equal (nth 2 (symbolexplode name)) "0")
  209.         (item.set_feat token "token_pos" "digits")
  210.         (item.set_feat token "token_pos" "number"))
  211.     (set! number
  212.           (builtin_english_token_to_words 
  213.            token (substring name 2 2)))
  214.     (append
  215.      block 
  216.      (list addr_tiny_break)
  217.      number)))
  218.      ((and 
  219.        (addr_succeeding_non_number token)
  220.        (string-matches name "[0-9][0-9][0-9]"))
  221.       ;; four digit number 
  222.       (let (block number)
  223.     (item.set_feat token "token_pos" "number")
  224.     (set! block 
  225.           (builtin_english_token_to_words 
  226.            token (substring name 0 1)))
  227.     (if (string-equal (nth 1 (symbolexplode name)) "0")
  228.         (item.set_feat token "token_pos" "digits")
  229.         (item.set_feat token "token_pos" "number"))
  230.     (set! number
  231.           (builtin_english_token_to_words 
  232.            token (substring name 1 2)))
  233.     (append
  234.      block number)))
  235.      ((string-matches name "[0-9]+")
  236.       (item.set_feat token "token_pos" "digits")
  237.       (builtin_english_token_to_words token name))
  238.      (t  ;; for all other cases
  239.       (addr_previous_t2w_func token name)))))
  240.  
  241. (define (addr_undo_abbrev name abbrevs)
  242. "(addr_undo_abbrev name abbrevs)
  243. General abbreviation undoer.  Looks for name in reverse assoc
  244. list and returns the value."
  245.   (cond
  246.    ((null abbrevs) nil)
  247.    ((member_string name (car (car abbrevs)))
  248.     (car abbrevs))
  249.    (t
  250.     (addr_undo_abbrev name (cdr abbrevs)))))
  251.  
  252. (set! tts_text_modes
  253.    (cons
  254.     (list
  255.       'addr         ;; mode name
  256.       (list         ;; addr mode params
  257.        (list 'init_func addr_init_func)
  258.        (list 'exit_func addr_exit_func)))
  259.     tts_text_modes))
  260.  
  261. (set! addr_us_states
  262.       '((( AL Ala ) Alabama )
  263.     (( AK ) Alaska )
  264.     (( AR ) Arkansas )
  265.     (( AZ Ariz ) Arizona )
  266.     (( CA Cal Calif ) California )
  267.     (( CO Colo ) Colorado )
  268.     (( CT Conn ) Connecticutt )
  269.     (( DC ) DC )
  270.     (( DE Dela ) Delaware )
  271.     (( FL Fla ) Florida )
  272.     (( GA ) Georgia )
  273.     (( HI ) Hawaii )
  274.     (( IA Ind ) Indiana )
  275.     (( ID ) Idaho )
  276.     (( IL Ill ) Illinois )
  277.     (( KS Kans ) Kansas )
  278.     (( KY ) Kentucky )
  279.     (( LA Lou Lous) Louisiana )
  280.     (( MA Mass ) Massachusetts )
  281.     (( MD ) Maryland )
  282.     (( ME ) Maine )
  283.     (( MI Mich ) Michigan )
  284.     (( MN Minn ) Minnesota )
  285.     (( MS Miss ) Mississippi )
  286.     (( MT ) Montana )
  287.     (( MO ) Missouri )
  288.     (( NC ) North Carolina )
  289.     (( ND ) North Dakota )
  290.     (( NE Neb ) Nebraska )
  291.     (( NH ) New Hampshire)
  292.     (( NV Nev ) Nevada )
  293.     (( NY ) New York )
  294.     (( OH ) Ohio )
  295.     (( OK Okla ) Oklahoma )
  296.     (( Or Ore ) Oregon )
  297.     (( PA Penn ) Pennsylvania )
  298.     (( RI ) Rhode Island )
  299.     (( SC ) Sourth Carolina )
  300.     (( SD ) Sourth Dakota )
  301.     (( TN  Tenn ) Tennessee )
  302.     (( TX Tex ) Texas )
  303.     (( UT ) Utah )
  304.     (( VA Vir ) Virginia )
  305.     (( VT ) Vermont )
  306.     (( WA Wash ) Washington )
  307.     (( WI Wisc ) Wisconsin )
  308.     (( WV ) West Virginia )
  309.     (( WY Wyom ) Wyoming )
  310.     (( PR ) Puerto Rico )
  311.     ))
  312.  
  313. (set! addr_compass_points
  314.       '(((S So Sth) South)
  315.     ((N No Nor) North)
  316.     ((E) East)
  317.     ((W) West)
  318.     ((NE) North East)
  319.     ((NW) North West)
  320.     ((SE) South East)
  321.     ((SW) South West)))
  322.  
  323. (set! addr_streets
  324.       '(((Hwy) Highway)
  325.     ((Rt Rte) Root)
  326.     ((Ct) Court)
  327.     ((Pl) Place)
  328.     ((Blvd Bld) Boulevard)
  329.     ((Ave) Avenue)
  330.     ((Rd) Road)
  331.     ((Apt App Appt) Apartment)
  332.     ((Cntr Ctr) Center)
  333.     ((Ter Terr Tr) Terrace)
  334.     ((Ln) Lane)
  335.     ((PO) pea oh)
  336.     ))
  337.  
  338. (set! addr_uk_counties
  339.       '((( Hants ) Hampshire)
  340.     (( Soton ) Southampton )
  341.     (( Berks ) Berkshire )
  342.     (( Yorks ) Yorkshire )
  343.     (( Leics ) Leicestershire )
  344.     (( Shrops ) Shropshire )
  345.     (( Cambs ) Cambridgeshire )
  346.     (( Oxon ) Oxfordshire )
  347.     (( Notts ) Nottinghamshire )
  348.     (( Humbers ) Humberside )
  349.     (( Glams ) Glamorganshire )
  350.     (( Pembs ) Pembrookeshire )
  351.     (( Lancs ) Lancashire )
  352.     (( Berwicks ) Berwickshire )
  353.     ))
  354.  
  355. (set! addr_addr_abbrevs
  356.       (append
  357.        addr_us_states
  358.        addr_compass_points
  359.        addr_streets))
  360.  
  361. (provide 'addr-mode)
  362.