Class: TAO::RDFizer

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

Instance Method Summary collapse

Constructor Details

#initialize(mode = nil) ⇒ RDFizer

if mode == :spans then produces span descriptions if mode == :annotations then produces annotation descriptions if mode == nil then produces both



10
11
12
13
14
15
16
17
18
19
# File 'lib/tao_rdfizer/tao_rdfizer.rb', line 10

def initialize(mode = nil)
  @mode = mode
  template = if !mode.nil? && mode == :spans
    ERB_SPANS_TTL
  else
    ERB_ANNOTATIONS_TTL
  end
  @tao_ttl_erb = ERB.new(template, nil, '-')
  @prefix_ttl_erb = ERB.new(ERB_PREFIXES_TTL, nil, '-')
end

Instance Method Details

#rdfize(annotations_col, options = nil) ⇒ Object



21
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
# File 'lib/tao_rdfizer/tao_rdfizer.rb', line 21

def rdfize(annotations_col, options = nil)
  options ||= {}
  only_prefixes = options.has_key?(:only_prefixes) ? options[:only_prefixes] == true : false
  with_prefixes = options.has_key?(:with_prefixes) ? options[:with_prefixes] == true : true

  # check the format
  annotations_col.each do |annotations|
    raise "'target' is missing" unless annotations.has_key? :target
  end

  # namespaces
  namespaces = {}

  anns = annotations_col.first
  anns[:namespaces].each {|n| namespaces[n[:prefix]] = n[:uri]} unless anns[:namespaces].nil?

  prefixes_ttl = @prefix_ttl_erb.result_with_hash(namespaces:namespaces) if only_prefixes || with_prefixes

  if only_prefixes
    prefixes_ttl
  else
    annotations_ttl = get_annotations_ttl(annotations_col, namespaces)
    if with_prefixes
      prefixes_ttl + annotations_ttl
    else
      annotations_ttl
    end
  end
end