Class: Pho::FileManagement::BNodeRewritingHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pho/upload.rb

Overview

Remove bnodes from the input data by assigning URIs to them

This implementation generates a simple hexdigest based on the node id and uses that to construct a uri based on a base uri provided in the constructor

Instance Method Summary collapse

Constructor Details

#initialize(base) ⇒ BNodeRewritingHandler

base

base uri for URIs generated for blank nodes



19
20
21
# File 'lib/pho/upload.rb', line 19

def initialize(base)
  @base = base
end

Instance Method Details

#assign_uri(node) ⇒ Object

FIXME semantics for this is wrong if nodeIds are reused across datasets



40
41
42
# File 'lib/pho/upload.rb', line 40

def assign_uri(node)
  return "#{@base}/#{Digest::MD5.hexdigest( node.id )}#self"
end

#handle(statement) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/pho/upload.rb', line 23

def handle(statement)
  if !statement.has_blank_nodes?
    return statement
  end
  subject = statement.subject
  if subject.anonymous?
    subject = RDF::URI.new( assign_uri(subject) )
  end
  object = statement.object
  if object.anonymous?
    object = RDF::URI.new( assign_uri(object) )
  end
  return RDF::Statement.new(subject, statement.predicate, object)
end