Class: PubliSci::Writers::Builder

Inherits:
Object
  • Object
show all
Includes:
Dataframe
Defined in:
lib/publisci/writers/dataframe.rb

Instance Method Summary collapse

Methods included from Dataframe

#create_dataframe, #framestring, #get_rownames, #get_vectors, #save_workspace

Instance Method Details

#from_store(endpoint_url, connection, variable_in = nil, variable_out = nil, verbose = true, save = true) ⇒ Object


65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/publisci/writers/dataframe.rb', line 65

def from_store(endpoint_url,connection,variable_in=nil, variable_out=nil, verbose=true, save=true)
  unless variable_in && variable_out
    puts "no variable specified. Simple inference coming soon" if verbose
    return
  end
  puts "connecting to endpoint at #{endpoint_url}" if verbose
  sparql = SPARQL::Client.new(endpoint_url)
  # client = PubliSci::Client.new
  query = PubliSci::QueryHelper.new

  rows = query.get_ary(sparql.query(query.row_names(variable_in))).flatten

end

#from_turtle(turtle_file, connection, variable_in = nil, variable_out = nil, verbose = true, save = true) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/publisci/writers/dataframe.rb', line 45

def from_turtle(turtle_file, connection, variable_in=nil, variable_out=nil, verbose=true, save=true)
  unless variable_in && variable_out
    puts "no variable specified. Simple inference coming soon" if verbose
    return
  end
  puts "loading #{turtle_file}" if verbose
  repo = RDF::Repository.load(turtle_file)
  puts "loaded #{repo.size} statements into temporary repo" if verbose
  # connection = Rserve::Connection.new
  query = PubliSci::QueryHelper.new
  rows = get_rownames(variable_in, query, repo)
  puts "frame has #{rows.size} rows" if verbose

  vectors = get_vectors(variable_in, query, repo)
  puts "got vectors of size #{vectors.first.last.size}" if verbose && vectors.first

  create_dataframe(variable_out, connection, rows, vectors)
  save_workspace(connection, connection.eval('getwd()').to_ruby) if save
end