Skip to content

Commit

Permalink
Rename API.toRDF to API.toRdf and .fromRDF to .fromRdf to align with …
Browse files Browse the repository at this point in the history
…spec.
  • Loading branch information
gkellogg committed Oct 9, 2013
1 parent 9225ee8 commit 2a1bf31
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Install with `gem install json-ld`
"foaf:nick": { "@list": [ "joe", "bob", "jaybe" ] }
})

graph = RDF::Graph.new << JSON::LD::API.toRDF(input)
graph = RDF::Graph.new << JSON::LD::API.toRdf(input)

require 'rdf/turtle'
graph.dump(:ttl, :prefixes => {:foaf => "http://xmlns.com/foaf/0.1/"})
Expand Down Expand Up @@ -190,7 +190,7 @@ Install with `gem install json-ld`
})

compacted = nil
JSON::LD::API::fromRDF(input) do |expanded|
JSON::LD::API::fromRdf(input) do |expanded|
compacted = JSON::LD::API.compact(expanded, context['@context'])
end
compacted =>
Expand Down
2 changes: 1 addition & 1 deletion bin/jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run(input, options)
if options[:format] == :jsonld && options[:input_format] != :jsonld
r = reader_class.new(input, options[:parser_options])
g = RDF::Repository.new << r
input = JSON::LD::API.fromRDF(g)
input = JSON::LD::API.fromRdf(g)
end

prefixes = {}
Expand Down
2 changes: 1 addition & 1 deletion example-files/schema-xform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
outfile = infile.sub('.html', '.jsonld')
puts outfile
RDF::Repository.load(infile) do |repo|
JSON::LD::API.fromRDF(repo) do |expanded|
JSON::LD::API.fromRdf(repo) do |expanded|
JSON::LD::API.compact(expanded, context) do |compacted|
compacted['@graph'].each do |obj|
next if type_exclusion.include?(obj['name'])
Expand Down
20 changes: 13 additions & 7 deletions lib/json/ld/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def self.frame(input, frame, options = {})
# @return [Array<RDF::Statement>] if no block given
# @yield statement
# @yieldparam [RDF::Statement] statement
def self.toRDF(input, options = {}, &block)
def self.toRdf(input, options = {}, &block)
results = []
results.extend(RDF::Enumerable)

Expand All @@ -373,21 +373,21 @@ def self.toRDF(input, options = {}, &block)
API.new(expanded_input, nil, options) do
# 1) Perform the Expansion Algorithm on the JSON-LD input.
# This removes any existing context to allow the given context to be cleanly applied.
debug(".toRDF") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}
debug(".toRdf") {"expanded input: #{expanded_input.to_json(JSON_STATE)}"}

# Generate _nodeMap_
node_map = Hash.ordered
node_map['@default'] = Hash.ordered
generate_node_map(expanded_input, node_map)
debug(".toRDF") {"node map: #{node_map.to_json(JSON_STATE)}"}
debug(".toRdf") {"node map: #{node_map.to_json(JSON_STATE)}"}

# Start generating statements
node_map.each do |graph_name, graph|
context = as_resource(graph_name) unless graph_name == '@default'
debug(".toRDF") {"context: #{context ? context.to_ntriples : 'null'}"}
debug(".toRdf") {"context: #{context ? context.to_ntriples : 'null'}"}
# Drop results for graphs which are named with relative IRIs
if graph_name.is_a?(RDF::URI) && !graph_name.absolute
debug(".toRDF") {"drop relative graph_name: #{statement.to_ntriples}"}
debug(".toRdf") {"drop relative graph_name: #{statement.to_ntriples}"}
next
end
graph_to_rdf(graph).each do |statement|
Expand All @@ -404,7 +404,7 @@ def self.toRDF(input, options = {}, &block)
end
end
if relative
debug(".toRDF") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
debug(".toRdf") {"drop statement with relative IRIs: #{statement.to_ntriples}"}
next
end

Expand Down Expand Up @@ -433,7 +433,7 @@ def self.toRDF(input, options = {}, &block)
# The JSON-LD document in expanded form
# @return [Array<Hash>]
# The JSON-LD document in expanded form
def self.fromRDF(input, options = {}, &block)
def self.fromRdf(input, options = {}, &block)
options = {:useNativeTypes => false}.merge(options)
result = nil

Expand Down Expand Up @@ -526,6 +526,12 @@ def self.documentLoader(url, options = {})
end
end

# Add class method aliases for backwards compatibility
class << self
alias :toRDF :toRdf
alias :fromRDF :fromRdf
end

