| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.2.4'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | my $JSON = JSON->new->utf8->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | my $JSON_PRETTY = JSON->new->utf8->canonical->pretty; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | ## get options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my %opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | \%opt, 'help|h|?', 'sparql|q=s', 'scheme|s=s', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'directory|d=s', 'name|n=s', 'language|l=s', 'quiet|q', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'verbose|v', 'debug', 'version', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ) or exit 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | say "skos2jskos $VERSION" and exit if $opt{version}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition25%1/4
$opt{'version'} && (say("skos2jskos $main::VERSION") && exit)
say "skos2jskos $main::VERSION" and exit
MC/DC0%0/2
$opt{'version'} && (say("skos2jskos $main::VERSION") && exit)
$opt{'version'}
say "skos2jskos $main::VERSION"
Truth table33%1/3
A && B
A= $opt{'version'}B= say "skos2jskos $main::VERSION"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | if ( $opt{help} or ( !$opt{sparql} && !@ARGV ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$opt{"help"} or not $opt{"sparql"} || @ARGV
$opt{'sparql'} || @ARGV
MC/DC33%1/3
$opt{"help"} or not $opt{"sparql"} || @ARGV
$opt{"help"}
$opt{'sparql'}
@ARGV
Truth table50%2/4
A or not(B || C)
A= $opt{"help"}B= $opt{'sparql'}C= @ARGV
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | pod2usage( -exitval => 1, -indent => 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | $opt{directory} //= '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{"directory"} //= "."
MC/DC0%0/1
$opt{"directory"} //= "."
$opt{"directory"}
Truth table50%1/2
A
A= $opt{"directory"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | $opt{directory} =~ s{/$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | die "output directory not found: " . $opt{directory} . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | unless -d $opt{directory}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | $opt{language} //= 'en'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{"language"} //= "en"
MC/DC0%0/1
$opt{"language"} //= "en"
$opt{"language"}
Truth table50%1/2
A
A= $opt{"language"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $opt{verbose} = 2 if $opt{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ## Logging methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $colored = -t STDOUT; ## no critic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub error($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | say STDERR ( $colored ? colored( $_[0], 'red' ) : $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub fatal($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fatal: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | error $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub warning($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
warning: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | say STDERR ( $colored ? colored( $_[0], 'yellow' ) : $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | ▶ | sub info($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: called CC=3 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | ▶ | return if $opt{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | say( $colored ? colored( $_[0], 'green' ) : $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | sub debug($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=3 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | return unless $opt{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | say( $colored ? colored( $_[0], 'white' ) : $_[0] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub trace($) { ## no critic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
trace: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | ▶ | return unless $opt{verbose} > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | say $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ## check where to get RDF data from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | use RDF::Trine; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 3 | ▶ | use RDF::Query; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | use RDF::Query::Client; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | my $source = $opt{sparql} || RDF::Trine::Model->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'sparql'} || 'RDF::Trine::Model'->new
MC/DC0%0/2
$opt{'sparql'} || 'RDF::Trine::Model'->new
$opt{'sparql'}
'RDF::Trine::Model'->new
Truth table33%1/3
A || B
A= $opt{'sparql'}B= 'RDF::Trine::Model'->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if ( $opt{sparql} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | info "Getting RDF from SPARQL endpoint " . $opt{sparql}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | elsif ( $ARGV[0] =~ qr{^https?://} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | info "Reading RDF from $ARGV[0]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | RDF::Trine->default_useragent->ssl_opts( verify_hostname => 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | RDF::Trine::Parser->parse_url_into_model( $ARGV[0], $source ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | debug $source->size . " triples"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | info "Reading RDF files"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my $size = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | foreach my $file (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my $parser = RDF::Trine::Parser->guess_parser_by_filename($file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $parser->parse_file_into_model( "file://$file", $file, $source ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | debug $source->size - $size . " triples from $file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | $size = $source->size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ### SPARQL query method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | sub sparql { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sparql: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my ($query) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $query = <<'SPARQL'. $query . "\n}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | PREFIX dct: <http://purl.org/dc/terms/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | PREFIX vann: <http://purl.org/vocab/vann/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | SELECT * WHERE { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | SPARQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | trace $query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | my $q = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | $opt{sparql} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | ▶ | ? RDF::Query::Client->new($query) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | : RDF::Query->new($query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | $q->execute($source) // RDF::Trine::Iterator->new( [], 'bindings', [] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$q->execute($source) // "RDF::Trine::Iterator"->new([], "bindings", [])
MC/DC0%0/2
$q->execute($source) // "RDF::Trine::Iterator"->new([], "bindings", [])
$q->execute($source)
"RDF::Trine::Iterator"->new([], "bindings", [])
Truth table33%1/3
A // B
A= $q->execute($source)B= "RDF::Trine::Iterator"->new([], "bindings", [])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | ▶ | sub language { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
language: called CC=2 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | ▶ | $_[0]->literal_value_language // do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_[0]->literal_value_language // do {
&warning('missing language tag of ' . $_[0]);
$opt{"language"}
}
MC/DC0%0/2
$_[0]->literal_value_language // do {
&warning('missing language tag of ' . $_[0]);
$opt{"language"}
}
$_[0]->literal_value_language
do {
&warning('missing language tag of ' . $_[0]);
$opt{"language"}
}
Truth table33%1/3
A // B
A= $_[0]->literal_value_languageB= do {
&warning('missing language tag of ' . $_[0]);
$opt{"language"}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | warning "missing language tag of " . $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $opt{language}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ## Conversion methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | ▶ | sub prefLabel { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prefLabel: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | my ( $entity, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | ▶ | return unless isLiteral( $label, 'prefLabel' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | my $language = language($label); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | my $value = $label->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 3 | ▶ | if ( ( $entity->{prefLabel}->{$language} // $value ) ne $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$entity->{"prefLabel"}{$language} // $value
MC/DC0%0/2
$entity->{"prefLabel"}{$language} // $value
$entity->{"prefLabel"}{$language}
$value
Truth table33%1/3
A // B
A= $entity->{"prefLabel"}{$language}B= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | warning "multiple prefLabel\@$language for " . $entity->{uri}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | $entity->{prefLabel}->{$language} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | sub equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equal: called CC=7 SCAR=34.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my ( $a, $b ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return 1 if $a eq $b or $a == $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$a eq $b or $a == $b
MC/DC0%0/2
$a eq $b or $a == $b
$a eq $b
$a == $b
Truth table33%1/3
A or B
A= $a eq $bB= $a == $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( 'HASH' eq ref $a && 'HASH' eq ref $b ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
"HASH" eq ref $a and "HASH" eq ref $b
MC/DC0%0/2
"HASH" eq ref $a and "HASH" eq ref $b
"HASH" eq ref $a
"HASH" eq ref $b
Truth table0%0/3
A and B
A= "HASH" eq ref $aB= "HASH" eq ref $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return 1 if ( $a->{uri} && $a->{uri} eq $b->{uri} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a->{"uri"} and $a->{"uri"} eq $b->{"uri"}
MC/DC0%0/2
$a->{"uri"} and $a->{"uri"} eq $b->{"uri"}
$a->{"uri"}
$a->{"uri"} eq $b->{"uri"}
Truth table0%0/3
A and B
A= $a->{"uri"}B= $a->{"uri"} eq $b->{"uri"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return $JSON->encode($a) eq $JSON->encode($b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | ▶ | sub pushUnique { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pushUnique: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | my ( $list, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | return if any { equal( $_, $value ) } @$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 4 | push @$list, $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | sub pushUniqueUri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pushUniqueUri: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | my ( $list, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | return if any { $_->{uri} eq $value } @$list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | push @$list, { uri => $value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | ▶ | sub uriSet { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uriSet: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | my ( $entity, $property, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | ▶ | return unless $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | pushUniqueUri( $entity->{$property} //= [], $node->uri_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entity->{$property} //= []
MC/DC100%1/1
$entity->{$property} //= []
$entity->{$property}
Truth table100%2/2
A
A= $entity->{$property}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | sub agent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
agent: called CC=5 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | my ( $entity, $field, $node ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | ▶ | if ( $node && $node->is_literal ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$node and $node->is_literal
MC/DC0%0/2
$node and $node->is_literal
$node
$node->is_literal
Truth table33%1/3
A and B
A= $nodeB= $node->is_literal
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $language = language($node) // 'und'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
language($node) // "und"
MC/DC0%0/1
language($node) // "und"
language($node)
Truth table0%0/2
A
A= language($node)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $agent = { prefLabel => { $language => $node->literal_value } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | pushUnique( $entity->{$field} //= [], $agent ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$entity->{$field} //= []
MC/DC0%0/1
$entity->{$field} //= []
$entity->{$field}
Truth table0%0/2
A
A= $entity->{$field}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } # TODO: if resource | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | sub notation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notation: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | my ( $entity, $label ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 4 | ▶ | return unless isLiteral( $label, 'notation' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | pushUnique( $entity->{notation} //= [], $label->literal_value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entity->{"notation"} //= []
MC/DC100%1/1
$entity->{"notation"} //= []
$entity->{"notation"}
Truth table100%2/2
A
A= $entity->{"notation"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 30 | ▶ | sub isLiteral { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isLiteral: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 30 | my ( $node, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 30 | ▶ | return unless $node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 8 | ▶ | if ( $node->is_literal ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | warn "skipping non-literal $type: $node"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 22 | ▶ | sub note { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
note: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 22 | my ( $entity, $note, $type ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 22 | ▶ | return unless isLiteral( $note, $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | my $language = language($note); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | my $map = $entity->{$type} //= {}; # language map of lists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entity->{$type} //= {}
MC/DC0%0/1
$entity->{$type} //= {}
$entity->{$type}
Truth table50%1/2
A
A= $entity->{$type}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | my $list = $map->{$language} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$map->{$language} //= []
MC/DC0%0/1
$map->{$language} //= []
$map->{$language}
Truth table50%1/2
A
A= $map->{$language}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | my $string = $note->literal_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | $string =~ s/^\s+|\s+$//mg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | $string = $1 if $string =~ /^"(.+)"$/m; # BARTOC cleanup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | pushUnique( $list, $string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | ## Export JSKOS method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | sub export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | my ( $file, $jskos ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | ▶ | $file = $opt{name} . "-$file" if defined $opt{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | $file = $opt{directory} . '/' . $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | open my $fh, '>', $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | if ( $file =~ /\.ndjson$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | say $fh $JSON->encode($_) for @$jskos; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | say $fh $JSON_PRETTY->encode($jskos); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | debug $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ## convert concept scheme | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | unless ( $opt{scheme} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | my @schemes = sparql('?s a skos:ConceptScheme .')->get_all; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | fatal "RDF contains no skos:ConceptScheme" unless @schemes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | if ( @schemes > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | error "Please choose a concept scheme with option --scheme:"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | say $_->{s}->uri_value for @schemes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | $opt{scheme} = $schemes[0]->{s}->uri_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | info "Converting concept scheme $opt{scheme}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | my $scheme = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | '@context' => 'https://gbv.github.io/jskos/context.json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | uri => $opt{scheme}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | type => ['http://www.w3.org/2004/02/skos/core#ConceptScheme'], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | my $uri = $opt{scheme}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | my $res = sparql(<<SPARQL); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | <$uri> dct:title ?title . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | OPTIONAL { <$uri> skos:notation ?notation } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | OPTIONAL { <$uri> vann:preferredNamespacePrefix ?notation } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | OPTIONAL { <$uri> dct:description ?description } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | OPTIONAL { <$uri> dct:creator ?creator } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | OPTIONAL { <$uri> dct:contributor ?contributor } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | SPARQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | fatal "Concept scheme <$uri> not found or incomplete" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | unless $res->peek; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | $res->each( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | prefLabel( $scheme, $s->{title} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | notation( $scheme, $s->{notation} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | note( $scheme, $s->{description}, 'definition' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | agent( $scheme, 'creator', $s->{creator} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | agent( $scheme, 'contributor', $s->{contributor} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $res = sparql("<$opt{scheme}> skos:hasTopConcept ?c ."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | $res->each( sub { uriSet( $scheme, 'topConcepts', $_[0]->{c} ) } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $scheme->{topConcepts} = [ sort @{ $scheme->{topConcepts} } ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | if $scheme->{topConcepts}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | ▶ | debug "Found " . @{ $scheme->{topConcepts} || [] } . " explicit top concepts"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$scheme->{'topConcepts'} || []
MC/DC0%0/1
$scheme->{'topConcepts'} || []
$scheme->{'topConcepts'}
Truth table50%1/2
A
A= $scheme->{'topConcepts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1 | info "Exporting JSKOS scheme"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | export( 'scheme.json', $scheme ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ## convert concepts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | info "Converting concepts"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | my @noteTypes = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | qw(scopeNote definition example historyNote editorialNote changeNote note); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | my $concepts = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # TODO: just all concepts instead of inScheme/topConceptOf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # TODO: broader, altLabel etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # TODO: created, modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | my $query = <<SPARQL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | { { ?c skos:inScheme <$opt{scheme}> } UNION { ?c skos:topConceptOf <$opt{scheme}> } } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | OPTIONAL { ?c skos:prefLabel ?pLabel } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | OPTIONAL { ?c skos:notation ?notation } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | OPTIONAL { ?c skos:narrower ?narrower } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | OPTIONAL { ?c skos:broader ?broader } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | OPTIONAL { ?c skos:topConceptOf ?top } . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | SPARQL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $query = join "\n", $query, map { "OPTIONAL { ?c skos:$_ ?$_ } ." } @noteTypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | sparql($query)->each( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 3 | my $row = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 3 | my $uri = $row->{c}->uri_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | ▶ | unless ( defined $concepts->{$uri} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 2 | debug "$uri"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | $concepts->{$uri} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | type => ['http://www.w3.org/2004/02/skos/core#Concept'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 2 | inScheme => [ { uri => $opt{scheme} } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | $concepts->{$uri}{topConceptOf} = $concepts->{$uri}{inScheme} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | if ($row->{top} && $row->{top}->uri_value eq $scheme->{uri}) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | grep {$_->{uri} eq $uri} @{$scheme->{topConcepts} || []}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition62%5/8
$row->{"top"} and $row->{"top"}->uri_value eq $scheme->{"uri"} or grep {$_->{"uri"} eq $uri;} @{$scheme->{"topConcepts"} or [];}
$row->{"top"} and $row->{"top"}->uri_value eq $scheme->{"uri"}
$scheme->{'topConcepts'} || []
MC/DC33%1/3
$row->{"top"} and $row->{"top"}->uri_value eq $scheme->{"uri"} or grep {$_->{"uri"} eq $uri;} @{$scheme->{"topConcepts"} or [];}
$row->{"top"}
$row->{"top"}->uri_value eq $scheme->{"uri"}
grep {$_->{"uri"} eq $uri;} @{$scheme->{"topConcepts"} or [];}
MC/DC0%0/1
$scheme->{'topConcepts'} || []
$scheme->{'topConcepts'}
Truth table40%2/5
A and B or C
A= $row->{"top"}B= $row->{"top"}->uri_value eq $scheme->{"uri"}C= grep {$_->{"uri"} eq $uri;} @{$scheme->{"topConcepts"} or [];}
Truth table50%1/2
A
A= $scheme->{'topConcepts'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | my $concept = $concepts->{$uri}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 3 | notation( $concept, $row->{notation} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 3 | prefLabel( $concept, $row->{pLabel} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 3 | note( $concept, $row->{$_}, $_ ) for @noteTypes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 3 | uriSet( $concept, 'narrower', $row->{narrower} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 3 | uriSet( $concept, 'broader', $row->{broader} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | my $count = values %$concepts or warning "No concepts found"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | info "Exporting $count JSKOS concepts"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 1 | export( 'concepts.ndjson', [ map { $concepts->{$_} } sort keys %$concepts ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||