Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/julius-speech/julius
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeAkinobu committed Sep 2, 2020
2 parents f8718df + 2dd2792 commit 8ff192f
Show file tree
Hide file tree
Showing 6 changed files with 983 additions and 700 deletions.
100 changes: 61 additions & 39 deletions gramtools/mkdfa/mkdfa.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,14 @@
#

## setup
# tmpdir
$usrtmpdir = ""; # specify if any
$tmpdir = ".";

# mkfa executable location
($thisdir) = ($0 =~ /(.*(\/|\\))[^\/\\]*$/o);
$mkfabin = "${thisdir}mkfa";

# dfa_minimize executable location
$minimizebin = "${thisdir}dfa_minimize";
# find tmpdir
@tmpdirs = ($usrtmpdir, $ENV{"TMP"}, $ENV{"TEMP"}, "/tmp", "/var/tmp", "/WINDOWS/Temp", "/WINNT/Temp");

$tmpdir="";
while (@tmpdirs) {
$t = shift(@tmpdirs);
next if ($t eq "");
if (-d "$t" && -w "$t") {
$tmpdir = $t;
last;
}
}
if ($tmpdir eq "") {
die "Please set working directory in \$usrtmpdir at $0\n";
}

#############################################################

Expand Down Expand Up @@ -62,10 +46,20 @@ $dfafile = "$ARGV[$#ARGV].dfa";
$fdfafile = "$ARGV[$#ARGV].dfa.forward";
$dictfile = "$ARGV[$#ARGV].dict";
$termfile = "$ARGV[$#ARGV].term";
$tmpprefix = "$tmpdir/g$$";
$tmpprefix = "$tmpdir/tmp$$";
$tmpgramfile = "${tmpprefix}.grammar";
$tmpvocafile = "${tmpprefix}.voca";
$rgramfile = "${tmpprefix}-rev.grammar";
$tmpheadfile = "${tmpprefix}.h";

# check if input file exists

if (! -f $gramfile) {
die "cannot open \"$gramfile\"";
}
if (! -f $vocafile) {
die "cannot open \"$vocafile\"";
}

# sanitize grammar file
open(GRAM,"< $gramfile") || die "cannot open \"$gramfile\"";
Expand All @@ -75,7 +69,10 @@ while (<GRAM>) {
$CRLF = 1 if /\r$/;
s/\r+$//g;
s/#.*//g;
if (/^[ \t]*$/) {next;}
if (/^[ \t]*$/) {
print SGRAM "\n";
next;
}
print SGRAM "$_\n";
}
close(SGRAM);
Expand All @@ -90,7 +87,10 @@ while (<GRAM>) {
$CRLF = 1 if /\r$/;
s/\r+$//g;
s/#.*//g;
if (/^[ \t]*$/) {next;}
if (/^[ \t]*$/) {
print RGRAM "\n";
next;
}
($left, $right) = split(/\:/);
if ($CRLF == 1) {
print RGRAM $left, ': ', join(' ', reverse(split(/ /,$right))), "\r\n";
Expand Down Expand Up @@ -120,7 +120,10 @@ while (<VOCA>) {
$CRLF = 1 if /\r$/;
s/\r+$//g;
s/#.*//g;
if (/^[ \t]*$/) {next;}
if (/^[ \t]*$/) {
print TMPVOCA "\n";
next;
}
if (/^%[ \t]*([A-Za-z0-9_]*)/) {
if ($CRLF == 1) {
printf(TMPVOCA "\#%s\r\n", $1);
Expand All @@ -146,41 +149,60 @@ if ($make_term == 1) {
close(GTERM);
}
print "$vocafile has $n1 categories and $n2 words\n";

print "---\n";

# call mkfa and make .dfa
sub mkfa {
my ($gram, $voca, $dfa, $h) = @_;
my $status;
my $command;
if ($tmpprefix =~ /cygdrive/) {
$command = "$mkfabin -e1 -fg `cygpath -w $gram` -fv `cygpath -w $voca` -fo `cygpath -w $dfa` -fh `cygpath -w $h`";
} else {
$command = "$mkfabin -e1 -fg $gram -fv $voca -fo $dfa -fh $h";
}
print "executing [$command]\n";
$status = system("$command");
if ($status != 0) {
print STDERR "\n";
print STDERR "**** Error occured in mkfa ***\n";
print STDERR "* Temporary files are left in $tmpdir for your debugging. You can delete them manually:\n";
print STDERR "* grammar = $tmpgramfile\n";
print STDERR "* reverse grammar = $rgramfile\n";
print STDERR "* vocab category = $tmpvocafile\n";
print STDERR "* header log = $tmpheadfile\n";
print STDERR "\n";
}
return $status;
}

if (! -x $minimizebin) {
# no minimization
print "Warning: dfa_minimize not found in the same place as mkdfa.pl\n";
print "Warning: no minimization performed\n";
if ($tmpprefix =~ /cygdrive/) {
$status = system("$mkfabin -e1 -fg `cygpath -w $rgramfile` -fv `cygpath -w $tmpvocafile` -fo `cygpath -w $dfafile` -fh `cygpath -w ${tmpprefix}.h`");
$status = system("$mkfabin -e1 -fg `cygpath -w $tmpgramfile` -fv `cygpath -w $tmpvocafile` -fo `cygpath -w $fdfafile` -fh `cygpath -w ${tmpprefix}.h`");
} else {
$status = system("$mkfabin -e1 -fg $rgramfile -fv $tmpvocafile -fo $dfafile -fh ${tmpprefix}.h");
$status = system("$mkfabin -e1 -fg $tmpgramfile -fv $tmpvocafile -fo $fdfafile -fh ${tmpprefix}.h");
if (&mkfa($rgramfile, $tmpvocafile, $dfafile, $tmpheadfile) != 0) {
die "stopped";
}
if (&mkfa($tmpgramfile, $tmpvocafile, $fdfafile, $tmpheadfile) != 0) {
die "stopped";
}
} else {
# minimize DFA after generation
if ($tmpprefix =~ /cygdrive/) {
$status = system("$mkfabin -e1 -fg `cygpath -w $rgramfile` -fv `cygpath -w $tmpvocafile` -fo `cygpath -w ${dfafile}.tmp` -fh `cygpath -w ${tmpprefix}.h`");
system("$minimizebin `cygpath -w ${dfafile}.tmp` -o `cygpath -w $dfafile`");
$status = system("$mkfabin -e1 -fg `cygpath -w $tmpgramfile` -fv `cygpath -w $tmpvocafile` -fo `cygpath -w ${dfafile}.tmp` -fh `cygpath -w ${tmpprefix}.h`");
system("$minimizebin `cygpath -w ${dfafile}.tmp` -o `cygpath -w $fdfafile`");
} else {
$status = system("$mkfabin -e1 -fg $rgramfile -fv $tmpvocafile -fo ${dfafile}.tmp -fh ${tmpprefix}.h");
system("$minimizebin ${dfafile}.tmp -o $dfafile");
$status = system("$mkfabin -e1 -fg $tmpgramfile -fv $tmpvocafile -fo ${dfafile}.tmp -fh ${tmpprefix}.h");
system("$minimizebin ${dfafile}.tmp -o $fdfafile");
if (&mkfa($rgramfile, $tmpvocafile, ${dfafile}.tmp, $tmpheadfile) != 0) {
die "stopped";
}
system("$minimizebin `cygpath -w ${dfafile}.tmp` -o `cygpath -w $dfafile`");
if (&mkfa($tmpgramfile, $tmpvocafile, ${dfafile}.tmp, $tmpheadfile) != 0) {
die "stopped";
}
system("$minimizebin `cygpath -w ${dfafile}.tmp` -o `cygpath -w $fdfafile`");
unlink("${dfafile}.tmp");
}

unlink("$tmpgramfile");
unlink("$rgramfile");
unlink("$tmpvocafile");
unlink("${tmpprefix}.h");
unlink("$tmpheadfile");
print "---\n";
if ($status != 0) {
# error
Expand Down
2 changes: 2 additions & 0 deletions gramtools/mkdfa/mkfa-1.44-flex/gram.l
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
%option yylineno
%option noyywrap
%%
"@"[a-zA-Z0-9_]+ {
yylval = yytext + 1;
Expand Down
6 changes: 3 additions & 3 deletions gramtools/mkdfa/mkfa-1.44-flex/gram.tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ char *getNewClassName( char *keyname )

sprintf( classname, "%s#%d", keyname , tmpClassNo++ );
if( !SW_SemiQuiet ){
fprintf( stderr, "\rNow modifying grammar to minimize states[%d]", GramModifyNum );
fprintf( stderr, "\rNow modifying grammar to reduce states[%d]", GramModifyNum );
NoNewLine = 1;
}
GramModifyNum++;
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void setGram( void )
if( !SW_Quiet ) fputs( "Now parsing grammar file\n", stderr );
yyparse();
if( !SW_Quiet ){
fprintf( stderr, "\rNow modifying grammar to minimize states[%d]\n", GramModifyNum - 1 );
fprintf( stderr, "\rNow modifying grammar to reduce states[%d]\n", GramModifyNum - 1 );
NoNewLine = 0;
}
if( StartSymbol == NULL ) StartSymbol = ClassList;
Expand Down Expand Up @@ -1515,7 +1515,7 @@ char *chkNoInstantClass( void )

int yyerror( char *mes )
{
errMes(mes );
errMes("%s: Line %d: %s", GramFile, yylineno, mes);
ErrParse++;
return( 0 );
}
4 changes: 2 additions & 2 deletions gramtools/mkdfa/mkfa-1.44-flex/gram.y
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ char *getNewClassName( char *keyname )

sprintf( classname, "%s#%d", keyname , tmpClassNo++ );
if( !SW_SemiQuiet ){
fprintf( stderr, "\rNow modifying grammar to minimize states[%d]", GramModifyNum );
fprintf( stderr, "\rNow modifying grammar to reduce states[%d]", GramModifyNum );
NoNewLine = 1;
}
GramModifyNum++;
Expand Down Expand Up @@ -338,7 +338,7 @@ void setGram( void )
if( !SW_Quiet ) fputs( "Now parsing grammar file\n", stderr );
yyparse();
if( !SW_Quiet ){
fprintf( stderr, "\rNow modifying grammar to minimize states[%d]\n", GramModifyNum - 1 );
fprintf( stderr, "\rNow modifying grammar to reduce states[%d]\n", GramModifyNum - 1 );
NoNewLine = 0;
}
if( StartSymbol == NULL ) StartSymbol = ClassList;
Expand Down
Loading

0 comments on commit 8ff192f

Please sign in to comment.