Last active
August 29, 2015 14:09
-
-
Save ktym/00bf7b0e9280c4ec1962 to your computer and use it in GitHub Desktop.
RDF format converter
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
#!/usr/bin/env ruby | |
# | |
# % gem install linkeddata | |
# % lodconvert.rb -h | |
# % lodconvert.rb [-i input_format] [-o output_format] inputfile > outputfile | |
# | |
require 'rubygems' | |
require 'linkeddata' | |
require 'getoptlong' | |
def help | |
puts DATA.read | |
end | |
# Set default output format to turtle | |
opts = { | |
:output => :ttl | |
} | |
args = GetoptLong.new( | |
[ '--input', '-i', GetoptLong::REQUIRED_ARGUMENT ], | |
[ '--output', '-o', GetoptLong::REQUIRED_ARGUMENT ], | |
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], | |
) | |
args.each_option do |name, value| | |
case name | |
when /--input/ | |
opts[:input] = value.to_sym | |
when /--output/ | |
opts[:output] = value.to_sym | |
when /--help/ | |
help | |
exit 0 | |
end | |
end | |
if opts[:input] | |
hash = { :format => opts[:input] } | |
else | |
hash = {} | |
end | |
RDF::Graph.load(ARGV.shift, hash) do |graph| | |
puts graph.dump(opts[:output], :standard_prefixes => true) | |
end | |
__END__ | |
NAME | |
lodconvert.rb -- RDF format converter | |
SYNOPSIS | |
lodconvert.rb --help | |
lodconvert.rb [--input format] --output format input_file > output_file | |
DESCRIPTION | |
Accepted formats includes: | |
rdf, rdfxml RDF/XML | |
ttl, turtle Turtle | |
ntriples N-Triples | |
jsonld JSON-LD | |
trig TriG | |
trix TriX | |
nquads N-Quads |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment