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, trim_mode: '-')
  @prefix_ttl_erb = ERB.new(ERB_PREFIXES_TTL, trim_mode: '-')
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
# File 'lib/tao_rdfizer/tao_rdfizer.rb', line 21

def rdfize(annotations_col, options = nil)
  options ||= {}
  only_prefixes = options[:only_prefixes] == true
  with_prefixes = options[:with_prefixes] != true

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

  # namespaces
  namespaces = get_namespaces(annotations_col.first)

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

  return prefixes_ttl if only_prefixes

  annotations_ttl = get_annotations_ttl(annotations_col, namespaces)
  with_prefixes ? prefixes_ttl + annotations_ttl : annotations_ttl
end