-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
although a little odd to be Rightfield::Rightfield
- Loading branch information
Showing
4 changed files
with
56 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters