Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SYNOPSIS
my $mrdf = MongoDB::RDF->new(
database => MongoDB::Connection->new(host => 'localhost', port => 27017)->test_rdf
);

my $graph = $mrdf->default_graph;

my $r = MongoDB::RDF::Resource->new('http://example.org/0');
$r->dc_title('my title');
$graph->save($r);
Expand Down
4 changes: 2 additions & 2 deletions lib/MongoDB/RDF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ MongoDB::RDF - Stores RDF-JSON documents in MongoDB.
my $mrdf = MongoDB::RDF->new(
database => MongoDB::Connection->new(host => 'localhost', port => 27017)->test_rdf
);

my $graph = $mrdf->default_graph;

my $r = MongoDB::RDF::Resource->new('http://example.org/0');
$r->dc_title('my title');
$graph->save($r);
Expand Down
4 changes: 2 additions & 2 deletions lib/MongoDB/RDF/Cursor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sub cursor { $_[0]->{cursor} }
=cut

sub next {
my $self = shift;
my $self = shift;
my $doc = $self->cursor->next;
return unless $doc;
return MongoDB::RDF::Resource->_new_from_document($doc);
Expand Down Expand Up @@ -104,7 +104,7 @@ TODO explain why it sort by the first value of the predicate.

=cut

sub sort {
sub sort {
my $self = shift;
my ($order) = @_;

Expand Down
6 changes: 3 additions & 3 deletions lib/MongoDB/RDF/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ sub _new {
my %args = @_;
my $self = bless {}, $class;
for (qw(name mrdf)) {
die "$_ required" unless $args{$_};
die "$_ required" unless $args{$_};
$self->{$_} = $args{$_};
}
# TODO maintain a global cache of the ensured indexes
# the cost of ensure_index may not be negligable
# the cost of ensure_index may not be negligable
$self->collection->ensure_index({ _subject => 1 }, { unique => 1 });
$self->ensure_index({ rdf_type => 1 });
return $self;
Expand All @@ -53,7 +53,7 @@ sub name { $_[0]->{name} }
=head2 $self->load( $uri )

Loads a resource from the graph.
If this resource has a registered rdf_type, then this resource
If this resource has a registered rdf_type, then this resource
will be reblessed to the corresponding class.
(See MongoDB::RDF::Resource->register_rdf_type)

Expand Down
2 changes: 1 addition & 1 deletion lib/MongoDB/RDF/Namespace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ sub resolve {
return $uri.$name;
}
}
return $local;
return $local;
}

=head2 register
Expand Down
32 changes: 16 additions & 16 deletions lib/MongoDB/RDF/Resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sub new {
$self->set_subject($subject);

if (my $type = $Class2rdf_type{$class}) {
$self->set(rdf_type => $type);
$self->set(rdf_type => $type);
}

$self->init if $self->can('init');
Expand All @@ -59,7 +59,7 @@ Set the subject, if $uri is undef a blank node URI is created.
=cut

sub set_subject {
my $self = shift;
my $self = shift;
my ($uri) = @_;
unless ($uri) {
my $oid = MongoDB::OID->new;
Expand All @@ -76,7 +76,7 @@ Returns the subject.
=cut

sub subject {
my $self = shift;
my $self = shift;
return $self->{document}{_subject};
}

Expand Down Expand Up @@ -128,11 +128,11 @@ sub properties {
# for this reason, if the property has only one element,
# don't create the array.
sub _property {
my $self = shift;
my $self = shift;
my ($uri, $values) = @_;

if ($values) {
die 'must be an arrayref' unless ref $values eq 'ARRAY';
die 'must be an arrayref' unless ref $values eq 'ARRAY';
if (@$values == 0) {
delete $self->{document}{$uri};
}
Expand All @@ -149,7 +149,7 @@ sub _property {

# object in the "subject predicate object" sense
sub _value2object {
my $self = shift;
my $self = shift;
my ($value) = @_;
if (looks_like_uri($value)) {
return { type => 'uri', value => canonical_uri($value) };
Expand All @@ -160,7 +160,7 @@ sub _value2object {
}

sub _object2value {
my $self = shift;
my $self = shift;
my ($object, $opts) = @_;
if (my $graph = $opts->{instanciate}) {
die '['.$self->mongodb_id.'] type is not uri, value: '.$object->{value}
Expand Down Expand Up @@ -190,7 +190,7 @@ Example:
=cut

sub get {
my $self = shift;
my $self = shift;
my ($predicate) = @_;
my $uri = fencode(resolve($predicate));
my @values = map {
Expand All @@ -204,7 +204,7 @@ sub get {
=cut

sub add {
my $self = shift;
my $self = shift;
my ($predicate, $value) = @_;
my $uri = fencode(resolve($predicate));
my $props = $self->_property($uri);
Expand All @@ -218,7 +218,7 @@ sub add {
=cut

sub del {
my $self = shift;
my $self = shift;
my ($predicate, $value) = @_;
my $uri = fencode(resolve($predicate));
my $props = $self->_property($uri);
Expand All @@ -237,7 +237,7 @@ or $self->set( $predicate ); to remove all the values.
=cut

sub set {
my $self = shift;
my $self = shift;
my $predicate = shift;
my $values = \@_;
my $uri = fencode(resolve($predicate));
Expand Down Expand Up @@ -284,11 +284,11 @@ Returns a RDF/JSON document. See <http://n2.talis.com/wiki/RDF_JSON_Specificatio
=cut

sub as_rdf_json {
my $self = shift;
my $self = shift;
my $obj = {
$self->subject => $self->properties
};
my $j = JSON::Any->new;
my $j = JSON::Any->new;
return $j->objToJson($obj);
}

Expand All @@ -297,8 +297,8 @@ sub as_rdf_json {
=cut

sub as_rdf_xml {
my $self = shift;
# TODO
my $self = shift;
# TODO
}

=head2 $self->as_ntriples
Expand Down Expand Up @@ -351,7 +351,7 @@ MongoDB::RDF::Resource can be subsclassed like this:
$graph->save($r);

...

my $r = $graph->load('http://myinstance');
# $r is a MyClass

Expand Down
8 changes: 4 additions & 4 deletions lib/MongoDB/RDF/Serializer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;

=head2 $class->dump( resource => ... )

or
or

$class->dump( graph => ... )
$class->dump( graph => ..., filename => ... )
Expand Down Expand Up @@ -38,7 +38,7 @@ sub dump {

}
else {
die "graph or resource required";
die "graph or resource required";
}

$fh->close if $fh;
Expand Down Expand Up @@ -66,8 +66,8 @@ sub serialize_resource { die 'to be overwritten' }

=head2 $class->load( graph => ..., filename => ... )

or
$class->load( graph => ... ); # read STDIN
or
$class->load( graph => ... ); # read STDIN

=cut

Expand Down
8 changes: 4 additions & 4 deletions lib/MongoDB/RDF/Serializer/NTriples.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Encode;

=head1 DESCRIPTION

NTriples serialization
NTriples serialization

=cut

Expand All @@ -32,7 +32,7 @@ sub _encode_literal {
$l =~ s/\r/\\r/g;
$l =~ s/\t/\\t/g;
$l =~ s/\"/\\"/g;
return $l;
return $l;
}

=head2 serialize_resource
Expand Down Expand Up @@ -60,7 +60,7 @@ sub _save_triplet {
my ($graph, $s, $p, $o) = @_;
my $resource = $graph->load($s) || MongoDB::RDF::Resource->new($s);
$resource->add($p => $o);
$graph->save($resource);
$graph->save($resource);
}

sub _clean_line {
Expand All @@ -72,7 +72,7 @@ sub _clean_line {
$line = Encode::decode_utf8($line);
$line =~ s/^\s+//;
$line =~ s/\s+$//;
return $line;
return $line;
}

sub _decode_literal {
Expand Down
6 changes: 3 additions & 3 deletions lib/MongoDB/RDF/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ sub looks_like_uri { # XXX we may want to not guess, and assume that the value

=head2 fencode

MongoDB doesn't allow '.' in the field names.
As the fields names here are URIs, we just encode the '.' to '%2E'
MongoDB doesn't allow '.' in the field names.
As the fields names here are URIs, we just encode the '.' to '%2E'

=cut

Expand Down Expand Up @@ -66,7 +66,7 @@ sub convert_query {
$convert_q = sub {
my ($query) = @_;
for my $key (keys %$query) {
# make this recursive in this case
# make this recursive in this case
if ($key eq '$or') {
$convert_q->($_) for @{ $query->{$key} };
}
Expand Down
6 changes: 3 additions & 3 deletions t/02-resource-query.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ isa_ok($graph, 'MongoDB::RDF::Graph');
my $cursor2 = $graph->find({ dc_title => 'my title' });
isa_ok($cursor2, 'MongoDB::RDF::Cursor');
cmp_ok($cursor2->count, '==', 1, 'one result');

# check that no index is used
$cursor = $graph->find({ dc_title => 'my title' });
ok $cursor->explain->{cursor} =~ /BasicCursor/, 'no index used';

# add an index on dc_title
$graph->ensure_index({ dc_title => 1}, { name => 'test_index', safe => 1 });
$cursor = $graph->find({ dc_title => 'my title' });
Expand Down Expand Up @@ -90,7 +90,7 @@ isa_ok($graph, 'MongoDB::RDF::Graph');
$cursor->reset;
@subset = $cursor->limit(2)->skip(3)->all;
cmp_ok(scalar(@subset), '==', 2, '2 results');

# or
my $query = { '$or' => [
{ dc_description => 1 },
Expand Down
2 changes: 1 addition & 1 deletion t/06-util.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ my %canonicals = (

for (keys %canonicals) {
my $expected = $canonicals{$_};
cmp_ok( canonical_uri($_), 'eq', $expected);
cmp_ok( canonical_uri($_), 'eq', $expected);
}