Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store::SPARQL reads and writes to Virtuoso (>=6.1.7) #113

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions RDF-Trine/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ t/store-hexastore-triplestore.t
t/store-hexastore.t
t/store-memory.t
t/store-redis.t
t/store-sparql.t
t/store-triple_sql.t
t/store.t
t/syntax.t
Expand Down
37 changes: 31 additions & 6 deletions RDF-Trine/lib/RDF/Trine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ This document describes RDF::Trine version 1.001
# Now print the results
print "Names of things:\n";
while (my $st = $iter->next) {
my $s = $st->subject;
my $name = $st->object;
# $s and $name have string overloading, so will print correctly
print "The name of $s is $name\n";
my $s = $st->subject;
my $name = $st->object;
# $s and $name have string overloading, so will print correctly
print "The name of $s is $name\n";
}

=head1 DESCRIPTION
Expand Down Expand Up @@ -96,7 +96,7 @@ use constant NIL_GRAPH => 'tag:[email protected],2010-01-01:RT:NIL';

use Log::Log4perl qw(:easy);
if (! Log::Log4perl::initialized() ) {
Log::Log4perl->easy_init($ERROR);
Log::Log4perl->easy_init($ERROR);
}

use RDF::Trine::Graph;
Expand Down Expand Up @@ -199,6 +199,31 @@ sub store {
return RDF::Trine::Store->new_with_string( $config );
}

=item C<< default_useragent ( [ $ua ] ) >>

Returns the L<LWP::UserAgent> object used by default for any operation requiring network
requests. Ordinarily, the calling code will obtain the default user agent, and clone it
before further configuring it for a specific request, thus leaving the default object
untouched.

If C<< $ua >> is passed as an argument, sets the global default user agent to this object.

=cut

{ my $_useragent;
sub default_useragent {
my $class = shift;
my $ua = shift || $_useragent;
unless (defined($ua)) {
$ua = LWP::UserAgent->new(
agent => "RDF::Trine/$RDF::Trine::VERSION",
#keep_alive => 1, # this is actually meaningless
);
}
$_useragent = $ua;
return $ua;
}}

1; # Magic true value required at end of module
__END__

Expand Down
2 changes: 2 additions & 0 deletions RDF-Trine/lib/RDF/Trine/Iterator/SAXHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ sub end_element {
push( @{ $results{ $addr } }, $vb );
}
} elsif ($tag eq 'bnode') {
# guess what! virtuoso uses funny bnodes
$string =~ s!nodeID://!!;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much prefer we didn't hard-code this, and instead found some way to modularize the code so that the SPARQL store could apply this fix only when it thinks necessary (or have it be applied to all results, but only when called from the SPARQL store or when explicitly requested). I'll try to think about what sort of API would work well for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that bnodes come through the sparql-results+xml format as nodeID://… The net effect is that without that line, the SPARQL results XML parser crashes when it tries to create a malformed bnode.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, understood. I'd just like to fix this by updating the API instead of hard-coding the fix into the XML parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure how to do this, other than making some kind of callback you can pass into the constructor (ugly), or otherwise a Virtuoso-specific subclass (worse).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the ::Iterator::SAXHandler constructor could already take optional configuration arguments, it just wasn't documented. I've updated the code to allow passing in a custom handler to generate the bnode IDs. Have a look at commit eea4393.

$values{ $addr } = RDF::Trine::Node::Blank->new( $string );
} elsif ($tag eq 'uri') {
$values{ $addr } = RDF::Trine::Node::Resource->new( $string );
Expand Down
Loading