Class: Iqvoc::RdfHelper

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

Overview

TODO: The whole class should move to umt because it highly proprietary (and also has the wrong name because it only deals with “turtle”). TODO: The term “Helper” is misleading.

Constant Summary collapse

LITERAL_REGEXP =
/"(.*)"@([a-zA-Z]{2})/
NSMAP =
{
'rdf'  => "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
'skos' => "http://www.w3.org/2004/02/skos/core#",
'owl'  => "http://www.w3.org/2002/07/owl#",
'rdfs' => "http://www.w3.org/2000/01/rdf-schema#" }

Class Method Summary collapse

Class Method Details

.extract_id(uri) ⇒ Object



31
32
33
34
# File 'lib/iqvoc/rdf_helper.rb', line 31

def self.extract_id(uri)
  uri =~ /([^\/]+)\/{0,1}$/
  $1
end

.is_literal_form?(str) ⇒ Boolean



36
37
38
# File 'lib/iqvoc/rdf_helper.rb', line 36

def self.is_literal_form?(str)
  str.match LITERAL_REGEXP
end

.quote_turtle_literal(val) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/iqvoc/rdf_helper.rb', line 40

def self.quote_turtle_literal(val)
  if val.to_s.match(/^<.*>$/)
    val
  else
    "\"#{val}\""
  end
end

.split_literal(str) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/iqvoc/rdf_helper.rb', line 48

def self.split_literal(str)
  elements = str.scan(LITERAL_REGEXP).first
  @split_literal = {
    :value    => elements[0].gsub(/\\"/, '"'),
    :language => elements[1]
  }
  ::Rails.logger.debug "@split_literal => #{@split_literal}"
  @split_literal
end

.to_xml_attribute_arrayObject



58
59
60
61
62
63
64
# File 'lib/iqvoc/rdf_helper.rb', line 58

def self.to_xml_attribute_array
  res = {}
  NSMAP.each do |k,v|
    res["xmlns:#{k}"] = v
  end
  res
end