#!/usr/bin/perl # Copyright Hong Kong University of Science and Technology (Author: Ricky Chan) 2013. # # A script for dictionary generation with an input dict and a wordlist # # example of dict format as follow: # WORD1 ph1 ph2 # WORD2 ph1 ph2 ph3 # WORDX ph4 # WORDY ph4 ph5 # WORDZ ph3 ph1 # # example of wordlist (support phrase of words) format as follow: # WORD1 # WORD2 # WORDX WORDY # WORDX WORDY WORDZ if($#ARGV+1 != 2 && $#ARGV+1 != 3) { printUsage(); exit; } $usespron=0; if(@ARGV == 3) { if($ARGV[2] ne "--spron") { printUsage(); exit; } $usespron=1; } $dictfile=$ARGV[0]; $inputfile=$ARGV[1]; %dictionarylist=(); open(INFILE, $dictfile) || die("Can't open dict ".$dictfile."\n"); while(){ chomp; @line=split(/\s+/); $a=$line[0]; $b=""; for($i=1; $i) { chomp; $phrase = $_; @line = split(/\s+/); ## single pronunciation handling if($usespron==1) { if(scalar(@line)==0) { next; } for($i=0; $i0) { $word = $line[$0]; if(!exists($dictionarylist{$word})) { push(@pronlist, '_NOT_FOUND_'); } else { @ref=@{ $dictionarylist{$word} }; for($i=0; $i0) { push(@tmppronlist, shift(@pronlist)); } while(scalar(@tmppronlist)>0) { $tmppron = shift(@tmppronlist); for($j=0; $j