/usr/share/perl5/RDF/Redland/Node.pm is in librdf-perl 1.0.13.1-2build1.
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | # -*- Mode: Perl -*-
#
# Node.pm - Redland Perl RDF Node module
#
# Copyright (C) 2000-2005 David Beckett - http://www.dajobe.org/
# Copyright (C) 2000-2005 University of Bristol - http://www.bristol.ac.uk/
#
# This package is Free Software and part of Redland http://librdf.org/
#
# It is licensed under the following three licenses as alternatives:
# 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
# 2. GNU General Public License (GPL) V2 or any newer version
# 3. Apache License, V2.0 or any newer version
#
# You may not use this file except in compliance with at least one of
# the above three licenses.
#
# See LICENSE.html or LICENSE.txt at the top of this package for the
# full license terms.
#
#
#
package RDF::Redland::Node;
use strict;
use vars qw($Type_Resource $Type_Property $Type_Literal
$Type_Statement $Type_Blank);
# FIXME: Should be the same as values of librdf_node_type enum in rdf_node.h
# and mechanically kept in sync.
$Type_Resource = 1;
$Type_Literal = 2;
$Type_Blank = 4;
# FIXME: Needs to also match documentation near sub type
=pod
=head1 NAME
RDF::Redland::Node - Redland RDF Node (RDF Resource, Property, Literal) Class
=head1 SYNOPSIS
use RDF::Redland;
my $node1=new RDF::Redland::Node("Hello, World!");
my $node2=new RDF::Redland::Node($uri); # $uri is an RDF::Redland::URI
my $node3=$node2->clone;
my $node4=new RDF::Redland::URINode("http://example.com/");
my $node5=new RDF::Redland::LiteralNode("Hello, World!");
my $node6=new RDF::Redland::XMLLiteral("<tag>content</tag>");
my $node7=new RDF::Redland::BlankNode("genid1");
# alternate more verbose ways:
my $node4=RDF::Redland::Node->new_from_uri("http://example.com/");
my $node5=RDF::Redland::Node->new_literal("Hello, World!");
my $node6=RDF::Redland::Node->new_xml_literal("<tag>content</tag>");
my $node7=RDF::Redland::Node->new_from_blank_identifier("genid1");
...
print $node4->uri->as_string,"\n"; # Using RDF::Redland::URI::as_string
print $node5->literal_value_as_latin1,"\n";
=head1 DESCRIPTION
This class represents RDF URIs, literals and blank nodes in the RDF graph.
=cut
######################################################################
=pod
=head1 CONSTRUCTORS
=over
=item new [STRING | URI | NODE]
Create a new URI node, literal node or copy an existing node.
If a literal I<STRING> is given, make a plain literal node. If a
the argument is of type I<URI> (perl URI or RDF::Redland::URI),
make a resource node.
Otherwise if the argument is an RDF::Redland::Node I<NODE>, copy it.
=cut
# CONSTRUCTOR
# (main)
sub new ($;$) {
my($proto,$arg)=@_;
my $class = ref($proto) || $proto;
my $self = {};
if($arg) {
if(my $arg_class=ref($arg)) {
# Try several classes
if(UNIVERSAL::isa($arg, 'RDF::Redland::Node')) {
return $arg->clone;
} elsif(UNIVERSAL::isa($arg, 'RDF::Redland::URI')) {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$arg->as_string);
} elsif (UNIVERSAL::isa($arg, 'URI')) {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$arg->as_string);
} else {
die "RDF::Redland::Node::new - Cannot make a node from an object of class $arg_class\n";
}
} else {
# Not a class
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_typed_literal($RDF::Redland::World->{WORLD},$arg,'',undef);
}
} else {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node($RDF::Redland::World->{WORLD});
}
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
sub new_from_uri_string ($$) {
my($proto,$uri_string)=@_;
my $class = ref($proto) || $proto;
my $self = {};
die "RDF::Redland::Node::new_from_uri_string - Cannot create node from empty URI\n"
unless $uri_string;
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$uri_string);
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
=item new_from_uri URI
Create a new URI node. I<URI> can be either a RDF::Redland::URI
object, a perl URI class or a literal string.
An alternative is:
new RDF::Redland::URINode("http://example.org/");
=cut
sub new_from_uri ($$) {
my($proto,$arg)=@_;
my $class = ref($proto) || $proto;
my $self = {};
if(my $class=ref $arg) {
if(UNIVERSAL::isa($arg, 'RDF::Redland::URI')) {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri($RDF::Redland::World->{WORLD},$arg->{URI});
} elsif (UNIVERSAL::isa($arg, 'URI')) {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$arg->as_string);
} else {
die "RDF::Redland::Node::new_from_uri - Cannot make a Node from an object of class $class\n";
}
} else {
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$arg);
}
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
sub new_from_literal ($$$$) {
my($proto,$string,$xml_language,$is_wf_xml)=@_;
my $class = ref($proto) || $proto;
my $self = {};
$is_wf_xml=($is_wf_xml ? 1 : 0);
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_literal($RDF::Redland::World->{WORLD},$string,$xml_language,$is_wf_xml);
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
=item new_literal STRING [DATATYPE [XML_LANGUAGE]]
Create a new literal node for a literal value I<STRING>.
Optional datatype URI I<DATATYPE> (RDF::Redland::URI, perl URI or string)
and language (xml:lang attribute) I<XML_LANGUAGE> may also be given.
An alternative is:
new RDF::Redland::LiteralNode("Hello, World!");
new RDF::Redland::LiteralNode("Bonjour monde!", undef, "fr");
=cut
sub new_literal ($$;$$) {
my($proto,$string,$dt,$xml_language)=@_;
my $class = ref($proto) || $proto;
my $self = {};
my $dt_uri=undef;
if(defined $dt) {
if(UNIVERSAL::isa($dt, 'RDF::Redland::URI')) {
# nop
} elsif (UNIVERSAL::isa($dt, 'URI')) {
$dt=RDF::Redland::URI->new($dt->as_string);
} else {
$dt=RDF::Redland::URI->new($dt);
}
$dt_uri=$dt->{URI};
}
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_typed_literal($RDF::Redland::World->{WORLD},$string,$xml_language,$dt_uri);
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
=item new_xml_literal STRING
Create a new XML datatyped literal node for the XML in I<STRING>.
An alternative is:
new RDF::Redland::XMLLiteral("<tag>content</tag>");
=cut
sub new_xml_literal ($$) {
my($proto,$string)=@_;
return $proto->new_from_literal($string,'',1);
}
=item new_from_blank_identifier IDENTIFIER
Create a new blank node with blank node identifier I<IDENTIFIER>.
An alternative is:
new RDF::Redland::BlankNode("id");
=cut
sub new_from_blank_identifier ($;$) {
my($proto,$identifier)=@_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_blank_identifier($RDF::Redland::World->{WORLD},$identifier);
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
=item clone
Copy a RDF::Redland::Node.
=cut
sub clone ($) {
my($node)=@_;
my $class = ref($node);
my $self = {};
if(!$class || $class ne 'RDF::Redland::Node') {
die "RDF::Redland::Node::clone - Cannot copy a node object not of class RDF::Redland::Node\n";
}
$self->{NODE}=&RDF::Redland::CORE::librdf_new_node_from_node($node->{NODE});
return undef if !$self->{NODE};
bless ($self, $class);
return $self;
}
sub new_from_node ($$) {
my($proto,$node)=@_;
return $node->clone;
}
# internal constructor to build an object from a node created
# by librdf e.g. from the result of a iterator->next operation
# It always makes a new Redland Node
sub _new_from_object ($$;$) {
my($proto,$object,$do_not_copy)=@_;
return undef if !$object;
my $class = ref($proto) || $proto;
my $self = {};
$self->{NODE}=$do_not_copy ? $object : &RDF::Redland::CORE::librdf_new_node_from_node($object);
bless ($self, $class);
return $self;
}
=pod
=back
=cut
# DESTRUCTOR
sub DESTROY ($) {
my $self=shift;
warn "RDF::Redland::Node DESTROY $self" if $RDF::Redland::Debug;
if($self->{NODE}) {
&RDF::Redland::CORE::librdf_free_node($self->{NODE});
}
warn "RDF::Redland::Node DESTROY done\n" if $RDF::Redland::Debug;
}
=head1 METHODS
=over
=item uri
Get the current URI of the node as an RDF::Redland::URI object.
=cut
sub uri ($) {
my $obj=&RDF::Redland::CORE::librdf_node_get_uri(shift->{NODE});
return $obj ? RDF::Redland::URI->_new_from_object($obj) : undef;
}
=item blank_identifier
Get the current blank identifier of the node
=cut
sub blank_identifier ($) {
return &RDF::Redland::CORE::librdf_node_get_blank_identifier(shift->{NODE});
}
=item type
Get the node type. It is recommended to use the is_resource, is_literal
or is_blank methods in preference to this (both simpler and quicker).
The current list of types that are supported are:
$RDF::Redland::Node::Type_Resource
$RDF::Redland::Node::Type_Literal
$RDF::Redland::Node::Type_Blank
Example:
if ($node->type == $RDF::Redland::Node::Type_Resource) {
print "Node is a resource with URI ", $node->uri->as_string, "\n";
} else {
...
}
=cut
sub type ($) {
return &RDF::Redland::CORE::librdf_node_get_type(shift->{NODE});
}
=item is_resource
Return true if node is a resource (with a URI)
=cut
sub is_resource($) {
return &RDF::Redland::CORE::librdf_node_is_resource(shift->{NODE});
}
=item is_literal
Return true if node is a literal
=cut
sub is_literal($) {
return &RDF::Redland::CORE::librdf_node_is_literal(shift->{NODE});
}
=item is_blank
Return true if node is a blank nodeID
=cut
sub is_blank($) {
return &RDF::Redland::CORE::librdf_node_is_blank(shift->{NODE});
}
=item literal_value
Get the node literal value string as UTF-8 (when the node is of type
$RDF::Redland::Node::Type_Literal)
=cut
sub literal_value ($) {
&RDF::Redland::CORE::librdf_node_get_literal_value(shift->{NODE});
}
=item literal_value_as_latin1
Get the node literal value string converted from UTF-8 to ISO Latin-1
(when the node is of type $RDF::Redland::Node::Type_Literal)
=cut
sub literal_value_as_latin1 ($) {
&RDF::Redland::CORE::librdf_node_get_literal_value_as_latin1(shift->{NODE});
}
=item literal_value_language
Get the node literal XML language (when the node is of type
$RDF::Redland::Node::Type_Literal) or undef if not present.
=cut
sub literal_value_language ($) {
&RDF::Redland::CORE::librdf_node_get_literal_value_language(shift->{NODE});
}
=item literal_value_is_wf_xml
Return non 0 if the literal string is well formed XML (when the node
is of type $RDF::Redland::Node::Type_Literal).
=cut
sub literal_value_is_wf_xml ($) {
&RDF::Redland::CORE::librdf_node_get_literal_value_is_wf_xml(shift->{NODE});
}
=item literal_datatype
Return the RDF::Redland::URI of the literal datatype or undef if it
is not a datatype.
=cut
sub literal_datatype($) {
my $self=shift;
my $uri=&RDF::Redland::CORE::librdf_node_get_literal_value_datatype_uri($self->{NODE});
return $uri ? RDF::Redland::URI->new(&RDF::Redland::CORE::librdf_uri_to_string($uri)) : undef;
}
=item as_string
Return the RDF::Redland::Node formatted as a string (UTF-8 encoded).
=cut
sub as_string ($) {
&RDF::Redland::CORE::librdf_node_to_string(shift->{NODE});
}
=item equals NODE
Return non zero if this node is equal to NODE
=cut
sub equals ($$) {
my($self,$node)=@_;
&RDF::Redland::CORE::librdf_node_equals($self->{NODE}, $node->{NODE});
}
# Ensure the thing given is a Redland node, promoting it if possible
# from other perl objects.
sub _ensure ($) {
my $node=shift;
if(UNIVERSAL::isa($node, 'RDF::Redland::Node')) {
$node=&RDF::Redland::CORE::librdf_new_node_from_node($node->{NODE});
} elsif(UNIVERSAL::isa($node, 'RDF::Redland::URI')) {
$node=&RDF::Redland::CORE::librdf_new_node_from_uri($RDF::Redland::World->{WORLD},$node->{URI});
} elsif (UNIVERSAL::isa($node, 'URI')) {
$node=&RDF::Redland::CORE::librdf_new_node_from_uri_string($RDF::Redland::World->{WORLD},$node->as_string);
} else {
$node=undef;
}
return $node;
}
=pod
=back
=head1 OLDER METHODS
=over
=item new_from_literal STRING XML_LANGUAGE IS_WF
Create a new RDF::Redland::Node object for a literal value I<STRING> with XML
language (xml:lang attribute) I<XML_LANGUAGE>
and if content is well formed XML, when I<IS_WF> is non
0. I<XML_LANGUAGE> is optional can can be set to undef.
This method remains but using new_literal is prefered.
Instead, for plain literals use:
$node=new RDF::Redland::Node("blah")
=item new_from_typed_literal STRING [DATATYPE [XML_LANGUAGE]]
Renamed to new_literal with same arguments.
=item new_from_uri_string URI_STRING
Create a new RDF::Redland::Node object for a resource with URI I<URI_STRING>.
It is equivalent to use the shorter:
$a=new RDF::Redland::Node->new_from_uri($uri_string)
=item new_from_node NODE
Create a new RDF::Redland::Node object from existing
RDF::Redland::Node I<NODE> (copy constructor).
It is equivalent to use:
$new_node=$old_node->clone
=back
=head1 SEE ALSO
L<RDF::Redland::Statement>
=head1 AUTHOR
Dave Beckett - http://www.dajobe.org/
=cut
1;
|