Module: BioRdf::Turtle

Defined in:
lib/bio/writers/rdf.rb

Class Method Summary collapse

Class Method Details

.identifier(id) ⇒ Object



46
47
48
# File 'lib/bio/writers/rdf.rb', line 46

def Turtle::identifier(id)
  raise "Illegal identifier #{id}" if id != Turtle::mangle_identifier(id)
end

.mangle_identifier(s) ⇒ Object

Replace letters/symbols that are not allowed in a Turtle identifier (short hand URI). This should be the definite mangler and replace the ones in bioruby-table and bio-exominer. Manglers are useful when using data from other sources and trying to transform them into simple RDF identifiers.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bio/writers/rdf.rb', line 56

def Turtle::mangle_identifier(s)
  id = s.strip.gsub(/[^[:print:]]/, '').gsub(/[#)(,]/,"").gsub(/[%]/,"perc").gsub(/(\s|\.|\$|\/|\\|\>)+/,"_")
  id = id.gsub(/\[|\]/,'')
  # id = URI::escape(id)
  id = id.gsub(/\|/,'_')
  id = id.gsub(/\-|:/,'_')
  if id != s 
    # Don't want Bio depency in templates!
    # logger = Bio::Log::LoggerPlus.new 'bio-rdf'
    # logger.warn "\nWARNING: Changed identifier <#{s}> to <#{id}>"
    # $stderr.print "\nWARNING: Changed identifier <#{s}> to <#{id}>"
  end
  if not RDF::valid_uri?(id)
    raise "Invalid URI after mangling <#{s}> to <#{id}>!"
  end
  valid_id = if id =~ /^\d/
               'r' + id
             else
               id
             end
  valid_id  # we certainly hope so!
end

.stringify_literal(literal) ⇒ Object



42
43
44
# File 'lib/bio/writers/rdf.rb', line 42

def Turtle::stringify_literal(literal)
  RDF::stringify_literal(literal)
end