class Redland::MergedModel
A non-context-aware model used for the purpose of merging
Attributes
canonical[R]
global_rewrites[R]
Public Class Methods
new(master_model)
click to toggle source
Constructor - needs a master model to use
Calls superclass method
Redland::Model.new
# File lib/rdf/redland/model.rb, line 447 def initialize(master_model) @hooks = {} @count = {} @inverse_functional_properties = [] @identifiers = [] # list of inverse functional properties to smush @canonical = {} #rewrites to perform on local level @global_rewrites = {} #rewrites to apply globally @transactions = [] @master = master_model @pred_identifiers = {} super() end
Public Instance Methods
find_canonical(predlist)
click to toggle source
Locate predicates for smushing
# File lib/rdf/redland/model.rb, line 475 def find_canonical(predlist) predlist.each do |pred| identifier = {} self.find(nil,pred,nil) do |subj,pred,obj| master_id = self.find_subject_in_master(pred,obj) if not master_id if not identifier.has_key?(obj.to_s) identifier[obj.to_s] = subj elsif identifier[obj.to_s] != subj #already an identifying URI new_value = identifier[obj.to_s] if not @canonical.has_key?(subj.to_s) @canonical[subj.to_s] = new_value end end else # master_id if identifier.has_key?(obj.to_s) if identifier[obj.to_s] != master_id @canonical[subj.to_s] = master_id identifier[obj.to_s] = master_id end else # master_id not in identifier identifier[obj.to_s] = master_id if @canonical.has_key?(subj.to_s) if @canonical[subj.to_s] != master_id @global_rewrites[master_id] = @canonical[subj.to_s] end else if subj != master_id @canonical[subj.to_s] = master_id end end end end end # self.find @pred_identifiers[pred] = identifier end #predlist.each end
find_subject_in_master(pred,obj)
click to toggle source
rewrite(context=nil)
click to toggle source
actually do the smush
# File lib/rdf/redland/model.rb, line 514 def rewrite(context=nil) self.triples() do |sub,pred,obj| sub = @canonical[sub.to_s] if @canonical.key?(sub.to_s) obj = @canonical[obj.to_s] if @canonical.key?(obj.to_s) @master.add(sub,pred,obj,context) end end
smush(predlist)
click to toggle source
Effectively removes the listes Predicates from the Model by replacing all occurrences with a blank node (?? confirm)
# File lib/rdf/redland/model.rb, line 469 def smush(predlist) self.find_canonical(predlist) self.rewrite() end