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
13 binmode(STDOUT, ":utf8");
16 my $json = decode_json(<>);
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';
21 my $id = $node->{'@id'};
22 my $code = $node->{'http://www.loc.gov/mads/rdf/v1#code'}[0]{'@value'};
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
32 for my $plabel (@{$node->{$label_type}}) {
33 my $lang = $plabel->{'@language'};
34 my $value= $plabel->{'@value'};
40 $per_labels{$lang} = $value;
44 ($en_label) = values(%per_labels) if (!$en_label and keys(%per_labels) == 1);
46 next unless $en_label;
48 print "$code\t$id\t$en_label\t".join(',', map {"\"$_\"=>\"$per_labels{$_}\""} keys %per_labels)."\n";