lib/iqvoc/skos_importer.rb in iqvoc-4.0.9 vs lib/iqvoc/skos_importer.rb in iqvoc-4.1.0

- old
+ new

@@ -6,10 +6,12 @@ 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::Concept.notation_classes + + [Iqvoc::Concept.root_class] + [Iqvoc::Collection.member_class] def initialize(file, default_namespace_url, logger = Rails.logger) @logger = logger @@ -28,18 +30,23 @@ 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.instance + @new_subjects = [] # Concepts 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 remebered it's prefLabel... - @unknown_second_level_tripes = [] + @unknown_second_level_triples = [] # 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 @@ -73,11 +80,11 @@ import_first_level_objects(first_level_types, *extract_triple(line)) || import_second_level_objects(second_level_types, false, *extract_triple(line)) end @logger.debug("Computing 'forward' defined triples...") - @unknown_second_level_tripes.each do |s, p, o| + @unknown_second_level_triples.each do |s, p, o| import_second_level_objects(second_level_types, true, s, p, o) end first_import_step_done = Time.now @logger.debug("Basic import done (took #{(first_import_step_done - start).to_i} seconds).") @@ -143,24 +150,24 @@ subject = load_first_level_object(subject_origin) unless subject if final @logger.warn "Iqvoc::SkosImporter: Couldn't find Subject with origin '#{subject_origin}. Skipping entry '#{subject} #{predicate} #{object}.'" else - @unknown_second_level_tripes << initial_triple + @unknown_second_level_triples << initial_triple end return false end # Load the data object for the object string if this is representing a thing in our domain if (object =~ /^:(.*)$/ && types[predicate]) object_origin = $1 object = load_first_level_object(object_origin) unless object if final - @logger.warn "Iqvoc::SkosImporter: Couldn't find Object with origin '#{object_origin}. Skipping entry ':#{subject_origin} #{predicate} #{object}.'" + @logger.warn "Iqvoc::SkosImporter: Couldn't find Object with origin '#{object_origin}'. Skipping entry ':#{subject_origin} #{predicate} #{object}.'" else - @unknown_second_level_tripes << initial_triple + @unknown_second_level_triples << initial_triple end return false end end @@ -172,11 +179,11 @@ # if blank_node?(object) if final object = @blank_nodes[object] else - @unknown_second_level_tripes << initial_triple + @unknown_second_level_triples << initial_triple return false end end types[predicate].build_from_rdf(subject, predicate, object) @@ -203,10 +210,10 @@ triple = line.split(' ', 3) # The first one are uris the last can be a literal too triple.each do |e| # Do some fun with the uris and literals @prefixes.keys.each do |uri_prefix| # Use prefixes instead of full uris - e.gsub! /<#{uri_prefix}([^>]*)>/ do |matches| + e.gsub! /^<#{uri_prefix}([^>]*)>/ do |matches| @prefixes[uri_prefix] + $1.gsub(".", "_") end end e.squish! e.gsub!(/^:(.*)$/) do