view release on metacpan or search on metacpan
lib/RDFStore/Parser/NTriples.pm view on Meta::CPAN
croak $err
if $err;
};
return $ret;
};
};
sub addTriple {
my ($class,$subject,$predicate,$object,$context) = @_;
#print STDERR "addTriple('".$subject->toString."','".$predicate->toString."','".$object->toString."'".( ($context) ? ",'".$context->toString."'" : '' ).")",((caller)[2]),"\n";
# If there is no subject (about=""), then use the URI/filename where the RDF description came from
$subject = $class->{nodeFactory}->createResource($class->{sSource})
unless( (defined $subject) && ($subject->toString()) && (length($subject->toString())>0) );
#Trigger 'Assert' event
my $assert = $class->{Handlers}->{Assert}
if(ref($class->{Handlers}) =~ /HASH/);
if (defined($assert)) {
return &$assert($class, $class->{nodeFactory}->createStatement($subject,$predicate,$object,$context) );
} else {
return;
};
};
sub newReificationID {
my ($class) = @_;
#print STDERR "newReificationID($class): ",((caller)[2]),"\n";
return 'genid' . $class->{iReificationCounter}++;
};
1;
};
__END__
=head1 NAME
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
if $err;
};
return unless defined wantarray;
return wantarray ? @ret : $ret;
};
};
sub getAttributeValue {
my ($expat,$attlist, $elName) = @_;
#print STDERR "getAttributeValue(@_): ".(caller)[2]."\n";
return
if( (ref($attlist) =~ /ARRAY/) && (!@{$attlist}) );
my $n;
for($n=0; $n<=$#{$attlist}; $n+=2) {
my $attname;
if(ref($attlist->[$n]) =~ /ARRAY/) {
#$attname = $attlist->[$n]->[0].$attlist->[$n]->[1];
$attname = $attlist->[$n]->[0];
$attname .= $attlist->[$n]->[1]
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
$expat->{SiRPAC}->{bCreateBags}, $expat->{SiRPAC}->{bCreateBags});
} else {
processTypedNode($expat,$ele);
};
};
sub processDescription {
my ($expat,$ele,$inPredicate,$reify,$createBag) = @_;
#print STDERR "processDescription($expat,".$ele->name.",$inPredicate,$reify,$createBag)",((caller)[2]),"\n";
# Return immediately if the description has already been managed
return $ele->{sID}
if($ele->{bDone});
my $iChildCount=1;
my $bOnce=1;
# Determine first all relevant values
my ($sID,$sBagid,$sAbout,$sAboutEach) = (
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
};
# we could use URI and XPath modules to validate and normalise the subject, predicate, object
# Use XPath/XPointer for literals could be cool to have one unique uri thing
sub addTriple {
my ($expat,$predicate,$subject,$object, $context) = @_;
#print STDERR "addTriple('".
# (($predicate) ? $predicate->toString : '')."','".
# (($subject) ? $subject->toString : '')."','".
# (($object) ? $object->toString : '')."')",((caller)[2]),"\n";
# If there is no subject (rdf:about="") or object (rdf:resource=""), then use the URI/filename where the RDF description came from
carp "Predicate null when subject=".$subject->toString." and object=".$object->toString
unless(defined $predicate);
carp "Subject null when predicate=".$predicate->toString." and object=".$object->toString
unless(defined $subject);
carp "Object null when predicate=".$predicate->toString." and subject=".$subject->toString
unless(defined $object);
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
return &$assert($expat,
$expat->{SiRPAC}->{nodeFactory}->createStatement($subject,$predicate,$object, $context) ); #context too nowdays...
} else {
return;
};
};
sub newReificationID {
my ($expat) = @_;
#print STDERR "newReificationID($expat): ",((caller)[2]),"\n";
# try to generate system/run wide unique ID i.e. 'S' + unpack("H*", rand()) + 'P' + $$ + 'T' + time() + 'N' + GenidNumber
return 'rdf:nodeID:genidrdfstore' .
'S'.$expat->{SiRPAC}->{'rand_seed'} .
'P'. $$.
'T'. $expat->{SiRPAC}->{'timestamp'} .
'N'. $expat->{SiRPAC}->{iReificationCounter}++;
};
sub processTypedNode {
my ($expat,$typedNode) = @_;
#print STDERR "processTypedNode(".$typedNode->{tag}."): ",((caller)[2]),"\n";
my $sID = $typedNode->{sID};
my $sBagID = $typedNode->{sBagID};
my $sAbout = $typedNode->{sAbout};
my $target = (defined $typedNode->{vTargets}->[0]) ? $typedNode->{vTargets}->[0] : undef;
my $sAboutEach = $typedNode->{sAboutEach};
if ( (defined $typedNode->{sResource}) && ($typedNode->{sResource} ne '') && ($typedNode->{sResource} !~ /^rdf:nodeID:/) ) {
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
};
my $sDesc = processDescription($expat,$typedNode, 0, $expat->{SiRPAC}->{bCreateBags}, 0);
return $sObject;
};
sub processContainer {
my ($expat,$n) = @_;
#print STDERR "processContainer($n)",((caller)[2]),"\n";
my $sID = $n->{sID};
$sID = $n->{sAbout}
unless((defined $sID) && ($sID ne ''));
my $nodeID = getAttributeValue($expat, $n->{attlist},$RDFStore::Parser::SiRPAC::RDFMS_nodeID);
if( defined $nodeID ) {
$sID = 'rdf:nodeID:'.$nodeID
unless((defined $sID) && ($sID ne ''));
} else {
$sID = newReificationID($expat)
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
if defined($eclines);
return $message;
};
# processPredicate handles all elements not defined as special
# RDF elements. <tt>predicate</tt> has either <tt>resource()</tt> or a single child
sub processPredicate {
my ($expat,$predicate,$description,$sTarget,$reify) = @_;
#print STDERR "processPredicate($predicate->{tag},$description->{tag},$sTarget,$reify)",((caller)[2]),"\n";
my $sStatementID = $predicate->{sID};
my $sBagID = $predicate->{sBagID};
my $sResource = $predicate->{sResource};
# If a predicate has other attributes than rdf:ID, rdf:bagID,
# or xmlns... -> generate new triples according to the spec.
# (See end of Section 6)
# this new element may not be needed
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
my $nodeID = getAttributeValue($expat, $ele->{attlist},$RDFStore::Parser::SiRPAC::RDFMS_nodeID); # XXXXXXX to be checked
if ( defined $nodeID ) {
$sNodeID = 'rdf:nodeID:'.$nodeID
if(not(((defined $sNodeID) && ($sNodeID ne ''))));
} else {
$sNodeID = newReificationID($expat)
if(not(((defined $sNodeID) && ($sNodeID ne ''))));
};
#print STDERR "reify('".$predicate->toString."','".$subject->toString."','".$object->toString."','$sNodeID','$ele')",((caller)[2]),"\n";
# The original statement must remain in the data model
addTriple($expat,$predicate, $subject, $object, $ele->{'context'});
# Do not reify reifyd properties
if ( ($predicate eq $RDFStore::Parser::SiRPAC::RDFMS_subject) ||
($predicate eq $RDFStore::Parser::SiRPAC::RDFMS_predicate) ||
($predicate eq $RDFStore::Parser::SiRPAC::RDFMS_object) ||
($predicate eq $RDFStore::Parser::SiRPAC::RDFMS_type) ) {
return;
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
return $sNodeID;
};
# Take an element <i>ele</i> with its parent element <i>parent</i>
# and evaluate all its attributes to see if they are non-RDF specific
# and non-XML specific in which case they must become children of
# the <i>ele</i> node.
sub expandAttributes {
my ($expat,$parent,$ele,$predicateNode,$resourceValue) = @_;
#print "expandAttributes(".$parent->name().",".$ele->name().",$predicateNode)",((caller)[2]),"\n";
#use Data::Dumper;
#print Dumper($parent);
my $foundAbbreviation = 0;
my $resourceFound = 0;
my $count=0;
while ($count<=$#{$ele->{attlist}}) {
my $sAttribute = ( (defined $ele->{attlist}->[$count++]->[0]) ? $ele->{attlist}->[$count-1]->[0] : '').( (defined $ele->{attlist}->[$count-1]->[1]) ? $ele->{attlist}->[$count-1]->[1] : '');
my $sValue = getAttributeValue($expat, $ele->{attlist},$sAttribute);
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
# print STDERR $_,"\n";
#};
#} @{$ele->{attlist}};
return $foundAbbreviation;
};
sub parseLiteral {
my ($expat) = @_;
#print STDERR "parseLiteral(): ".(caller)[2]."\n";
foreach(reverse @{$expat->{SiRPAC}->{elementStack}}) {
my $sParseType = getAttributeValue( $expat,
$_->{attlist},
$RDFStore::Parser::SiRPAC::RDFMS_parseType );
return 1
if( (defined $sParseType) &&
($sParseType ne "Resource") &&
($sParseType ne "Collection") );
};
return 0;
};
sub parseResource {
my ($expat) = @_;
#print STDERR "parseResource($expat)",((caller)[2]),"\n";
foreach(reverse @{$expat->{SiRPAC}->{elementStack}}) {
my $sParseType = getAttributeValue( $expat,
$_->{attlist},
$RDFStore::Parser::SiRPAC::RDFMS_parseType );
return 1
if( (defined $sParseType) &&
($sParseType eq "Resource") );
};
return 0;
};
sub normalizeResourceIdentifier {
my ($expat,$sURI) = @_;
return $sURI
if ( $sURI =~ /^rdf:nodeID:/ ); #do not touch bNodes
#print STDERR "normalizeResourceIdentifier(['",$expat->base,"'],'$sURI')".(caller)[2]."\n";
my $xml_base = $expat->base; #which is also set if a SourceBase is passed to the parser
my $URL = URI->new($sURI);
if( (defined $URL->scheme) &&
( $URL->scheme ne 'file') ) {
# If sURI is an absolute URI, don't bother
# with it
return $sURI;
} elsif( (defined $sURI) &&
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
};
package RDFStore::Parser::SiRPAC::Element;
{
sub new {
my ($pkg, $namespace, $tag, $attlist, $lang, $datatype, $context) = @_;
$attlist = []
unless(defined $attlist);
#print STDERR "RDFStore::Parser::SiRPAC::Element::new( @_ ): ".(caller)[2]."\n";
my $self = {
tag => $tag,
sNamespace => $namespace,
attlist => $attlist,
children => [],
vTargets => [],
bDone => 0,
isCollection => 0,
#at this level is just because SiRPAC parsing struct is broken (wrong to propagate XML attribute on elements)
lib/RDFStore/Parser/SiRPAC.pm view on Meta::CPAN
return $_[0]->{sNamespace};
};
};
package RDFStore::Parser::SiRPAC::DataElement;
{
@RDFStore::Parser::SiRPAC::DataElement::ISA = qw( RDFStore::Parser::SiRPAC::Element );
sub new {
my ($pkg, $text, $parsetype, $lang, $datatype, $context) = @_;
#print STDERR "RDFStore::Parser::SiRPAC::DataElement::new( @_ ): ".(caller)[2]."\n";
my $self = $pkg->SUPER::new(undef,$text,undef,$lang, $datatype, $context);
delete $self->{sNamespace}; # we do not need it
delete $self->{attlist}; # we do not need it
$self->{'parse_type'} = ( $parsetype or
$datatype eq 'http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral' ) ? 1 : 0; #Literal or Resource
$self->{tag} = "[DATA: " . $text . "]";
$self->{sContent} = $text; #instanceOf Data :-)