|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (lts_rules_predict word feats) |
|
(let ((dcword (downcase word)) |
|
(syls) (phones)) |
|
(if (string-matches dcword "[a-z]*") |
|
(begin |
|
(set! phones |
|
(cdr (reverse (cdr (reverse (lts_predict dcword)))))) |
|
(set! phones (add_lex_stress word feats phones)) |
|
(set! syls (lex.syllabify.phstress phones)) |
|
|
|
) |
|
(set! syls nil)) |
|
(format t "word %l phones %l\n" word syls) |
|
(list word nil syls))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (word-is-content word guess_pos) |
|
(cond |
|
((null guess_pos) |
|
t) |
|
((member_string word (cdr (car guess_pos))) |
|
nil) |
|
(t |
|
(word-is-content word (cdr guess_pos))))) |
|
|
|
(defvar lts_pos nil) |
|
|
|
(define (lts_predict word rules) |
|
"(lts_predict word rules) |
|
Return list of phones related to word using CART trees." |
|
(let ((utt (make_let_utt (enworden (wordexplode word))))) |
|
(predict_phones utt rules) |
|
(cdr (reverse (cdr (reverse |
|
(mapcar |
|
(lambda (p) (intern (item.name p))) |
|
(utt.relation.items utt 'PHONE)))))) |
|
) |
|
) |
|
|
|
(define (wordexplode lets) |
|
(if (consp lets) |
|
lets |
|
(symbolexplode lets))) |
|
|
|
(define (make_let_utt letters) |
|
"(make_let_utt letters) |
|
Build an utterances from th4ese letters." |
|
(let ((utt (Utterance Text ""))) |
|
(utt.relation.create utt 'LTS) |
|
(utt.relation.create utt 'LETTER) |
|
(utt.relation.create utt 'PHONE) |
|
|
|
(mapcar |
|
(lambda (l) |
|
(let ((lsi (utt.relation.append utt 'LETTER))) |
|
(item.set_feat lsi "pos" lts_pos) |
|
(item.set_name lsi l))) |
|
letters) |
|
utt)) |
|
|
|
(define (predict_phones utt rules) |
|
"(predict_phones utt) |
|
Predict phones using CART." |
|
(add_new_phone utt (utt.relation.first utt 'LETTER) '#) |
|
(mapcar |
|
(lambda (lsi) |
|
(let ((tree (car (cdr (assoc_string (item.name lsi) rules))))) |
|
(if (not tree) |
|
(format t "failed to find tree for %s\n" (item.name lsi)) |
|
(let ((p (wagon_predict lsi tree))) |
|
|
|
(cond |
|
((string-matches p ".*-.*-.*-.*") |
|
(add_new_phone utt lsi (string-before p "-")) |
|
(add_new_phone utt lsi (string-before (string-after p "-") "-")) |
|
(add_new_phone utt lsi (string-before (string-after (string-after p "-") "-") "-")) |
|
(add_new_phone utt lsi (string-after (string-after (string-after p "-") "-") "-"))) |
|
((string-matches p ".*-.*-.*") |
|
(add_new_phone utt lsi (string-before p "-")) |
|
(add_new_phone utt lsi (string-before (string-after p "-") "-")) |
|
(add_new_phone utt lsi (string-after (string-after p "-") "-"))) |
|
((string-matches p ".*-.*") |
|
(add_new_phone utt lsi (string-before p "-")) |
|
(add_new_phone utt lsi (string-after p "-"))) |
|
(t |
|
(add_new_phone utt lsi p))))))) |
|
(reverse (cdr (reverse (cdr (utt.relation.items utt 'LETTER)))))) |
|
(add_new_phone utt (utt.relation.last utt 'LETTER) '#) |
|
utt) |
|
|
|
(define (add_new_phone utt lsi p) |
|
"(add_new_phone utt lsi p) |
|
Add new phone linking to letter, ignoreing it if its _epsilon_." |
|
(if (not (equal? p '_epsilon_)) |
|
(let ((psi (utt.relation.append utt 'PHONE))) |
|
(item.set_name psi p) |
|
(item.relation.append_daughter |
|
(utt.relation.append utt 'LTS lsi) |
|
'LTS psi) |
|
))) |
|
|
|
(define (enworden lets) |
|
(cons '# (reverse (cons '# (reverse lets))))) |
|
|
|
|
|
|
|
|
|
(define (add_lex_stress word pos phones tree) |
|
"(add_lex_stress word syls) |
|
Predict lexical stress by decision tree." |
|
(let ((utt (Utterance Text "")) |
|
(si) |
|
(nphones)) |
|
(utt.relation.create utt 'Letter) |
|
(set! si (utt.relation.append utt 'Letter)) |
|
(item.set_feat si 'pos pos) |
|
(item.set_feat si 'numsyls (count_syls phones)) |
|
(item.set_feat si 'sylpos 1) |
|
(set! nphones (add_lex_stress_syl phones si tree)) |
|
|
|
|
|
nphones)) |
|
|
|
(define (count_syls phones) |
|
(cond |
|
((null phones) 0) |
|
((string-matches (car phones) "[aeiou@].*") |
|
(+ 1 (count_syls (cdr phones)))) |
|
(t (count_syls (cdr phones))))) |
|
|
|
(define (add_lex_stress_syl phones si tree) |
|
"(add_lex_stress_syl phones si tree) |
|
Add lexical stressing." |
|
(cond |
|
((null phones) nil) |
|
((string-matches (car phones) "[aeiou@].*") |
|
(item.set_feat si 'phone (car phones)) |
|
(item.set_feat si 'name (car phones)) |
|
(item.set_feat si 'num2end |
|
(- (+ 1 (item.feat si 'numsyls)) |
|
(item.feat si 'sylpos))) |
|
(set! stress (wagon_predict si tree)) |
|
(item.set_feat si 'sylpos |
|
(+ 1 (item.feat si 'sylpos))) |
|
(cons |
|
(if (not (string-equal stress "0")) |
|
(string-append (car phones) stress) |
|
(car phones)) |
|
(add_lex_stress_syl (cdr phones) si tree))) |
|
(t |
|
(cons |
|
(car phones) |
|
(add_lex_stress_syl (cdr phones) si tree))))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'lts) |
|
|