Class: LD4L::WorksRDF::GetRdfxmlFromMarcxml

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/works_rdf/services/conversion_services/get_rdfxml_from_marcxml.rb

Class Method Summary collapse

Class Method Details

.call(marcxml, baseuri) ⇒ Object

Get rdfxml from marcxml

Parameters:

  • marcxml (String)

    to be converted

Raises:

  • (ArgumentError)


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
# File 'lib/ld4l/works_rdf/services/conversion_services/get_rdfxml_from_marcxml.rb', line 11

def self.call( marcxml, baseuri )
  raise ArgumentError, 'marcxml argument must be a non-empty string'  unless
      marcxml.kind_of?(String) && marcxml.size > 0

  marcxml = marcxml.force_encoding('ASCII-8BIT').encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')

  # TODO: Where should tmp files be saved?  The following puts them in the lib directory
  uuid = SecureRandom.uuid
  rdfxml_file  = File.join(File.dirname(__FILE__), "tmp_#{uuid}.rdf")
  marcxml_file = File.join(File.dirname(__FILE__), "tmp_#{uuid}.marcxml")
  File.open(marcxml_file, 'w') { |file| file.write marcxml; file.close }

  saxon = File.join(File.dirname(__FILE__), 'saxon', 'saxon9he.jar')
  xquery = File.join(File.dirname(__FILE__), 'marc2bibframe', 'xbin', 'saxon.xqy')

  `java -cp #{saxon} net.sf.saxon.Query  #{xquery} marcxmluri=#{marcxml_file} baseuri=#{baseuri} > #{rdfxml_file}`

  # command = "java -cp #{saxon} net.sf.saxon.Query  #{xquery} marcxmluri=#{marcxml_file} baseuri=#{baseuri} > #{rdfxml_file}"

  rdfxml = ""
  File.open(rdfxml_file, 'r') do |file|
    file.each_line {|line| rdfxml << line }
  end

  # Delete temporary files
  File.delete(marcxml_file,rdfxml_file)

  rdfxml
end