Skip to content

Commit

Permalink
fixed Rightfield module
Browse files Browse the repository at this point in the history
although a little odd to be Rightfield::Rightfield
  • Loading branch information
stuzart committed Dec 11, 2024
1 parent b5cae28 commit ed0f64c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 54 deletions.
104 changes: 53 additions & 51 deletions lib/rightfield/rightfield.rb
Original file line number Diff line number Diff line change
@@ -1,78 +1,80 @@
require 'open4'
require 'rdf/rdfxml'

module RightField
JAR_PATH = File.dirname(__FILE__) + '/rightfield-bin.jar'
module Rightfield
module Rightfield
JAR_PATH = File.dirname(__FILE__) + '/rightfield-bin.jar'

def invoke_rdf_command(datafile)
id = rdf_resource_uri(datafile)
"java -jar #{JAR_PATH} -export -format rdf -id #{id} #{datafile.content_blob.filepath}"
end
def invoke_rdf_command(datafile)
id = rdf_resource_uri(datafile)
"java -jar #{JAR_PATH} -export -format rdf -id #{id} #{datafile.content_blob.filepath}"
end

def invoke_csv_command(datafile)
"java -jar #{JAR_PATH} -export -format csv #{datafile.content_blob.filepath}"
end
def invoke_csv_command(datafile)
"java -jar #{JAR_PATH} -export -format csv #{datafile.content_blob.filepath}"
end

def rdf_resource_uri(datafile)
Seek::Util.routes.data_file_url(datafile)
end
def rdf_resource_uri(datafile)
Seek::Util.routes.data_file_url(datafile)
end

def generate_rightfield_csv(datafile)
Rails.cache.fetch("#{datafile.content_blob.filepath}_rf_csv") do
cmd = invoke_csv_command datafile

def generate_rightfield_csv(datafile)
Rails.cache.fetch("#{datafile.content_blob.filepath}_rf_csv") do
cmd = invoke_csv_command datafile
output = ''

output = ''
status = Open4.popen4(cmd) do |_pid, _stdin, stdout, stderr|
while (line = stdout.gets) != nil
output << line
end
stdout.close

status = Open4.popen4(cmd) do |_pid, _stdin, stdout, stderr|
while (line = stdout.gets) != nil
output << line
stderr.close
end
stdout.close

stderr.close
end
if status.to_i != 0
# error message is coming out through stdout rather than stderr due to log4j configuration.
raise Exception, output
end

if status.to_i != 0
# error message is coming out through stdout rather than stderr due to log4j configuration.
raise Exception, output
output.strip
end

output.strip
end
end

def generate_rightfield_rdf(datafile)
Rails.cache.fetch("#{datafile.content_blob.filepath}_rf_rdf") do
cmd = invoke_rdf_command datafile
def generate_rightfield_rdf(datafile)
Rails.cache.fetch("#{datafile.content_blob.filepath}_rf_rdf") do
cmd = invoke_rdf_command datafile

output = ''
output = ''

status = Open4.popen4(cmd) do |_pid, _stdin, stdout, stderr|
while (line = stdout.gets) != nil
output << line
status = Open4.popen4(cmd) do |_pid, _stdin, stdout, stderr|
while (line = stdout.gets) != nil
output << line
end
stdout.close

stderr.close
end
stdout.close

stderr.close
end
if status.to_i != 0
# error message is coming out through stdout rather than stderr due to log4j configuration.
raise Exception, output
end

if status.to_i != 0
# error message is coming out through stdout rather than stderr due to log4j configuration.
raise Exception, output
output.strip
end

output.strip
end
end

def generate_rightfield_rdf_graph(datafile)
rdf = generate_rightfield_rdf datafile
graph = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(rdf) do |reader|
reader.each_statement do |stmt|
graph << stmt
def generate_rightfield_rdf_graph(datafile)
rdf = generate_rightfield_rdf datafile
graph = RDF::Graph.new
RDF::Reader.for(:rdfxml).new(rdf) do |reader|
reader.each_statement do |stmt|
graph << stmt
end
end
graph
end
graph
end
end
2 changes: 1 addition & 1 deletion lib/seek/rdf/rdf_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Seek
module Rdf
module RdfGeneration
include RdfRepositoryStorage
include RightField
include Rightfield::Rightfield
include CSVMappingsHandling

def self.included(base)
Expand Down
2 changes: 1 addition & 1 deletion lib/seek/templates/extract/rightfield_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Templates
module Extract
# Base class for handling of extracting and interpreting metadata from within a Rightfield Template
class RightfieldExtractor
include RightField
include Rightfield::Rightfield

attr_reader :current_user

Expand Down
2 changes: 1 addition & 1 deletion test/unit/rdf_generation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'libxml'

class RDFGenerationTest < ActiveSupport::TestCase
include RightField
include Rightfield::Rightfield

test 'rightfield rdf generation' do
df = FactoryBot.create :rightfield_annotated_datafile
Expand Down

0 comments on commit ed0f64c

Please sign in to comment.