« blib/lib/auto/share/dist/Uplug/lang/nonbreaking_prefixes/nonbreaking_prefix.pl
↑ Summary
lib/Uplug.pm »
| 1 | #!/usr/local/bin/perl | ||
| 2 | ################################################################## | ||
| 3 | # Postprocessing script for GMA alignment | ||
| 4 | # <align file> contains entries as i,j,...k <=> l,m,...n | ||
| 5 | #script places lines i, j,... k from file1 in file1.a | ||
| 6 | #lines l,m,...n from file2 in file2.a | ||
| 7 | #results in file1.a and file2.a being aligned files | ||
| 8 | # optional parameters: | ||
| 9 | # threshold: pring the names of the files when more than threshold % | ||
| 10 | # of the lines are missing | ||
| 11 | # -s parameter for just statistics, do not generate aligned files | ||
| 12 | # if the following parameters are specified, | ||
| 13 | # print error message if a string is missing and it is not marked 'omitted' and the line is not empty | ||
| 14 | # and some word in the line is found in the lexicon | ||
| 15 | # file1 morph - morpholised version of text1 (that was used for axis generation | ||
| 16 | # file2 morph - morpholised version of text2 (that was used for axis generation | ||
| 17 | # file1 lexicon | ||
| 18 | # file2 lexicon | ||
| 19 | # | ||
| 20 | ################################################################## | ||
| 21 | |||
| 22 | |||
| 23 | if($#ARGV<2) | ||
| 24 | { | ||
| 25 | print "usage $0 <align file> <text1> <text2> [<threshold> <-e> <file1 morph> <file2 morph> <file1 lexicon> <file2 lexicon>]\n"; | ||
| 26 | exit 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | $statonly = 0; | ||
| 30 | if($ARGV[4] eq '-s') | ||
| 31 | { | ||
| 32 | $statonly = 1; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | #empty lines from file 1 | ||
| 37 | $cnt = 0; | ||
| 38 | open(F1, $ARGV[1]); | ||
| 39 | while(<F1>) | ||
| 40 | { | ||
| 41 | $cnt++; | ||
| 42 | $emptyF1{$cnt} = 1 if(length($_)<=2); | ||
| 43 | |||
| 44 | } | ||
| 45 | |||
| 46 | close(F1); | ||
| 47 | #empty lines from file 2 | ||
| 48 | $cnt = 0; | ||
| 49 | open(F2, $ARGV[2]); | ||
| 50 | while(<F2>) | ||
| 51 | { | ||
| 52 | $cnt++; | ||
| 53 | $emptyF2{$cnt} = 1 if(length($_)<=2); | ||
| 54 | } | ||
| 55 | |||
| 56 | close(F2); | ||
| 57 | |||
| 58 | |||
| 59 | open(ALIGN, $ARGV[0]); | ||
| 60 | |||
| 61 | $lang1 = $ARGV[1]; | ||
| 62 | $lang2 = $ARGV[2]; | ||
| 63 | $thresh = $ARGV[3]; | ||
| 64 | $lang1morph = $ARGV[5]; | ||
| 65 | $lang2morph = $ARGV[6]; | ||
| 66 | $lang1lex = $ARGV[7]; | ||
| 67 | $lang2lex = $ARGV[8]; | ||
| 68 | #$dir = $ARGV[3]; | ||
| 69 | |||
| 70 | #read in lang1 lexicon | ||
| 71 | undef $/; | ||
| 72 | open(F1, $lang1lex) || die "Couldn't open $lang1lex: $!\n"; | ||
| 73 | $lang1lexdata = <F1>; | ||
| 74 | close(F1); | ||
| 75 | open(F2, $lang2lex) || die "Couldn't open $lang2lex: $!\n"; | ||
| 76 | $lang2lexdata = <F2>; | ||
| 77 | close(F2); | ||
| 78 | $/ = "\n"; | ||
| 79 | |||
| 80 | if(!($statonly)) | ||
| 81 | { | ||
| 82 | system("rm $lang1.a") if(-f "$lang1.a" ); | ||
| 83 | system("rm $lang2.a") if(-f "$lang2.a" ); | ||
| 84 | #exit 0 if(-f "$lang1.a" ); | ||
| 85 | #exit 0 if(-f "$lang2.a" ); | ||
| 86 | } | ||
| 87 | |||
| 88 | while(<ALIGN>) | ||
| 89 | { | ||
| 90 | # print stderr $_; | ||
| 91 | chop; | ||
| 92 | @align = split '<=>'; | ||
| 93 | @l1 = split ',',$align[0]; | ||
| 94 | @l2 = split ',',$align[1]; | ||
| 95 | |||
| 96 | if($align[0]=~/omitted/ || $align[1] =~ /omitted/) | ||
| 97 | { | ||
| 98 | #print "omitted $align[0] $align[1]\n"; | ||
| 99 | foreach $l(@l1){ | ||
| 100 | $l1_omit[$l]++; | ||
| 101 | } | ||
| 102 | foreach $l(@l2){ | ||
| 103 | $l2_omit[$l]++; | ||
| 104 | } | ||
| 105 | |||
| 106 | |||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | foreach $l(@l1){ | ||
| 111 | system("sellinesnonewline $l $l $lang1 >> $lang1.a") if(!($statonly)); | ||
| 112 | $l1_check[$l]++; | ||
| 113 | } | ||
| 114 | |||
| 115 | foreach $l(@l2){ | ||
| 116 | system("sellinesnonewline $l $l $lang2 >> $lang2.a") if(!($statonly)); | ||
| 117 | $l2_check[$l]++; | ||
| 118 | } | ||
| 119 | |||
| 120 | system("echo ''>> $lang1.a"); | ||
| 121 | system("echo ''>> $lang2.a"); | ||
| 122 | |||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | |||
| 127 | $numlines1 = `wc -l $lang1`; | ||
| 128 | $numlines2 = `wc -l $lang2`; | ||
| 129 | |||
| 130 | ################################################################################################## | ||
| 131 | # print error message if a string is missing and it is not marked 'omitted' and the line is not empty | ||
| 132 | # and some word in the line is found in the lexicon | ||
| 133 | ################################################################################################## | ||
| 134 | |||
| 135 | for($i = 1; $i<=$numlines1; $i++) | ||
| 136 | { | ||
| 137 | if($l1_check[$i]==0 && $l1_omit[$i] == 0 && !(exists $emptyF1{$i}) ) | ||
| 138 | { | ||
| 139 | #print "$lang1 missing $i\n"; | ||
| 140 | $str = `head -$i $lang1morph | tail -1`; | ||
| 141 | @words = split " ", $str; | ||
| 142 | $found = 0; | ||
| 143 | foreach $w(@words) | ||
| 144 | { | ||
| 145 | $found = 1 if($lang1lexdata =~ /\b\Q$w\E\b/) | ||
| 146 | } | ||
| 147 | |||
| 148 | if($found){ | ||
| 149 | print "$lang1 missing $i:$str\n"; | ||
| 150 | $missing1++; | ||
| 151 | } | ||
| 152 | |||
| 153 | #exit 0; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | for($i = 1; $i<=$numlines2; $i++) | ||
| 158 | { | ||
| 159 | if($l2_check[$i]==0 && $l2_omit[$i] == 0 && !(exists $emptyF2{$i})) | ||
| 160 | { | ||
| 161 | #print "$lang2 missing $i\n"; | ||
| 162 | $str = `head -$i $lang2morph | tail -1`; | ||
| 163 | @words = split " ", $str; | ||
| 164 | $found = 0; | ||
| 165 | foreach $w(@words) | ||
| 166 | { | ||
| 167 | $found = 1 if($lang2lexdata =~ /\b\Q$w\E\b/) | ||
| 168 | } | ||
| 169 | |||
| 170 | if($found){ | ||
| 171 | print "$lang2 missing $i:$str\n"; | ||
| 172 | $missing2++; | ||
| 173 | } | ||
| 174 | #exit 0; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | print("$lang1\n") if($missing1/$numlines1 > $thresh); | ||
| 179 | print("$lang2\n") if($missing2/$numlines2 > $thresh); |