Sha256: ff4558f0f8212ca56af2555d5c2d3c87096a82b43502995e74c4578be2f99e7f

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

#!/usr/bin/env ruby -s
require 'rubygems'
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
require 'rdf/n3'
require 'getoptlong'

def parse(input, base)
  puts RDF::Writer.for($format.to_sym).buffer(:base_uri => base) { |writer|
    RDF::N3::Reader.new(input, :base_uri => base, :strict => true).each do |statement|
      writer << statement
    end
  }
end

mode = ARGV.shift
raise "Mode must be one of 'parse'" unless mode == "parse"

$verbose = false
$format = :ntriples
base_uri  = "http://example.com"
input = nil

opts = GetoptLong.new(
  ["--debug", GetoptLong::NO_ARGUMENT],
  ["--verbose", GetoptLong::NO_ARGUMENT],
  ["--quiet", GetoptLong::NO_ARGUMENT],
  ["--format", GetoptLong::REQUIRED_ARGUMENT],
  ["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
  ["--uri", GetoptLong::REQUIRED_ARGUMENT]
)
opts.each do |opt, arg|
  case opt
  when '--verbose' then $verbose = true
  when '--quiet' then $quiet = true
  when '--debug' then ::RDF::N3::debug = true
  when '--execute' then input = arg
  when '--format' then $format = arg
  when '--uri' then base_uri = arg
  end
end

if ARGV.empty?
  s = input ? input : $stdin.read
  parse(StringIO.new(s), base_uri)
else
  ARGV.each do |test_file|
    parse(File.open(test_file), base_uri)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rdf-n3-0.2.3.2 script/parse
rdf-n3-0.2.3.1 script/parse
rdf-n3-0.2.3 script/parse