Changeset 19dfa5c


Ignore:
Timestamp:
04/24/08 12:36:13 (16 years ago)
Author:
pawelk <pawelk@…>
Branches:
master, help
Children:
12d8443
Parents:
a5fdde9
git-author:
pawelk <pawelk@…> (04/24/08 12:36:13)
git-committer:
pawelk <pawelk@…> (04/24/08 12:36:13)
Message:

gph i dgc obsluguja configi

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@33 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

Location:
app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • app/dist/common/utt_make_config.pl

    ra5fdde9 r19dfa5c  
    1414conf_utt(catfile($usr_home, 'utt.conf'), $sys_home); 
    1515 
     16conf_cor(catfile($usr_home, 'cor.conf'), $sys_home); 
     17conf_kor(catfile($usr_home, 'kor.conf'), $sys_home); 
    1618conf_compiledic(catfile($usr_home, 'compiledic.conf'), $sys_home); 
    17 conf_cor(catfile($usr_home, 'cor.conf'), $sys_home); 
    18 conf_dgc(catfile($usr_home, 'dgc.conf'), $sys_home); 
    1919conf_grp(catfile($usr_home, 'grp.conf'), $sys_home); 
    2020conf_gue(catfile($usr_home, 'gue.conf'), $sys_home); 
    21 conf_kor(catfile($usr_home, 'kor.conf'), $sys_home); 
    2221conf_lem(catfile($usr_home, 'lem.conf'), $sys_home); 
    2322conf_ser(catfile($usr_home, 'ser.conf'), $sys_home); 
     23conf_dgc(catfile($usr_home, 'dgc.conf'), $sys_home); 
    2424 
    2525print "UTT user configuration created in $usr_home\n"; 
     
    3434 
    3535    if(-d $dir) { 
    36                 print "Old configuration detected. "; 
    37                 my $cnt = unlink <$dir/*>; 
    38                 print "($cnt files deleted)\n"; 
     36        print "Old configuration detected. "; 
     37        my $cnt = unlink <$dir/*>; 
     38        print "($cnt files deleted)\n"; 
    3939    } 
    4040    else { 
    41                 print "Creating directory $dir\n"; 
    42                 if(1 != mkdir $dir) { 
    43                     die "Unable to create UTT user configuration!\n"; 
    44                 } 
     41        print "Creating directory $dir\n"; 
     42        if(1 != mkdir $dir) { 
     43            die "Unable to create UTT user configuration!\n"; 
     44        } 
    4545    } 
    4646} 
     
    108108  print FILE makeConfigHeader(); 
    109109  print FILE "dictionary-home=", abs_path("$utthome/share/utt"), "\n"; 
    110   print FILE "weights=", abs_path("$utthome/lib/utt/weights.kor"), "\n"; 
     110  print FILE "weights=", abs_path("$utthome/lib/utt/weights.cor"), "\n"; 
    111111  print FILE "threshold=1.0\n"; 
    112112 
     
    222222 
    223223  print FILE makeConfigHeader(); 
    224   print FILE "categories=", abs_path("$utthome/lib/utt/cats.dgc"), "\n"; 
    225   print FILE "grammar=", abs_path("$utthome/lib/utt/gram.dgc"), "\n"; 
     224  print FILE "catfile=", abs_path("$utthome/lib/utt/cats.dgc"), "\n"; 
     225  print FILE "gramfile=", abs_path("$utthome/lib/utt/gram.dgc"), "\n"; 
    226226 
    227227  close FILE; 
  • app/src/dgp/dgc

    r0214596 r19dfa5c  
    66#author:        Tomasz Obrebski 
    77 
     8# wymaga niejawnie programu canonize!!!! 
    89#use lib "ENV{HOME}/.utt/lib/perl"; 
    9 #use strict; 
     10 
     11use strict; 
    1012use Getopt::Long; 
    1113use Data::Dumper; 
    1214 
    1315use attr; 
    14 #use File::HomeDir; 
     16use File::HomeDir; 
     17 
     18my $systemconfigfile='/usr/local/etc/utt/dgc.conf'; 
     19my $userconfigfile=home()."/.utt/dgc.conf"; 
     20 
     21Getopt::Long::Configure('no_ignore_case_always'); 
    1522 
    1623my $help=0; 
     
    1825my $dicfile=0; 
    1926my $gramfile=0; 
     27my $outputfile=0; 
     28 
     29#read configuration files########################### 
     30my $file; 
     31foreach $file ($systemconfigfile, $userconfigfile){ 
     32  if(open(CONFIG, $file)){ 
     33        while (<CONFIG>) { 
     34                chomp; 
     35                s/#.*//; 
     36                s/^\s+//; 
     37                s/\s+$//; 
     38                next unless length; 
     39                my ($name, $value) = split(/\s*=\s*/, $_, 2); 
     40                if(($name eq "catfile")or($name eq "c")){ 
     41                        $catfile=$value; 
     42                } 
     43                elsif(($name eq "dicfile")or($name eq "d")){ 
     44                        $dicfile=$value; 
     45                } 
     46                elsif(($name eq "gramfile")or($name eq "g")){ 
     47                        $gramfile=$value; 
     48                } 
     49                elsif(($name eq "outputfile")or($name eq "o")){ 
     50                        $outputfile=$value; 
     51                } 
     52                elsif(($name eq "help")or($name eq "h")){ 
     53                        $help=1; 
     54                } 
     55 
     56        } 
     57        close CONFIG; 
     58  } 
     59} 
     60######################################################### 
     61 
     62GetOptions("help|h" => \$help, 
     63           "catfile|c=s" => \$catfile, 
     64           "dicfile|d=s" => \$dicfile, 
     65           "gramfile|g=s" => \$gramfile, 
     66           "outputfile|o=s" => \$outputfile); 
     67 
     68if($help) 
     69{ 
     70    print <<'END' 
     71Usage: dgc [OPTIONS] 
     72 
     73Options: 
     74   --catfile -c filename        List of syntactic categories. 
     75   --dicfile -d filename        Dictionary. 
     76   --gramfile -g filename       List of grammar rules. 
     77   --outputfile -o filename     Output filename. 
     78   --help -h                    Help. 
     79END 
     80; 
     81    exit 0; 
     82} 
     83 
     84die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile; 
    2085 
    2186my $ncat=0; 
     
    2792my $nlink=0; 
    2893 
    29 GetOptions("help|h" => \$help, 
    30            "catfile|c=s" => \$catfile, 
    31            "dicfile|d=s" => \$dicfile, 
    32            "gramfile|g=s" => \$gramfile); 
    33  
    34 if($help) 
    35 { 
    36     print <<'END' 
    37 Usage: dgpcompile [OPTIONS] 
    38  
    39 Options: 
    40    --cats -c filename           List of syntactic categories. 
    41    --dic  -d filename           Dictionary. 
    42    --help -h                    Help. 
    43 END 
    44 ; 
    45     exit 0; 
    46 } 
    47  
    48 die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile; 
    49  
    5094my %cats; 
    5195my %roles; 
     
    5397my %gov; 
    5498 
     99if(!$outputfile) { 
     100        *OUTPUT = *STDOUT; 
     101} 
     102elsif($outputfile eq "-") { 
     103    *OUTPUT = *STDOUT; 
     104} 
     105else { 
     106        open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!"); 
     107} 
     108 
     109 
     110 
    55111loadcats($catfile) if $catfile; 
    56112extractcats($dicfile) if $dicfile; 
    57113 
    58114 
    59 $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 
     115my $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 
    60116 
    61117# class parse_class: 
    62118# /$attr::cat_re/g; 
    63119 
    64 while(<>) 
     120 
     121if(!$gramfile) {  
     122        *INPUT = *STDIN; 
     123} 
     124elsif($gramfile eq "-"){ 
     125    *INPUT = *STDIN; 
     126} 
     127else { 
     128        open(INPUT, $gramfile) or die("Unable to open: $gramfile!"); 
     129} 
     130 
     131while(<INPUT>) 
    65132{ 
    66133    if(/^\s*AGR\s+(\S+)\s+(\S+)\s*$/) 
     
    75142    { 
    76143        $roles{$_}=1; 
    77         print; 
     144        print OUTPUT; 
    78145    } 
    79146    elsif(/^\s*SGL\s+\S+\s*$/) 
    80147    { 
    81148        ++$nsgl; 
    82         print; 
     149        print OUTPUT; 
    83150    } 
    84151    elsif(/^\s*REQ\s+(\S+)\s+(\S+)\s*$/) 
    85152    { 
    86         print "#$_"; 
     153        print OUTPUT "#$_"; 
    87154        my $cat = attr::parse $1; 
    88155        for my $atomcat (keys %cats) 
     
    90157            if(attr::match @$cat, @{$cats{$atomcat}}) 
    91158            { 
    92                 print "REQ ".$atomcat." $2\n"; 
     159                print OUTPUT "REQ ".$atomcat." $2\n"; 
    93160                ++$nreq; 
    94161            } 
     
    98165    { 
    99166        ++$nleft; 
    100         print; 
     167        print OUTPUT; 
    101168    } 
    102169    elsif(/^\s*RIGHT\s+\S+\s*$/) 
    103170    { 
    104171        ++$nright; 
    105         print; 
    106     } 
    107     elsif(($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/) 
    108     { 
    109         print "#$_"; 
    110         for $h ($hs =~ /$attr::cat_re/g) 
    111         { 
    112             for $d ($ds =~ /$attr::cat_re/g) 
     172        print OUTPUT; 
     173    } 
     174    elsif(my ($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/) 
     175    { 
     176        print OUTPUT "#$_"; 
     177        for my $h ($hs =~ /$attr::cat_re/g) 
     178        { 
     179            for my $d ($ds =~ /$attr::cat_re/g) 
    113180            { 
    114181                addlinks($h,$d,$r); 
     
    119186    else 
    120187    { 
    121         print; 
     188        print OUTPUT; 
    122189    } 
    123190} 
     
    126193sub addlinks 
    127194{ 
    128     ($h,$d,$r) = @_; 
    129  
    130     for my $a (@{$agr{$r}}) { print "#AGR $r $a\n"; } 
    131     for my $c (@{$gov{$r}}) { print "#GOV $r ".attr::unparse(@$c)."\n"; } 
     195    my ($h,$d,$r) = @_; 
     196 
     197    for my $a (@{$agr{$r}}) { print OUTPUT "#AGR $r $a\n"; } 
     198    for my $c (@{$gov{$r}}) { print OUTPUT "#GOV $r ".attr::unparse(@$c)."\n"; } 
    132199    my $head = attr::parse $h; 
    133200    my $dep = attr::parse $d; 
     
    152219                } 
    153220                 
    154                 print "LINK "; 
    155                 print $atomhead." "; 
    156                 print $atomdep." $r\n"; 
     221                print OUTPUT "LINK "; 
     222                print OUTPUT $atomhead." "; 
     223                print OUTPUT $atomdep." $r\n"; 
    157224                ++$nlink; 
    158225                 
     
    180247        while(/,([^[:space:];]+)/g) 
    181248        { 
    182             $cat=$1; 
     249            my $cat=$1; 
    183250            next if !$cat || exists $cats{$cat}; 
    184251            $ncat++; 
    185             print "CAT $1\n"; 
     252            print OUTPUT "CAT $1\n"; 
    186253            $cats{$cat}=attr::parse($cat); 
    187254        } 
     
    199266        tr/ \t\n//d; 
    200267        next if !$_ || exists $cats{$_}; 
    201         print "CAT $_\n"; 
     268        print OUTPUT "CAT $_\n"; 
    202269        ++$ncat; 
    203270        $cats{$_}=attr::parse($_); 
     
    205272    close CATFILE; 
    206273} 
     274 
  • app/src/gph/gph

    rcfed5c1 r19dfa5c  
    88use strict; 
    99use Getopt::Long; 
     10use File::HomeDir; 
    1011 
    11 my @process; 
     12 
     13 
     14 
     15 
     16my $systemconfigfile='/usr/local/etc/utt/gph.conf'; 
     17my $userconfigfile=home()."/.utt/gph.conf"; 
     18 
     19Getopt::Long::Configure('no_ignore_case_always'); 
     20 
    1221my $help=0; 
     22my $inputfile=0; 
     23my $outputfile=0; 
     24my @process=(); 
    1325my $reset; 
    14 my $interactive=1; 
     26my $interactive=0; 
     27 
     28#read configuration files########################### 
     29my $file; 
     30my @process_conf=(); 
     31foreach $file ($systemconfigfile, $userconfigfile){ 
     32  if(open(CONFIG, $file)){ 
     33        while (<CONFIG>) { 
     34                chomp; 
     35                s/#.*//; 
     36                s/^\s+//; 
     37                s/\s+$//; 
     38                next unless length; 
     39                my ($name, $value) = split(/\s*=\s*/, $_, 2); 
     40                if(($name eq "inputfile")or($name eq "f")){ 
     41                        $inputfile=$value; 
     42                } 
     43                elsif(($name eq "outputfile")or($name eq "o")){ 
     44                        $outputfile=$value; 
     45                } 
     46                elsif(($name eq "process")or($name eq "p")){ 
     47                        push @process_conf, $value; 
     48                } 
     49                elsif(($name eq "reset")or($name eq "r")){ 
     50                        $reset=$value; 
     51                } 
     52                elsif(($name eq "interactive")or($name eq "i")){ 
     53                        $interactive=1; 
     54                } 
     55                elsif(($name eq "help")or($name eq "h")){ 
     56                        $help=1; 
     57                } 
     58 
     59        } 
     60        close CONFIG; 
     61  } 
     62} 
     63######################################################### 
     64 
     65 
    1566 
    1667GetOptions("process|p=s" => \@process, 
     68           "inputfile|f=s" => \$inputfile, 
     69           "outputfile|o=s" => \$outputfile, 
    1770           "help|h" => \$help, 
    1871           "reset|r=s" => \$reset, 
    1972           "interactive|i" => \$interactive); 
     73 
     74@process = @process_conf if @process<1; 
    2075 
    2176if($help) 
     
    2782   -p tag               Process segments with this tag as nodes. 
    2883   -r tag               Start new graph at this tag. 
    29    -f filename          Input file (NIE DZIALA). 
    30    -o filename          Output file (NIE DZIALA). 
    31    -i                   Toggle interactive mode (default=on). 
     84   -f filename          Input file. 
     85   -o filename          Output file. 
     86   -i                   Toggle interactive mode (default=off). 
    3287END 
    3388; 
     
    3893$|=1 if $interactive; 
    3994 
     95 
     96if(!$inputfile or $inputfile eq "-") { 
     97        *INPUT = *STDIN; 
     98} 
     99else { 
     100        open(INPUT, "$inputfile") or die("Can't open input file: $inputfile!"); 
     101} 
     102 
     103if(!$outputfile or $outputfile eq "-") { 
     104        *OUTPUT = *STDOUT; 
     105} 
     106else { 
     107        open(OUTPUT, "$outputfile") or die("Can't open output file: $outputfile!"); 
     108} 
     109 
    40110my @prev; 
    41  
    42111my $n=0; 
    43112 
    44 while(<>) 
     113while(<INPUT>) 
    45114{ 
    46115    chomp; 
     
    89158    } 
    90159 
    91     print $_.$gph."\n";     
     160    print OUTPUT $_.$gph."\n";     
    92161} 
    93162 
Note: See TracChangeset for help on using the changeset viewer.