##
# A {RemoteDocument} is returned from a {documentLoader}.
class RemoteDocument
Expand Down
2 changes: 1 addition & 1 deletion lib/json/ld/from_rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def from_statements(input)
node.delete(:usages)
result << node unless node_reference?(node)
end
debug("fromRDF") {result.to_json(JSON_STATE)}
debug("fromRdf") {result.to_json(JSON_STATE)}
result
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/json/ld/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def initialize(input = $stdin, options = {}, &block)
# @private
# @see RDF::Reader#each_statement
def each_statement(&block)
JSON::LD::API.toRDF(@doc, @options).each do |statement|
JSON::LD::API.toRdf(@doc, @options).each do |statement|
# If RDF version is 1.0, fold literals with xsd:string to be just simple literals
statement.object.datatype = nil if
RDF::VERSION.to_s < "1.1" &&
Expand Down
2 changes: 1 addition & 1 deletion lib/json/ld/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def write_epilogue
@debug = @options[:debug]

debug("writer") { "serialize #{@repo.count} statements, #{@options.inspect}"}
result = API.fromRDF(@repo, @options)
result = API.fromRdf(@repo, @options)

# If we were provided a context, or prefixes, use them to compact the output
context = RDF::Util::File.open_file(@options[:context]) if @options[:context].is_a?(String)
Expand Down
4 changes: 2 additions & 2 deletions script/tc
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ def run_tc(man, tc, options)
output == expected ? 'passed' : 'failed'
when 'jld:FromRDFTest'
repo = RDF::Repository.load(tc.input_loc)
output = JSON::LD::API.fromRDF(repo, tc.options)
output = JSON::LD::API.fromRdf(repo, tc.options)
expected = JSON.load(tc.expect)
output == expected ? 'passed' : 'failed'
when 'jld:ToRDFTest'
quads = JSON::LD::API.toRDF(tc.input_loc, tc.options).map do |statement|
quads = JSON::LD::API.toRdf(tc.input_loc, tc.options).map do |statement|
tc.to_quad(statement)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
jld.should produce(JSON.load(File.open(framed)), @debug)
end if File.exist?(framed) && File.exist?(frame)

it "toRDF" do
it "toRdf" do
RDF::Repository.load(filename, :debug => @debug).should be_equivalent_graph(RDF::Repository.load(ttl), :trace => @debug)
end if File.exist?(ttl)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/from_rdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'rdf/spec/writer'

describe JSON::LD::API do
describe ".fromRDF" do
describe ".fromRdf" do
context "simple tests" do
it "One subject IRI object" do
input = %(<http://a/b> <http://a/c> <http://a/d> .)
Expand Down Expand Up @@ -374,6 +374,6 @@ def serialize(ntstr, options = {})
g = ntstr.is_a?(String) ? parse(ntstr, options) : ntstr
@debug << g.dump(:trig)
statements = g.each_statement.to_a
JSON::LD::API.fromRDF(statements, options.merge(:debug => @debug))
JSON::LD::API.fromRdf(statements, options.merge(:debug => @debug))
end
end
8 changes: 4 additions & 4 deletions spec/suite_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def run(rspec_example = nil)
when "jld:FromRDFTest"
repo = RDF::Repository.load(input_loc, :format => :nquads)
debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
JSON::LD::API.fromRDF(repo, options.merge(:debug => debug))
JSON::LD::API.fromRdf(repo, options.merge(:debug => debug))
when "jld:ToRDFTest"
JSON::LD::API.toRDF(input_loc, options.merge(:debug => debug)).map do |statement|
JSON::LD::API.toRdf(input_loc, options.merge(:debug => debug)).map do |statement|
to_quad(statement)
end
else
Expand Down Expand Up @@ -156,9 +156,9 @@ def run(rspec_example = nil)
when "jld:FromRDFTest"
repo = RDF::Repository.load(t.input_loc)
debug << "repo: #{repo.dump(id == '#t0012' ? :nquads : :trig)}"
JSON::LD::API.fromRDF(repo, options.merge(:debug => debug))
JSON::LD::API.fromRdf(repo, options.merge(:debug => debug))
when "jld:ToRDFTest"
JSON::LD::API.toRDF(t.input_loc, options.merge(:debug => debug)).map do |statement|
JSON::LD::API.toRdf(t.input_loc, options.merge(:debug => debug)).map do |statement|
t.to_quad(statement)
end
else
Expand Down
6 changes: 3 additions & 3 deletions spec/to_rdf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
describe JSON::LD::API do
before(:each) {@debug = []}

context ".toRDF" do
context ".toRdf" do
it "should implement RDF::Enumerable" do
expect(JSON::LD::API.toRDF({})).to be_a(RDF::Enumerable)
expect(JSON::LD::API.toRdf({})).to be_a(RDF::Enumerable)
end

context "unnamed nodes" do
Expand Down Expand Up @@ -650,7 +650,7 @@ def parse(input, options = {})
@debug = []
graph = options[:graph] || RDF::Graph.new
options = {:debug => @debug, :validate => true, :canonicalize => false}.merge(options)
JSON::LD::API.toRDF(StringIO.new(input), options) {|st| graph << st}
JSON::LD::API.toRdf(StringIO.new(input), options) {|st| graph << st}
graph
end
end

0 comments on commit 2a1bf31

Please sign in to comment.