Class: Graffiti::RdfConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/graffiti/rdf_config.rb

Overview

Configuration of relational RDF storage (see examples)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ RdfConfig

Returns a new instance of RdfConfig.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/graffiti/rdf_config.rb', line 22

def initialize(config)
  @ns = config['ns']

  @map = {}

  config['map'].each_pair do |p, m|
    table, field = m.to_a.first
    p = ns_expand(p)
    @map[p] = RdfPropertyMap.new(p, table, field)
  end

  if config['subproperties'].kind_of? Hash
    config['subproperties'].each_pair do |p, subproperties|
      p = ns_expand(p)
      map = @map[p] or raise RuntimeError,
        "Incorrect RDF storage configuration: superproperty #{p} must be mapped"
      map.superproperty = true

      qualifier = RdfPropertyMap.qualifier_property(p)
      @map[qualifier] = RdfPropertyMap.new(
        qualifier, map.table, RdfPropertyMap.qualifier_field(map.field))

      subproperties.each do |subp|
        subp = ns_expand(subp)
        @map[subp] = RdfPropertyMap.new(subp, map.table, map.field)
        @map[subp].subproperty_of = p
      end
    end
  end

  if config['transitive_closure'].kind_of? Hash
    config['transitive_closure'].each_pair do |p, table|
      @map[ ns_expand(p) ].transitive_closure = table

      if config['subproperties'].kind_of?(Hash) and config['subproperties'][p]
        config['subproperties'][p].each do |subp|
          @map[ ns_expand(subp) ].transitive_closure = table
        end
      end
    end
  end
end

Instance Attribute Details

#mapObject (readonly)

map internal property names with expanded namespaces to RdfPropertyMap objects



71
72
73
# File 'lib/graffiti/rdf_config.rb', line 71

def map
  @map
end

#nsObject (readonly)

hash of namespaces



66
67
68
# File 'lib/graffiti/rdf_config.rb', line 66

def ns
  @ns
end

Instance Method Details

#ns_expand(p) ⇒ Object



73
74
75
# File 'lib/graffiti/rdf_config.rb', line 73

def ns_expand(p)
  p and p.sub(/\A(\S+?)::/) { @ns[$1] }
end