Created
March 30, 2012 12:42
-
-
Save ldodds/2251260 to your computer and use it in GitHub Desktop.
Example of Bulk load Ntriples into Kasabi using kasabi.rb
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
# Bulk load N-Triples into Kasabi | |
# | |
# Simple script to iterate through a large n-triples file and load it into Kasabi | |
# | |
# Be sure to set two environment variables: KASABI_DATASET and KASABI_API_KEY | |
# | |
# Script accepts a single command-line parameter which is the location of the file to upload | |
require 'rubygems' | |
require 'kasabi' | |
#URI of dataset api | |
dataset = ENV["KASABI_DATASET"] | |
#Developer API key | |
apikey = ENV["KASABI_API_KEY"] | |
#base url of API | |
base = ENV["KASABI_BASE_URI"] || "http://api.kasabi.com" | |
#create our client | |
dataset = Kasabi::Dataset.new("#{base}/dataset/#{dataset}", {:apikey => apikey}) | |
#Uncomment for HTTP level debugging | |
#dataset.client.debug_dev = $stderr | |
puts "Dataset: #{dataset.endpoint}" | |
puts "API key: #{apikey}" | |
to_add = File.read(ARGV[0]) | |
count = 0 | |
lines = "" | |
File.open(ARGV[0], "r").each do |line| | |
lines << line + "\n" | |
count = count + 1 | |
if count % 9000 == 0 | |
puts "Submitting data to Kasabi dataset" | |
begin | |
client = dataset.store_api_client() | |
resp = client.store_data( lines, "text/turtle") | |
puts "Data submitted. Update URI: #{resp}" | |
rescue => e | |
puts "FAIL" | |
puts e | |
end | |
lines = "" | |
end | |
end | |
if lines != "" | |
puts "Submitting test data to Kasabi dataset" | |
begin | |
client = dataset.store_api_client() | |
resp = client.store_data( lines, "text/turtle") | |
puts "Data submitted. Update URI: #{resp}" | |
rescue => e | |
puts "FAIL" | |
puts e | |
end | |
end | |
puts "Data loaded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment