Skip to content

Commit

Permalink
Merge branch 'rdf-trine-0.120'
Browse files Browse the repository at this point in the history
  • Loading branch information
kasei committed Apr 20, 2010
2 parents 6ce0c95 + 082e38d commit c1190fb
Show file tree
Hide file tree
Showing 66 changed files with 620 additions and 201 deletions.
6 changes: 3 additions & 3 deletions RDF-Query/bin/graph-bgp.pl
Expand Up @@ -6,6 +6,7 @@

use lib qw(. t lib .. ../t ../lib);
use RDF::Query;
use RDF::Query::Util;

unless (@ARGV) {
print <<"END";
Expand All @@ -17,9 +18,6 @@ END
exit;
}

my $qfile = shift;
my $sparql = do { open(my $fh, '<', $qfile) or die $!; local($/) = undef; <$fh> };

use GraphViz;
use List::Util qw(first);
use Time::HiRes qw(tv_interval gettimeofday);
Expand Down Expand Up @@ -48,6 +46,8 @@ END
foreach my $n (@nodes) {
if ($n->isa('RDF::Query::Node::Variable')) {
push( @{ $vars{ $n->name } }, $i );
} elsif ($n->isa('RDF::Query::Node::Blank')) {
push( @{ $vars{ '_:' . $n->blank_identifier } }, $i );
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions RDF-Query/examples/queries/sparql-bgp-people-knows.rq
@@ -1,7 +1,8 @@
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?knows
WHERE {
[] a foaf:Person ;
?p a foaf:Person ;
foaf:name ?name ;
foaf:knows [ foaf:name ?knows ] .
foaf:knows ?q .
?q foaf:name ?knows .
}
22 changes: 20 additions & 2 deletions RDF-Query/lib/RDF/Query/Algebra/Aggregate.pm
Expand Up @@ -40,6 +40,8 @@ BEGIN {

=item C<new ( $pattern, \@groupby, $alias => [$op => $col] )>
=item C<new ( $pattern, \@groupby, expressions => [ $alias => [$op => $col] ], having => \@constraint )>
Returns a new Aggregate structure. Groups by the named bindings in C<< @groupby >>,
and returns new bindings for the named C<< $alias >> for the operation C<< $op >>
on column C<< $col >>.
Expand Down Expand Up @@ -74,7 +76,12 @@ will produce a clone of this algebra pattern.
sub construct_args {
my $self = shift;
my @ops = @{ $self->[2] };
return ($self->pattern, [ $self->groupby ], \@ops);
my %args = ( expressions => \@ops );
my @having = $self->having;
if (scalar(@having)) {
$args{ having } = \@having;
}
return ($self->pattern, [ $self->groupby ], \%args);
}

=item C<< pattern >>
Expand All @@ -90,7 +97,7 @@ sub pattern {

=item C<< groupby >>
Returns the aggregates GROUP BY binding names.
Returns the aggregate's GROUP BY binding names.
=cut

Expand All @@ -99,6 +106,17 @@ sub groupby {
return @{ $self->[1] };
}

=item C<< having >>
Returns the aggregate's HAVING clause.
=cut

sub having {
my $self = shift;
return @{ $self->[3] };
}

=item C<< ops >>
Returns a list of tuples as ARRAY refs containing C<< $alias, $op, $col >>.
Expand Down
9 changes: 9 additions & 0 deletions RDF-Query/lib/RDF/Query/Node/Blank.pm
Expand Up @@ -59,6 +59,15 @@ sub _cmp {
return $cmp;
}

sub new {
my $class = shift;
my $name = shift;
unless (defined($name)) {
$name = 'r' . time() . 'r' . $RDF::Trine::Node::Blank::COUNTER++;
}
return $class->_new( $name );
}

=item C<< as_sparql >>
Returns the SPARQL string for this node.
Expand Down
3 changes: 2 additions & 1 deletion RDF-Query/lib/RDF/Query/Plan.pm
Expand Up @@ -370,7 +370,8 @@ sub generate_plans {
my @base = $self->generate_plans( $algebra->pattern, $context, %args );
my @groups = $algebra->groupby;
my @ops = $algebra->ops;
my @plans = map { RDF::Query::Plan::Aggregate->new( $_, \@groups, @ops ) } @base;
my @having = $algebra->having;
my @plans = map { RDF::Query::Plan::Aggregate->new( $_, \@groups, expressions => \@ops, having => \@having ) } @base;
push(@return_plans, @plans);
} elsif ($type eq 'Construct') {
my $triples = $algebra->triples;
Expand Down
19 changes: 16 additions & 3 deletions RDF-Query/lib/RDF/Query/Plan/Aggregate.pm
Expand Up @@ -33,16 +33,18 @@ BEGIN {

######################################################################

=item C<< new ( $pattern, \@group_by, [ $alias, $op, $attribute ], ... ) >>
=item C<< new ( $pattern, \@group_by, expressions => [ [ $alias, $op, $attribute ], ... ], having => \@constraings ) >>
=cut

sub new {
my $class = shift;
my $plan = shift;
my $groupby = shift;
my @ops = @_;
my $self = $class->SUPER::new( $plan, $groupby, \@ops );
my %args = @_;
my @ops = @{ $args{ 'expressions' } || [] };
my @having = @{ $args{ 'having' } || [] };
my $self = $class->SUPER::new( $plan, $groupby, \@ops, \@having );
$self->[0]{referenced_variables} = [ RDF::Query::_uniq($plan->referenced_variables, map { $_->name } @$groupby) ];
return $self;
}
Expand Down Expand Up @@ -382,6 +384,17 @@ sub groupby {
return @{ $self->[2] || [] };
}

=item C<< having >>
Returns the aggregate's HAVING clause.
=cut

sub having {
my $self = shift;
return @{ $self->[4] || [] };
}

=item C<< plan_node_name >>
Returns the string name of this plan node, suitable for use in serialization.
Expand Down
2 changes: 1 addition & 1 deletion RDF-Query/lib/RDF/Query/Util.pm
Expand Up @@ -67,7 +67,7 @@ following the final argument parsed by C<< &cli_parse_args >>.

sub cli_make_query {
my %args = cli_parse_args();
my $class = delete $args{ class };
my $class = delete $args{ class } || 'RDF::Query';
my $sparql = delete $args{ query };
my $l = Log::Log4perl->get_logger("rdf.query.util");
$l->debug("creating sparql query with class $class");
Expand Down
36 changes: 33 additions & 3 deletions RDF-Query/t/aggregate.t
Expand Up @@ -377,14 +377,17 @@ END
# @prefix : <http://books.example/> .
#
# :org1 :affiliates :auth1, :auth2 .
# :org2 :affiliates :auth3 .
#
# :auth1 :writesBook :book1, :book2 .
# :auth2 :writesBook :book3 .
# :auth3 :writesBook :book4 .
#
# :book1 :price 9 .
# :book2 :price 5 .
# :auth2 :writesBook :book3 .
# :book3 :price 7 .
# :org2 :affiliates :auth3 .
# :auth3 :writesBook :book4 .
# :book4 :price 7 .
#
# END
# my $parser = RDF::Trine::Parser->new('turtle');
# $parser->parse_into_model( 'http://base/', $data, $model );
Expand All @@ -399,6 +402,33 @@ END
# GROUP BY ?org
# HAVING (SUM(?lprice) > 10)
# END
#
# ##############################
# # GROUPS:
# # org auth book lprice
# # ----------------------------
# # org1 auth1 book1 9
# # org1 auth1 book2 5
# # org1 auth2 book3 7
# # ----------------------------
# # org2 auth3 book4 7
# # ----------------------------
# ##############################
# # AGGREGATES:
# # org SUM(lprice)
# # ----------------------------
# # org1 21
# # ----------------------------
# # org2 7
# # ----------------------------
# ##############################
# # CONSTRAINTS:
# # org SUM(lprice)
# # ----------------------------
# # org1 21
# # ----------------------------
# ##############################
#
# warn RDF::Query->error unless ($query);
# my $iter = $query->execute( $model );
# while (my $r = $iter->next) {
Expand Down
18 changes: 18 additions & 0 deletions RDF-Trine/Changes.ttl
Expand Up @@ -10,6 +10,24 @@
dcterms:references <http://kasei.us/code/rdf-trine/#project> .


<http://kasei.us/code/files/RDF-Trine-0.120.tar.gz>
dcterms:isVersionOf <http://kasei.us/code/rdf-trine/#project> ;
dcterms:replaces <http://kasei.us/code/files/RDF-Trine-0.119.tar.gz> ;

doap:Version [
doap:revision "0.120" ;
doap:created "2010-04-20" ;
];
asc:changes [
asc:addition "Added optional value canonicalization on parsing (xsd integer, decimal, and boolean)." ;
asc:update "RDF/XML parser now attempts to canonicalize XMLLiterals (doesn't yet canonicalize all XMLLiterals that it shold)." ;
asc:update "Added RDF::Trine::Node::Blank::_new constructor that doesn't validate bnode name for N-Triples conformance." ;
asc:update "Performance improvements to RDF::Trine::Node::_unicode_escape." ;
asc:update "Updated Turtle parser to throw error on undeclared namespace prefixes." ;
asc:update "Updated Turtle serializer to produce QName literal datatypes." ;
] .


<http://kasei.us/code/files/RDF-Trine-0.119.tar.gz>
dcterms:isVersionOf <http://kasei.us/code/rdf-trine/#project> ;
dcterms:replaces <http://kasei.us/code/files/RDF-Trine-0.118.tar.gz> ;
Expand Down
2 changes: 1 addition & 1 deletion RDF-Trine/META.yml
Expand Up @@ -3,7 +3,7 @@ meta-spec:
version: 1.3
url: http://module-build.sourceforge.net/META-spec-v1.3.html
name: RDF-Trine
version: 0.119
version: 0.120
abstract: An RDF framework, providing a triplestore, parsers, serializers, and common classes for nodes, triples, quads, etc.
author:
- Gregory Todd Williams <gwilliams@cpan.org>
Expand Down
1 change: 1 addition & 0 deletions RDF-Trine/Makefile.PL
Expand Up @@ -43,6 +43,7 @@ WriteMakefile(
'XML::CommonNS' => 0.04,
'XML::Namespace' => 0,
'XML::SAX' => 0,
'XML::LibXML' => 0,
'XML::LibXML::SAX' => 1.66, # we shouldn't need this, but XML::SAX::PurePerl seems to have some major bugs with unicode in some of the RDF/XML syntax examples
},
);
10 changes: 10 additions & 0 deletions RDF-Trine/README
Expand Up @@ -42,6 +42,7 @@ REQUIREMENTS
* XML::CommonNS
* XML::Namespace
* XML::SAX
* XML::LibXML
* XML::LibXML::SAX


Expand All @@ -64,6 +65,15 @@ INSTALLATION

VERSION HISTORY

Version 0.120 (2010-04-20)

* Added optional value canonicalization on parsing (xsd integer, decimal, and boolean).
* RDF/XML parser now attempts to canonicalize XMLLiterals (doesn't yet canonicalize all XMLLiterals that it shold).
* Added RDF::Trine::Node::Blank::_new constructor that doesn't validate bnode name for N-Triples conformance.
* Performance improvements to RDF::Trine::Node::_unicode_escape.
* Updated Turtle parser to throw error on undeclared namespace prefixes.
* Updated Turtle serializer to produce QName literal datatypes.

Version 0.119 (2010-04-15)

* Fixed bug in NTriples parser handling of language literals (reported by tobyink).
Expand Down

0 comments on commit c1190fb

Please sign in to comment.