This repository has been archived by the owner on Nov 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatfinder
executable file
·81 lines (73 loc) · 2.05 KB
/
catfinder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw($Bin $Script);
use Getopt::Long qw(:config no_ignore_case);
use Pod::Usage;
use lib "$Bin/lib";
my $EXT='.wiki';
my $verbose;
help() unless GetOptions(
'v+' => \$verbose,
'h|help' => \&help,
'm|man' => \&man,
);
sub help { pod2usage(-verbose=>1); }
sub man { pod2usage(-verbose=>2); }
my (
%cat2ph,
%wikicat,
%ph2cat,
%wikiph,
%lang,
);
my $matcher= "/([^/]+)/Category/(..)" . quotemeta($EXT) . '$';
$matcher= qr/$matcher/;
my $TRANSLATIONS= "$Bin/translations";
while (<$TRANSLATIONS/*/Category/*$EXT>) {
die "Can't find language in $_" unless $_=~$matcher;
my $lang=lc $2;
my $placeholder= $1;
++$lang{$lang};
my $iswiki;
if ( -d "$TRANSLATIONS/$placeholder/Link") {
++$wikiph{$placeholder}{$lang};
$iswiki= 1;
}
open my $catfile, '<:utf8', $_ or die "Can't read $_: $!\n";
my $categories= do { local $/; <$catfile> };
close $catfile;
foreach my $cat (split /\n/, $categories) {
for ($cat) {
tr/\012\015//d;
$cat=~ s/^\s+|\s+$//g;
}
++$cat2ph{$cat}{$lang}{$placeholder};
++$ph2cat{$placeholder}{$lang}{$cat};
if ($iswiki) {
++$wikicat{$cat}{$lang};
}
}
}
print "Categories for Wiki Entries:\n";
foreach my $cat (sort keys %cat2ph) {
next unless exists $wikicat{$cat};
foreach my $lang (sort keys %lang) {
next unless exists $cat2ph{$cat}{$lang};
print "$cat\t$lang\t",scalar keys %{$cat2ph{$cat}{$lang}},"\n";
next unless $verbose;
print "\t$_\n" foreach (sort keys %{$cat2ph{$cat}{$lang}})
}
}
print "\n";
print "Other Categories:\n";
foreach my $cat (sort keys %cat2ph) {
next if exists $wikicat{$cat};
foreach my $lang (sort keys %lang) {
next unless exists $cat2ph{$cat}{$lang};
print "$cat\t$lang\t",scalar keys %{$cat2ph{$cat}{$lang}},"\n";
next unless $verbose;
print "\t$_\n" foreach (sort keys %{$cat2ph{$cat}{$lang}})
}
}
print "\n";