Redland RDF Application Framework - Ruby RDoc - Class: Redland::MergedModel

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

find_canonical find_subject_in_master new rewrite smush

### Attributes

canonical | [R] |
global_rewrites | [R] |

### Public Class methods

new(master_model)

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

find_canonical(predlist)

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

find_subject_in_master(pred,obj)

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

rewrite(context=nil)

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

smush(predlist)

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