Skip to content

Instantly share code, notes, and snippets.

@kasei
Created September 7, 2012 16:29
Show Gist options
  • Save kasei/3667578 to your computer and use it in GitHub Desktop.
Save kasei/3667578 to your computer and use it in GitHub Desktop.
RDF::Query rewriting ideas
$query->rewrite_algebra( postfix => sub {
my $visitor = shift;
my $algebra = shift;
if ($algebra->isa('RDF::Query::Algebra::BasicGraphPattern'))
return $visitor->stop; # stop traversal
if ($algebra->isa('RDF::Query::Algebra::Filter')) {
my $expr = $algebra->expr;
if ($expr->isa('RDF::Query::Expression::Function')) {
if ($expr->uri eq 'sparql:regex') {
# replace the algebra with a new one that's more efficient...
return $new_algebra;
}
}
}
return;
} );
# Maybe there are better (DSL-like) ways to write the algebra pattern to match?
if ($algebra->matches('FILTER/FUNCTION[sparql:regex]')) { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment