| 1 | =head1 NAME | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | RDF::Query::Functions::Jena - Jena/ARQ work-alike functions | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 VERSION | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | This document describes RDF::Query::Functions::Jena version 2.919. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Defines the following functions: | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =over | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =item * java:com.hp.hpl.jena.query.function.library.langeq | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =item * java:com.hp.hpl.jena.query.function.library.listMember | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =item * java:com.hp.hpl.jena.query.function.library.now | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =item * java:com.hp.hpl.jena.query.function.library.sha1sum | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =back | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | package RDF::Query::Functions::Jena; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 35 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 35 | our ($VERSION, $l); | |||||||||||||||||||||||||||
| 33 | 35 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 35 | $l = Log::Log4perl->get_logger("rdf.query.functions.jena"); | |||||||||||||||||||||||||||
| 35 | 35 | $VERSION = '2.919'; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 35 | ▶ | use Digest::SHA qw(sha1_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 35 | ▶ | use I18N::LangTags; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 35 | ▶ | use Scalar::Util qw(blessed reftype refaddr looks_like_number); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =begin private | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =item C<< install >> | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Documented in L<RDF::Query::Functions>. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =end private | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =cut | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 35 | ▶ | sub install { | ||||||||||||||||||||||||||
|
Subroutine
install: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | RDF::Query::Functions->install_function( | ||||||||||||||||||||||||||||
| 54 | ["http://jena.hpl.hp.com/ARQ/function#sha1sum", "java:com.hp.hpl.jena.query.function.library.sha1sum"], | ||||||||||||||||||||||||||||
| 55 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 56 | 2 | my $query = shift; | |||||||||||||||||||||||||||
| 57 | 2 | my $node = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | my $value; | |||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ($node->isa('RDF::Query::Node::Literal')) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 61 | 1 | $value = $node->literal_value; | |||||||||||||||||||||||||||
| 62 | } elsif ($node->isa('RDF::Query::Node::Resource')) { | ||||||||||||||||||||||||||||
| 63 | 1 | $value = $node->uri_value; | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 0 | throw RDF::Query::Error::TypeError -text => "jena:sha1sum called without a literal or resource"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 2 | my $hash = sha1_hex( $value ); | |||||||||||||||||||||||||||
| 68 | 2 | return RDF::Query::Node::Literal->new( $hash ); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 35 | ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | RDF::Query::Functions->install_function( | ||||||||||||||||||||||||||||
| 73 | ["http://jena.hpl.hp.com/ARQ/function#now", "java:com.hp.hpl.jena.query.function.library.now"], | ||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 75 | 2 | my $query = shift; | |||||||||||||||||||||||||||
| 76 | 2 | my $dt = DateTime->now(); | |||||||||||||||||||||||||||
| 77 | 2 | ▶ | my $f = ref($query) ? $query->dateparser : DateTime::Format::W3CDTF->new; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 2 | my $value = $f->format_datetime( $dt ); | |||||||||||||||||||||||||||
| 79 | 2 | return RDF::Query::Node::Literal->new( $value, undef, 'http://www.w3.org/2001/XMLSchema#dateTime' ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 35 | ); | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | RDF::Query::Functions->install_function( | ||||||||||||||||||||||||||||
| 84 | ["http://jena.hpl.hp.com/ARQ/function#langeq", "java:com.hp.hpl.jena.query.function.library.langeq"], | ||||||||||||||||||||||||||||
| 85 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 2 | my $query = shift; | |||||||||||||||||||||||||||
| 87 | 2 | my $node = shift; | |||||||||||||||||||||||||||
| 88 | 2 | my $lang = shift; | |||||||||||||||||||||||||||
| 89 | 2 | my $litlang = $node->literal_value_language; | |||||||||||||||||||||||||||
| 90 | 2 | my $match = $lang->literal_value; | |||||||||||||||||||||||||||
| 91 | 2 | ▶ | return I18N::LangTags::is_dialect_of( $litlang, $match ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | ? RDF::Query::Node::Literal->new('true', undef, 'http://www.w3.org/2001/XMLSchema#boolean') | ||||||||||||||||||||||||||||
| 93 | : RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean'); | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 35 | ); | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | RDF::Query::Functions->install_function( | ||||||||||||||||||||||||||||
| 98 | ["http://jena.hpl.hp.com/ARQ/function#listMember", "java:com.hp.hpl.jena.query.function.library.listMember"], | ||||||||||||||||||||||||||||
| 99 | 3 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=22.0
| |||||||||||||||||||||||||||||
| 100 | 3 | my $query = shift; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | my $list = shift; | |||||||||||||||||||||||||||
| 103 | 3 | my $value = shift; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | my $first = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first' ); | |||||||||||||||||||||||||||
| 106 | 3 | my $rest = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest' ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 3 | my $result; | |||||||||||||||||||||||||||
| 109 | 3 | ▶ | LIST: while ($list) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 6 | ▶ | if ($list->is_resource and $list->uri_value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$list->is_resource and $list->uri_value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
MC/DC0%0/2
$list->is_resource and $list->uri_value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
$list->is_resource
$list->uri_value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
Truth table33%1/3
A and B
A= $list->is_resourceB= $list->uri_value eq "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
| |||||||||||||||||||||||||||||
| 111 | 0 | return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean'); | |||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||
| 113 | 6 | my $stream = $query->model->get_statements( $list, $first, undef ); | |||||||||||||||||||||||||||
| 114 | 6 | ▶ | while (my $stmt = $stream->next()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 6 | my $member = $stmt->object; | |||||||||||||||||||||||||||
| 116 | 6 | ▶ | return RDF::Query::Node::Literal->new('true', undef, 'http://www.w3.org/2001/XMLSchema#boolean') if ($value->equal( $member )); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 3 | my $stmt = $query->model->get_statements( $list, $rest, undef )->next(); | |||||||||||||||||||||||||||
| 120 | 3 | ▶ | return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean') unless ($stmt); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 3 | my $tail = $stmt->object; | |||||||||||||||||||||||||||
| 123 | 3 | ▶ | if ($tail) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 3 | $list = $tail; | |||||||||||||||||||||||||||
| 125 | 3 | next; #next LIST; | |||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | 0 | return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean'); | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean'); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 35 | ); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 35 | 1; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||