From d0fdf366f4b0354b27058a5d23b6082bd01f464d Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 1 Jun 2017 16:17:30 +1000 Subject: [PATCH] Bug 18713 - Add support for named graphs and rfds:seeAlso to Koha::RDF This patch adds methods to Koha::RDF that creates or deletes a named graph by removing/adding RDF quads from/to a triplestore. This patch also can create a rdfs:seeAlso relationship between two RDF entities. --- Koha/RDF.pm | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Koha/RDF.pm b/Koha/RDF.pm index def6dfddcb..c9a635e7f1 100644 --- a/Koha/RDF.pm +++ b/Koha/RDF.pm @@ -47,4 +47,47 @@ sub mint_uri { return $new_uri; } +sub DelNamedGraph { + my ($self, $args) = @_; + my $model = $args->{model}; + my $context = $args->{context}; + if ($model && $context){ + #Create a statement including variables to match everything with a given context (ie within a named graph), so that we can delete all these statements + my $s = RDF::Trine::Node::Variable->new("s"); + my $p = RDF::Trine::Node::Variable->new("p"); + my $o = RDF::Trine::Node::Variable->new("o"); + my $quad = RDF::Trine::Statement::Quad->new($s, $p, $o, $context); + + #Perform operations + $model->remove_statements($quad); + } +} + +sub AddNamedGraph { + my ($self, $args) = @_; + my $model = $args->{model}; + my $context = $args->{context}; + my $iterator = $args->{iterator}; + + while (my $st = $iterator->next){ + #Set the context (in order to populate the named graph) + $st->context($context); + + $model->add_statement($st); + #NOTE: This method returns undef on success. + } +} + +sub AddSeeAlso { + my ($self, $args) = @_; + my $model = $args->{model}; + my $subject = $args->{subject}; + my $predicate = RDF::Trine::Node::Resource->new("http://www.w3.org/2000/01/rdf-schema#seeAlso"); + my $object = $args->{object}; + if ($model && $subject && $predicate && $object){ + my $statement = RDF::Trine::Statement->new($subject,$predicate,$object); + $model->add_statement($statement); + } +} + 1; -- 2.12.0