Class: SkosImporter
- Inherits:
-
Object
- Object
- SkosImporter
- Defined in:
- app/aides/skos_importer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object, default_namespace_url, logger = Rails.logger, publish = true, verbose = false) ⇒ SkosImporter
constructor
A new instance of SkosImporter.
- #run ⇒ Object
Constructor Details
#initialize(object, default_namespace_url, logger = Rails.logger, publish = true, verbose = false) ⇒ SkosImporter
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/aides/skos_importer.rb', line 20 def initialize(object, default_namespace_url, logger = Rails.logger, publish = true, verbose = false) @file = case object when File File.open(object) when Array object else open(object) end @default_namespace_url = default_namespace_url @publish = publish @verbose = verbose @logger = logger unless @file.is_a?(File) || @file.is_a?(Array) raise "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 = {} # Concept cache (don't load any concept twice from db) # Assign the default concept scheme singleton instance as a seen first level object upfront # in order to handle a missing scheme definition in ntriple data @seen_first_level_objects[Iqvoc::Concept.root_class.instance.origin] = Iqvoc::Concept.root_class @new_subjects = {} # Concepts, collections, labels etc. to be published later # Triples the importer doesn't understand immediately. Example: # # :a skos:prefLabel "foo". # => What is :a? Remember this and try again later # .... # :a rdf:type skos:Concept # => Now I know :a, good I remembered it's prefLabel... @unknown_second_level_triples = Set.new # Hash of arrays of arrays: { "_:n123" => [["pred1", "obj1"], ["pred2", "obj2"]] } @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').load.each do |thing| @existing_origins[thing.origin] = klass end end end |
Class Method Details
.prepend_first_level_object_classes(args) ⇒ Object
16 17 18 |
# File 'app/aides/skos_importer.rb', line 16 def self.prepend_first_level_object_classes(args) self.first_level_object_classes.unshift(*args) end |
Instance Method Details
#run ⇒ Object
77 78 79 80 81 |
# File 'app/aides/skos_importer.rb', line 77 def run print_known_namespaces print_known_import_classes import @file end |