forked from zbw/pm20_bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurlalias.pl
91 lines (75 loc) · 2.54 KB
/
urlalias.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/perl
# nbt, 8.3.2021
# create aliases for folders and collections
use strict;
use warnings;
use utf8;
use lib './lib';
use Data::Dumper;
use JSON;
use Path::Tiny;
use Readonly;
use ZBW::PM20x::Folder;
$Data::Dumper::Sortkeys = 1;
Readonly my $IMAGEDATA_ROOT => path('../data/imagedata');
Readonly my $KLASSDATA_ROOT => path('../data/klassdata');
Readonly my $URLALIAS_FILE => path("../var/awstats/urlalias.pm20.txt");
# open alias file
open( my $alias_fh, '>:encoding(utf8)', $URLALIAS_FILE );
# static aliases
print $alias_fh <<"EOF";
/\tHome
/film/\tDigitalisierte Filme
/list/publication/\tListe der Zeitungen und Zeitschriften
/doc/holding/\tBestandsübersicht
/category/geo/\tMappen nach Ländersystematik
/category/subject/\tMappen nach Sachsystematik
/category/ware/\tMappen nach Warensystematik
/awstats/awstats.pl\tStatistics
/folder/pe/\tPersonen-Archiv
/folder/co/\tFirmen/Institutionen-Archiv
/folder/sh/\tLänder-Sach-Archiv
/folder/wa/\tWaren-Archiv
/report/pe/persons_with_metadata\tReport Personen mit Metadaten
/report/pe/persons\tReport Personen
/report/pe/companies_with_metadata\tReport Firmen mit Metadaten
/report/co/companies\tReport Firmen
/report/co/companies_with_reports\tReport Firmen mit Geschaftsberichten
/report/\tReports
/about-pm20/legal\tRechtlichtes
/about-pm20/\tÜber PM20
/report/\tReports
/doc/\tDokumentation
/mirador/\tMirador IIIF Viewer
EOF
# collections
foreach my $collection (qw/ co pe sh wa /) {
# load input file
my $imagedata_file = $IMAGEDATA_ROOT->child("${collection}_image.json");
my $imagedata_ref = decode_json( $imagedata_file->slurp );
foreach my $folder_nk ( sort keys %{$imagedata_ref} ) {
my $folder = ZBW::PM20x::Folder->new( $collection, $folder_nk );
print $alias_fh '/folder/'
. $folder->get_folder_hashed_path() . "/\t"
. ( $folder->get_folderlabel('de') || 'label_missing' ), "\n";
}
}
# categories
foreach my $vocab (qw/ geo subject /) {
my $klassdata_file = $KLASSDATA_ROOT->child("${vocab}_by_signature.de.json");
my $klassdata_ref = decode_json( $klassdata_file->slurp );
foreach my $entry ( @{ $klassdata_ref->{results}{bindings} } ) {
my $uri =
defined $entry->{category}
? $entry->{category}{value}
: $entry->{country}{value};
my $label =
defined $entry->{categoryLabel}
? $entry->{categoryLabel}{value}
: $entry->{countryLabel}{value};
my $signature = $entry->{signature}{value};
( my $id = $uri ) =~ s|.+/(\d{6})$|$1|;
print $alias_fh "/category/$vocab/i/$id/\t$signature $label\n";
}
}
close($alias_fh);