Redland RDF Language Bindings - Ruby RDoc - Class: Redland::MergedModel

### Home Classes Methods

### In Files

- rdf/redland/model.rb

### Parent

Redland::Model

### Methods

- ::new
- #find_canonical
- #find_subject_in_master
- #rewrite
- #smush

### Files

- Makefile
- Makefile
- Makefile
- Makefile

### Class/Module Index

Quicksearch

- Redland
- Redland::BNode
- Redland::ContextParser
- Redland::FileStore
- Redland::HashOpen
- Redland::HashStore
- Redland::Literal
- Redland::MemoryStore
- Redland::MergedModel
- Redland::Model
- Redland::Namespace
- Redland::Node
- Redland::NodeIterator
- Redland::NodeTypeError
- Redland::OWL
- Redland::Parser
- Redland::Query
- Redland::QueryResults
- Redland::RDFS
- Redland::RedlandError
- Redland::Resource
- Redland::Serializer
- Redland::Statement
- Redland::Stream
- Redland::TripleStore
- Redland::Uri
- Redland::Util
- Redland::World
- DC
- FOAF

No matching classes.

# 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

    # 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) click to toggle source

Locate predicates for smushing

    # 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) click to toggle source

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

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

rewrite(context=nil) click to toggle source

actually do the smush

    # 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) click to toggle source

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

    # 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-2013 Dave Beckett, (C) Copyright 2004-2005 University of Bristol