-
Notifications
You must be signed in to change notification settings - Fork 0
/
makelatex.pl
executable file
·72 lines (58 loc) · 1.71 KB
/
makelatex.pl
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
#!/usr/bin/env perl
#
# convert Wikidata classification given in CSV format to LaTeX
#
use v5.14;
use Catmandu -all;
use Pandoc::Elements;
binmode(STDOUT, ":encoding(UTF-8)");
my $file = shift @ARGV;
my $entries = importer('CSV', file => $file);
my %items;
say '\begin{tabbing}';
say '\hspace*{58mm}X\= \kill';
$entries->each(sub {
my $item = shift;
$items{ $item->{item} } //= {
sites => $item->{sites},
instances => $item->{size},
};
my $level = $item->{level};
if ($level) {
$level =~ s/./\\cdot\\:/g;
$level = '$'.$level.'$ ';
}
my $parents = '';
if ($item->{parents}) {
$parents = '$' . ('\uparrow' x $item->{parents}) . '$';
}
my $content = $item->{size} || '';
$content .= '{\raisebox{.4\height}{\scalebox{.6}{+}}}'
. $item->{sites} if $item->{sites};
my $label = $item->{label};
if (length $item->{level} < 2) {
$label = "\\textbf{$label}";
}
if ( $item->{level} =~ /=/ ) {
say "$level \\textit{$label}\\\\"
} else {
say "$level $label $parents \\` $content\\\\";
}
});
say '\end{tabbing}';
say '';
my $classes = keys %items;
my $instances = grep {$_->{instances}} values %items;
my $sites = grep {$_->{sites}} values %items;
say '\vfill';
say '\begin{tabbing}';
say '\hspace*{15mm}\=\hspace*{32mm}\=\kill';
say '\\>\textbf{Summary}\\\\';
say "\\>number of classes:\\`$classes (100\\%)\\\\";
say "\\>with instance:\\`$instances (".int($instances/$classes*100)."\\%)\\\\";
say "\\>with sitelink:\\`$sites (".int($sites/$classes*100)."\\%)";
$instances = shift @ARGV;
if ($instances) {
say "\\\\\\>number of instances:\\`$instances";
}
say '\end{tabbing}';