Class: Iqvoc::SkosImporter

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

Constant Summary collapse

FIRST_LEVEL_OBJECT_CLASSES =
[Iqvoc::Concept.base_class, Iqvoc::Collection.base_class]
SECOND_LEVEL_OBJECT_CLASSES =
Iqvoc::Concept.labeling_classes.keys +
Iqvoc::Concept.note_classes +
Iqvoc::Concept.relation_classes +
Iqvoc::Concept.match_classes +
Iqvoc::Collection.member_classes

Instance Method Summary collapse

Constructor Details

#initialize(file, default_namespace_url, logger = Rails.logger) ⇒ SkosImporter

Returns a new instance of SkosImporter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/iqvoc/skos_importer.rb', line 11

def initialize(file, default_namespace_url, logger = Rails.logger)

  @logger = logger

  unless file.is_a?(File) || file.is_a?(Array)
    raise "Iqvoc::SkosImporter#import: Parameter 'file' should be a File or an Array."
  end

  # Some general Namespaces to support in any case
  @prefixes = {
    "http://www.w3.org/2004/02/skos/core#" => "skos:",
    "http://www.w3.org/2008/05/skos#" => "skos:",
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#" => "rdf:",
    default_namespace_url => ":"
  }
  # Add the namespaces specified in the Iqvoc config
  Iqvoc.rdf_namespaces.each do |pref, uri|
    @prefixes[uri] = "#{pref.to_s}:"
  end

  @seen_first_level_objects = {}
  @blank_nodes = {}

  @existing_origins = {} # To prevent the creation of first level objects we already have
  FIRST_LEVEL_OBJECT_CLASSES.each do |klass|
    klass.select("origin").all.each do |thing|
      @existing_origins[thing.origin] = klass
    end
  end

  import(file)
end