Go to Redland Home - Language Bindings Home - Ruby API Home
Class Redland::MergedModel
In: rdf/redland/model.rb
Parent: Model

A non-context-aware model used for the purpose of merging

Methods

Attributes

canonical  [R] 
global_rewrites  [R] 

Public Class methods

Constructor - needs a master model to use

[Source]

# File 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

Locate predicates for smushing

[Source]

# File 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

Return one Node in the Model matching (?,predicate,target) The source and predicate can be a Node or Uri

[Source]

# File rdf/redland/model.rb, line 463
    def find_subject_in_master(pred,obj)
      return @master.subject(pred,obj)
    end

actually do the smush

[Source]

# File 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

Effectively removes the listes Predicates from the Model by replacing all occurrences with a blank node (?? confirm)

[Source]

# File rdf/redland/model.rb, line 469
    def smush(predlist)
      self.find_canonical(predlist)
      self.rewrite()
    end

Go to Redland Home - Language Bindings Home - Ruby API Home

(C) Copyright 2004-2011 Dave Beckett, (C) Copyright 2004-2005 University of Bristol