Class: TaliaCore::RdfImport

Inherits:
Object show all
Defined in:
lib/talia_core/rdf_import.rb

Overview

Import RDF data directly into the triple store. This is called to import onotologies and other RDF data.

Class Method Summary collapse

Class Method Details

.clear_file_contextsObject

Clear the currently registered ontologies



54
55
56
57
58
59
60
61
# File 'lib/talia_core/rdf_import.rb', line 54

def clear_file_contexts
  # Remove all registered contexts
  to_clear = ActiveRDF::Query.new(N::URI).select(:context).distinct.where(N::TALIA.rdf_context_space, N::TALIA.rdf_file_context, :context).execute
  to_clear.each do |context|
    adapter.clear(context) 
  end
  ActiveRDF::FederationManager.delete(N::TALIA.rdf_context_space, N::TALIA.rdf_file_context, nil)
end

.import(rdf_syntax, files, context = nil) ⇒ Object

Import the given files. The rdf_syntax may be nil. If “auto” is given, it will use a default value for each imported file

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/talia_core/rdf_import.rb', line 14

def import(rdf_syntax, files, context=nil)
  puts "Importing #{files.size} files into the triple store."
  
  raise(ArgumentError, "Cannot use context, adapter doesn't support it.") if(context && !adapter.contexts?)
  
  # check if the connection to te triplestore is ok...otherwise exit the script
  if !adapter
    puts "\nERROR: impossible to open a connection to the triple store. Check your system and your configuration files!\n\n"
    exit(1)
  end

  # try to load every file into the triple store
  files.each do |file|
    import_file(file, rdf_syntax, context)
  end

  adapter.try_call.save

  puts "\n--> Importing rdf/rdfs file: complete!\n\n"
end

.import_file(file, syntax, context) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/talia_core/rdf_import.rb', line 35

def import_file(file, syntax, context)
  puts "\tLoading: " << file.to_s

  my_context = make_ontology_context(context, file)

  # load rdf/rdfs file into triplestore
  begin
    params = [ file ]
    # Other than the adapter, we prefer rdfxml syntax
    params << ((syntax && syntax != 'auto') ? syntax : 'rdfxml')
    params << my_context if(my_context)
    adapter.load(*params)
  rescue Exception => e
    puts "\tProblem loading #{file.to_s}: (#{e.message}) File not loaded!"
    puts e.backtrace
  end
end