- 论坛徽章:
- 0
|
#!/usr/bin/perl
use strict;
use warnings;
no strict 'refs';
#####将多个字典(dict1.txt dict2.txt)文件合并#####
open (my $fh1,"dict1.txt");
open (my $fh2,"dict2.txt");
open (my $fh3,">","newdict.txt");
my %h1;
while (<$fh1>) {
chomp;
my ($k,$v)=split /\s+/,$_,2;
push @{$h1{$k}},$v;
}
while (<$fh2>) {
chomp;
my ($k,$v)=split /\s+/,$_,2;
next if $v~~@{$h1{$k}};
push @{$h1{$k}},$v;
}
map {my $k=$_;print $fh3 map{"$k\t$_\n"}@{$h1{$_}};}sort keys %h1;
close($fh1);
close($fh2);
close($fh3);
open Afile,"WordList.txt";
open OOV,">","oov.txt";
open OOV1,">","oov1.txt";
while(<Afile>){
chomp;
if (exists $h1{$_}) {
my $k=$_;
print OOV1 map {"$k=>$_ \n"} @{$h1{$_}};
}else{
print OOV "$_\n";
}
}
close(Afile);
close(OOV);
close(OOV1);
open Bfile,"tp6-6.txt";
open OOV2,">","oov2.txt";
open OOV3,">","oov3.txt";
while (<Bfile>) {
while (/([a-zA-Z\']+)/g) {
my $w=$1;
print OOV2 "$w\t";
if (exists $h1{$w}) {
print OOV3 map {"$w=>$_ \n"} @{$h1{$w}};
}
}
}
|
|