module BioRdf::Turtle
Public Class Methods
identifier(id)
click to toggle source
# 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)
click to toggle source
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.
# 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)
click to toggle source
# File lib/bio/writers/rdf.rb, line 42 def Turtle::stringify_literal(literal) RDF::stringify_literal(literal) end