Sha256: 75c095b014d1e0c8c02c286f48393dd18a8a11c762f967ccd0a5c00ee4fd2085
Contents?: true
Size: 1.84 KB
Versions: 4
Compression:
Stored size: 1.84 KB
Contents
#!/usr/bin/env ruby -s require 'rubygems' require File.expand_path(File.dirname(__FILE__) + "/../lib/rdf_context") require 'getoptlong' class Parse include RdfContext def parse(file, base_uri, store = nil) puts "Parse: #{file}" if $quiet graph_opts = {:identifier => base_uri} graph_opts[:store] = store if store parser = Parser.new(:graph => Graph.new(graph_opts)) parser.parse(File.read(file), base_uri, :strict => true) output = case $format when "xml" parser.graph.to_rdfxml else parser.graph.to_ntriples end puts output unless $quiet puts parser.debug.join("\n\t") if $verbose rescue RdfException => e puts "Parse failure: #{e.message}" puts parser.debug if $verbose && parser #raise rescue Exception => e puts "Parser fault: #{e.message}" puts parser.debug if parser && !$quiet raise end end $verbose = false base_uri = "http://example.com" store = :list_store opts = GetoptLong.new( ["--verbose", GetoptLong::NO_ARGUMENT], ["--quiet", GetoptLong::NO_ARGUMENT], ["--debug", GetoptLong::NO_ARGUMENT], ["--format", GetoptLong::REQUIRED_ARGUMENT], ["--store", 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 $DEBUG = true when '--format' then $format = arg when '--uri' then base_uri = arg when '--store' case arg when /list/ store = :list_store when /memory/ store = :memory_store else puts "Creating SQLite3 database '#{arg}'" unless File.exists?(arg) store = RdfContext::SQLite3Store.new(RdfContext::URIRef.new("http://kellogg-assoc.com/rdf_context"), :path => arg) end end end x = Parse.new ARGV.each do |test_file| x.parse(test_file, base_uri, store) end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rdf_context-0.4.8 | bin/rdf_context |
rdf_context-0.4.7 | bin/rdf_context |
rdf_context-0.4.6 | bin/rdf_context |
rdf_context-0.4.5 | bin/rdf_context |