Sha256: 42565ee084e60b49ac577dd980a1ac751c1098d9ec1b1ef4a90283da3a8a878f

Contents?: true

Size: 1.59 KB

Versions: 3

Compression:

Stored size: 1.59 KB

Contents

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

def parse(input, base)
  reader_class = RDF::Reader.for($input_format.to_sym)
  writer_class = RDF::Writer.for($output_format.to_sym)
  raise "Reader not found for #{$input_format}" unless reader_class
  raise "Writer not found for #{$output_format}" unless writer_class
  puts writer_class.buffer { |writer|
    reader_class.new(input, :base_uri => base, :validate => true).each do |statement|
      writer << statement
    end
  }
end

$verbose = false
$output_format = :ntriples
$input_format = :rdfa
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],
  ["--input-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::RDFa::debug = true
  when '--execute' then input = arg
  when '--format' then $output_format = arg
  when '--input-format' then $input_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(Kernel.open(test_file), base_uri)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rdf-rdfa-0.3.1.2 script/parse
rdf-rdfa-0.3.1.1 script/parse
rdf-rdfa-0.3.0 script/parse