]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/convert_LoCSchemas_to_thesauri.pl
LP1864371 Angular 10 deps
[Evergreen.git] / Open-ILS / src / extras / convert_LoCSchemas_to_thesauri.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use JSON;
5
6
7 # Pulled original data from LoC on Feb 7, 2017.
8 # URL: http://id.loc.gov/vocabulary/subjectSchemes.json
9 # URL: http://id.loc.gov/vocabulary/genreFormSchemes.json
10 # Post-processing with iconv to convert from Latin1 to UTF8
11 # See files: subjectSchemes.utf8.json, genreFormSchemes.utf8.json
12
13 binmode(STDOUT, ":utf8");
14
15 local $/ = undef;
16 my $json = decode_json(<>);
17
18 for my $node (@$json) {
19     next unless $node->{'@type'}[2] and $node->{'@type'}[2] eq 'http://www.w3.org/2004/02/skos/core#Concept';
20
21     my $id = $node->{'@id'};
22     my $code = $node->{'http://www.loc.gov/mads/rdf/v1#code'}[0]{'@value'};
23
24     my $en_label;
25     my %per_labels;
26
27     for my $label_type ( qw|
28             http://www.w3.org/2000/01/rdf-schema#label
29             http://www.loc.gov/mads/rdf/v1#authoritativeLabel
30             http://www.w3.org/2004/02/skos/core#prefLabel
31     | ) {
32         for my $plabel (@{$node->{$label_type}}) {
33             my $lang = $plabel->{'@language'};
34             my $value= $plabel->{'@value'};
35             if ($lang eq 'en') {
36                 $en_label = $value;
37                 next;
38             }
39             $value =~ s/"/'/g;
40             $per_labels{$lang} = $value;
41         }
42     }
43
44     ($en_label) = values(%per_labels) if (!$en_label and keys(%per_labels) == 1);
45
46     next unless $en_label;
47
48     print "$code\t$id\t$en_label\t".join(',', map {"\"$_\"=>\"$per_labels{$_}\""} keys %per_labels)."\n";
49 }
50
51