Sha256: 4c95ff27699e93a99c102c47572cc25f85fb04f1634d6e6fd68447e1c6ac12bf

Contents?: true

Size: 1.8 KB

Versions: 21

Compression:

Stored size: 1.8 KB

Contents

# encoding: UTF-8

# Copyright 2011 innoQ Deutschland GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Iqvoc
  # 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.
  class RdfHelper

    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#" }

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

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

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

    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

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

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
iqvoc-3.2.11 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.10 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.9 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.8 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.6 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.5 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.4 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.7 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.3 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.2 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.1 lib/iqvoc/rdf_helper.rb
iqvoc-3.5.0 lib/iqvoc/rdf_helper.rb
iqvoc-3.4.0 lib/iqvoc/rdf_helper.rb
iqvoc-3.3.4 lib/iqvoc/rdf_helper.rb
iqvoc-3.3.3 lib/iqvoc/rdf_helper.rb
iqvoc-3.3.2 lib/iqvoc/rdf_helper.rb
iqvoc-3.3.1 lib/iqvoc/rdf_helper.rb
iqvoc-3.3.0 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.6 lib/iqvoc/rdf_helper.rb
iqvoc-3.2.5 lib/iqvoc/rdf_helper.rb