/usr/share/perl5/RDF/Query/Functions/Jena.pm is in librdf-query-perl 2.918-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | =head1 NAME
RDF::Query::Functions::Jena - Jena/ARQ work-alike functions
=head1 VERSION
This document describes RDF::Query::Functions::Jena version 2.918.
=head1 DESCRIPTION
Defines the following functions:
=over
=item * java:com.hp.hpl.jena.query.function.library.langeq
=item * java:com.hp.hpl.jena.query.function.library.listMember
=item * java:com.hp.hpl.jena.query.function.library.now
=item * java:com.hp.hpl.jena.query.function.library.sha1sum
=back
=cut
package RDF::Query::Functions::Jena;
use strict;
use warnings;
use Log::Log4perl;
our ($VERSION, $l);
BEGIN {
$l = Log::Log4perl->get_logger("rdf.query.functions.jena");
$VERSION = '2.918';
}
use Digest::SHA qw(sha1_hex);
use I18N::LangTags;
use Scalar::Util qw(blessed reftype refaddr looks_like_number);
=begin private
=item C<< install >>
Documented in L<RDF::Query::Functions>.
=end private
=cut
sub install {
RDF::Query::Functions->install_function(
["http://jena.hpl.hp.com/ARQ/function#sha1sum", "java:com.hp.hpl.jena.query.function.library.sha1sum"],
sub {
my $query = shift;
my $node = shift;
my $value;
if ($node->isa('RDF::Query::Node::Literal')) {
$value = $node->literal_value;
} elsif ($node->isa('RDF::Query::Node::Resource')) {
$value = $node->uri_value;
} else {
throw RDF::Query::Error::TypeError -text => "jena:sha1sum called without a literal or resource";
}
my $hash = sha1_hex( $value );
return RDF::Query::Node::Literal->new( $hash );
}
);
RDF::Query::Functions->install_function(
["http://jena.hpl.hp.com/ARQ/function#now", "java:com.hp.hpl.jena.query.function.library.now"],
sub {
my $query = shift;
my $dt = DateTime->now();
my $f = ref($query) ? $query->dateparser : DateTime::Format::W3CDTF->new;
my $value = $f->format_datetime( $dt );
return RDF::Query::Node::Literal->new( $value, undef, 'http://www.w3.org/2001/XMLSchema#dateTime' );
}
);
RDF::Query::Functions->install_function(
["http://jena.hpl.hp.com/ARQ/function#langeq", "java:com.hp.hpl.jena.query.function.library.langeq"],
sub {
my $query = shift;
my $node = shift;
my $lang = shift;
my $litlang = $node->literal_value_language;
my $match = $lang->literal_value;
return I18N::LangTags::is_dialect_of( $litlang, $match )
? RDF::Query::Node::Literal->new('true', undef, 'http://www.w3.org/2001/XMLSchema#boolean')
: RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean');
}
);
RDF::Query::Functions->install_function(
["http://jena.hpl.hp.com/ARQ/function#listMember", "java:com.hp.hpl.jena.query.function.library.listMember"],
sub {
my $query = shift;
my $list = shift;
my $value = shift;
my $first = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#first' );
my $rest = RDF::Query::Node::Resource->new( 'http://www.w3.org/1999/02/22-rdf-syntax-ns#rest' );
my $result;
LIST: while ($list) {
if ($list->is_resource and $list->uri_value eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil') {
return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean');
} else {
my $stream = $query->model->get_statements( $list, $first, undef );
while (my $stmt = $stream->next()) {
my $member = $stmt->object;
return RDF::Query::Node::Literal->new('true', undef, 'http://www.w3.org/2001/XMLSchema#boolean') if ($value->equal( $member ));
}
my $stmt = $query->model->get_statements( $list, $rest, undef )->next();
return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean') unless ($stmt);
my $tail = $stmt->object;
if ($tail) {
$list = $tail;
next; #next LIST;
} else {
return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean');
}
}
}
return RDF::Query::Node::Literal->new('false', undef, 'http://www.w3.org/2001/XMLSchema#boolean');
}
);
}
1;
__END__
=head1 AUTHOR
Gregory Williams <gwilliams@cpan.org>.
=cut
|