| 25 | | my $firstloop = 1; |
|---|
| 26 | | foreach my $word ($doc->findnodes('/ken/word')) { |
|---|
| 27 | | my ($attr) = $word->attributes(); |
|---|
| 28 | | print $word->nodeName . ":" . $attr->to_literal() . "\n"; |
|---|
| 29 | | my @childnodes = $word->childNodes; |
|---|
| 30 | | displayChildNodes(@childnodes); |
|---|
| 31 | | if ($firstloop) { |
|---|
| 32 | | print "VoxForge Missing Word processing (q to quit)\n"; |
|---|
| 33 | | $firstloop = 0; |
|---|
| 34 | | } |
|---|
| 35 | | my $phonesSelected = 0; |
|---|
| 36 | | while (defined(my $line=$term->readline($prompt))) { |
|---|
| | 26 | print "VoxForge Missing Word processing (q to quit)\n"; |
|---|
| | 27 | print "--------------------------------------------\n"; |
|---|
| | 28 | |
|---|
| | 29 | my @processedWordsPhones; |
|---|
| | 30 | my $wordNumber = 0; |
|---|
| | 31 | my @wordList = $doc->findnodes('/ken/word'); |
|---|
| | 32 | while (1) { |
|---|
| | 33 | my $wordRef = $wordList[$wordNumber]; |
|---|
| | 34 | my $command = process($wordRef,$wordNumber,\@processedWordsPhones); |
|---|
| | 35 | if ($command eq "back") { |
|---|
| | 36 | if ($wordNumber-1 >= 0 ) { |
|---|
| | 37 | $wordNumber--; |
|---|
| | 38 | } else { |
|---|
| | 39 | print color("red"), "\ncan\'t go back, already at beginning\n" , color("reset"); |
|---|
| | 40 | } |
|---|
| | 41 | } elsif ($command eq "next") { |
|---|
| | 42 | if ($wordNumber < (@wordList - 1)) { |
|---|
| | 43 | $wordNumber++; |
|---|
| | 44 | } else { |
|---|
| | 45 | exit; |
|---|
| | 46 | } |
|---|
| | 47 | } |
|---|
| | 48 | } |
|---|
| | 49 | |
|---|
| | 50 | updateDictionary(\@processedWordsPhones); |
|---|
| | 51 | print "completed!\n"; |
|---|
| | 52 | |
|---|
| | 53 | ##################################################### |
|---|
| | 54 | # methods |
|---|
| | 55 | ##################################################### |
|---|
| | 56 | sub process{ |
|---|
| | 57 | my ($wordRef,$wordNumber,$processedWordsPhones)= @_; |
|---|
| | 58 | my $phonesPreviouslySelected = 0; |
|---|
| | 59 | my ($attrRef) = $wordRef->attributes(); |
|---|
| | 60 | my $word = $attrRef->to_literal(); |
|---|
| | 61 | |
|---|
| | 62 | displayChildNodes($wordRef); |
|---|
| | 63 | while (defined(my $line=$term->readline($prompt))) { # get command from user |
|---|
| 52 | | print "\n$line:\t$phoneSelector[$asciiOfFirstCharacter]\n"; |
|---|
| 53 | | $phonesSelected = $phoneSelector[$asciiOfFirstCharacter]; |
|---|
| | 77 | print "\nSelected phone set:"; |
|---|
| | 78 | print color("green"),"$line:\t$phoneSelector[$asciiOfFirstCharacter]\n" , color("reset"); |
|---|
| | 79 | print "(press \"@\" then hit <enter> key to accept, and move to next word)\n"; |
|---|
| | 80 | print "(enter \"@\" followed by your own phone sequence, and then hit <enter> key)\n"; |
|---|
| | 81 | print "(enter \"^\" to go back one entry)\n"; |
|---|
| | 82 | $phonesPreviouslySelected = $phoneSelector[$asciiOfFirstCharacter]; |
|---|
| 57 | | } elsif (($line eq '@') and ($phonesSelected)) { |
|---|
| 58 | | print "phone selected: $phonesSelected\n"; |
|---|
| 59 | | last; |
|---|
| | 86 | } elsif (($line eq '@') and ($phonesPreviouslySelected)) { # phoneme set selected by user |
|---|
| | 87 | $$processedWordsPhones[$wordNumber] = [$word,$phonesPreviouslySelected]; |
|---|
| | 88 | return "next"; |
|---|
| | 89 | } elsif (($line =~ /^\@(.+)$/) and ($phonesPreviouslySelected)) { # phoneme set selected by user |
|---|
| | 90 | $$processedWordsPhones[$wordNumber] = [$word,$1]; |
|---|
| | 91 | return "next"; |
|---|
| | 92 | } elsif ($line eq '^') { # back one |
|---|
| | 93 | if (($wordNumber -1)>0) { |
|---|
| | 94 | $wordNumber = $wordNumber -1; |
|---|
| | 95 | } |
|---|
| | 96 | return "back"; |
|---|
| 65 | | print "the end!\n"; |
|---|
| | 103 | |
|---|
| | 104 | sub displayChildNodes { |
|---|
| | 105 | my ($wordRef)= @_; |
|---|
| | 106 | my $promptSelector = 1; |
|---|
| | 107 | my $phoneSelector = 97; |
|---|
| | 108 | my ($attrRef) = $wordRef->attributes(); |
|---|
| | 109 | my $word = $attrRef->to_literal(); |
|---|
| | 110 | my @childNodes = $wordRef->childNodes; |
|---|
| | 111 | |
|---|
| | 112 | print $wordRef->nodeName . " " . ($wordNumber +1) ." of " . scalar(@wordList). ":"; |
|---|
| | 113 | print color("green"), $word . "\n" , color("reset"); |
|---|
| | 114 | foreach my $child (@childNodes) { |
|---|
| | 115 | if ($child->nodeName eq "prompt") { |
|---|
| | 116 | my ($attr) = $child->attributes; |
|---|
| | 117 | my $promptID=$attr->to_literal; |
|---|
| | 118 | my $prompt=$child->to_literal; |
|---|
| | 119 | |
|---|
| | 120 | print "$promptSelector:"; |
|---|
| | 121 | print $promptID . ":" . $prompt . "\n"; |
|---|
| | 122 | $promptSelector[$promptSelector] = $promptID; |
|---|
| | 123 | $promptSelector++; |
|---|
| | 124 | } |
|---|
| | 125 | if ($child->nodeName eq "g2pPhones") { |
|---|
| | 126 | my $phones = $child->to_literal; |
|---|
| | 127 | |
|---|
| | 128 | print " " . chr($phoneSelector) . ":g2p:\t" . $phones . "\n"; |
|---|
| | 129 | $phoneSelector[$phoneSelector] = $phones; |
|---|
| | 130 | $phoneSelector++; |
|---|
| | 131 | } |
|---|
| | 132 | if ($child->nodeName eq "hvitePhones") { |
|---|
| | 133 | my ($attr) = $child->attributes; |
|---|
| | 134 | my $promptID=$attr->to_literal; |
|---|
| | 135 | my $phones = $child->to_literal; |
|---|
| | 136 | |
|---|
| | 137 | print " " . chr($phoneSelector) . ":"; |
|---|
| | 138 | print $promptID . ":\t" . $phones . "\n"; |
|---|
| | 139 | $phoneSelector[$phoneSelector] = $phones; |
|---|
| | 140 | $phoneSelector++; |
|---|
| | 141 | } |
|---|
| | 142 | } |
|---|
| | 143 | } |
|---|
| | 144 | |
|---|
| | 145 | sub updateDictionary { |
|---|
| | 146 | my ($word,$phonesSelected)= @_; |
|---|
| | 147 | open(MISSINGWORDSFINAL,">AudioBook/interim_files/MissingWords_final") or confess ("cannot open AudioBook/interim_files/MissingWords_final file"); |
|---|
| | 148 | foreach my $line (@$phonesSelected) { |
|---|
| | 149 | print "$line\n"; |
|---|
| | 150 | my $word = @$line[0]; |
|---|
| | 151 | my $phonesSelected = @$line[1]; |
|---|
| | 152 | print MISSINGWORDSFINAL "$word\t[$word]\t$phonesSelected\n"; |
|---|
| | 153 | } |
|---|
| | 154 | close MISSINGWORDSFINAL; |
|---|
| | 155 | } |
|---|
| 74 | | sub displayChildNodes { |
|---|
| 75 | | my (@childnodes)= @_; |
|---|
| 76 | | my $promptSelector = 1; |
|---|
| 77 | | my $phoneSelector = 97; |
|---|
| 78 | | foreach my $child (@childnodes) { |
|---|
| 79 | | if ($child->nodeName eq "prompt") { |
|---|
| 80 | | print "$promptSelector:"; |
|---|
| 81 | | my ($attr) = $child->attributes(); |
|---|
| 82 | | print $attr->to_literal() . ":" . $child->to_literal . "\n"; |
|---|
| 83 | | $promptSelector[$promptSelector] = $attr->to_literal; |
|---|
| 84 | | $promptSelector++; |
|---|
| 85 | | } |
|---|
| 86 | | if ($child->nodeName eq "g2pPhones") { |
|---|
| 87 | | print " " . chr($phoneSelector) . ":\t\t" . $child->to_literal . "\n"; |
|---|
| 88 | | $phoneSelector[$phoneSelector] = $child->to_literal; |
|---|
| 89 | | $phoneSelector++; |
|---|
| 90 | | } |
|---|
| 91 | | if ($child->nodeName eq "hvitePhones") { |
|---|
| 92 | | print " " . chr($phoneSelector) . ":"; |
|---|
| 93 | | my ($attr) = $child->attributes(); |
|---|
| 94 | | print $attr->to_literal() . ":\t" . $child->to_literal . "\n"; |
|---|
| 95 | | $phoneSelector[$phoneSelector] = $child->to_literal; |
|---|
| 96 | | $phoneSelector++; |
|---|
| 97 | | } |
|---|
| 98 | | } |
|---|
| 99 | | } |
|---|
| | 168 | |
|---|
| | 169 | |
|---|