Skip to content

Commit 151f3a2

Browse files
committed
Release 0.1.0
2 parents 0891a0f + 95b1c04 commit 151f3a2

46 files changed

Lines changed: 71317 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/InstalledFiles
66
/pkg/
77
/spec/reports/
8+
/spec/testsuite
89
/test/tmp/
910
/test/version_tmp/
1011
/tmp/
@@ -33,3 +34,4 @@ build/
3334

3435
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
3536
.rvmrc
37+
/Gemfile.lock

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: ruby
2+
bundler_args: --without debug
3+
script: "bundle exec rspec spec"
4+
env:
5+
- CI=true
6+
rvm:
7+
- 2.0
8+
- 2.1
9+
- 2.2
10+
- jruby
11+
- rbx-2
12+
cache: bundler
13+
sudo: false

.yardopts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--title "W3C Linked Data Patch Format for RDF.rb."
2+
--output-dir doc/yard
3+
--protected
4+
--no-private
5+
--hide-void-return
6+
--markup markdown
7+
--readme README.md
8+
-
9+
AUTHORS
10+
VERSION
11+
LICENSE
12+
etc/ld-patch.html
13+
etc/earl.ttl
14+
etc/earl.html

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Gregg Kellogg <gregg@greggkellogg.net>

Gemfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
source "http://rubygems.org"
2+
3+
gemspec
4+
5+
gem 'rdf', git: "git://github.com/ruby-rdf/rdf.git", branch: "develop"
6+
gem 'ebnf', git: "git://github.com/gkellogg/ebnf.git", branch: "develop"
7+
8+
group :development do
9+
gem "wirble"
10+
gem "byebug", platforms: :mri_21
11+
end
12+
13+
group :development, :test do
14+
gem 'simplecov', require: false
15+
gem 'coveralls', require: false
16+
gem 'psych', platforms: [:mri, :rbx]
17+
end
18+
19+
platforms :rbx do
20+
gem 'rubysl', '~> 2.0'
21+
gem 'rubinius', '~> 2.0'
22+
gem 'json'
23+
end

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# LD Patch for RDF.rb
2+
3+
This is a [Ruby][] implementation of [LD Patch][] for [RDF.rb][].
4+
5+
[![Gem Version](https://badge.fury.io/rb/ld-patch.png)](http://badge.fury.io/rb/ld-patch)
6+
[![Build Status](https://travis-ci.org/ruby-rdf/ld-patch.png?branch=master)](http://travis-ci.org/ruby-rdf/ld-patch)
7+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/ld-patch/badge.svg)](https://coveralls.io/r/ruby-rdf/ld-patch)
8+
9+
## Description
10+
11+
This gem implements the [LD Patch][] specification with a couple of changes and/or limitations:
12+
13+
* The `INDEX` terminal was replaced by `INTEGER`. Having two terminals matching the same token strings causes a conflict. As a result, a _slice_ may contain positive integers, as well as unsigned and negative-integers.
14+
* The _graph_ rule is changed to the following:
15+
16+
[18] graph ::= triples ('.' triples?)*
17+
18+
This is necessary as the specified production is not context-free. As a result, it is possible for a graph to contain multiple trailing "`.`".
19+
20+
[LD Patch][] is useful inside a Rack container where it can respond to `POST` messages to affect the modification of a _target graph_ identified using the URL of the `POST`.
21+
22+
## Features
23+
24+
* 100% free and unencumbered [public domain](http://unlicense.org/) software.
25+
* Complete [Linked Data Patch Format][LD Patch] parsing and execution
26+
* Implementation Report: {file:etc/earl.html EARL}
27+
* Compatible with Ruby >= 2.0.0.
28+
29+
## Documentation
30+
Full documentation available on [Rubydoc.info][LD-Patch doc]
31+
32+
## Implementation Notes
33+
The reader uses the [EBNF][] gem to generate first, follow and branch tables, and uses the `Parser` and `Lexer` modules to implement the LD Patch parser.
34+
35+
The parser takes branch and follow tables generated from the [LD Patch Grammar](file.ld-patch.html) described in the [specification][LD Patch]. Branch and Follow tables are specified in the generated {LD::Patch::Meta}.
36+
37+
## Dependencies
38+
39+
* [Ruby](http://ruby-lang.org/) (>= 2.0.0)
40+
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1.15)
41+
* [EBNF][] (>= 0.3.0)
42+
* [SPARQL][] (>= 1.1.7)
43+
* [SXP][] (>= 0.1.5)
44+
* [RDF::XSD][] (>= 1.1.4)
45+
46+
## Mailing List
47+
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
48+
49+
## Author
50+
* [Gregg Kellogg](http://github.com/gkellogg) - <http://greggkellogg.net/>
51+
52+
## Contributing
53+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
54+
55+
* Do your best to adhere to the existing coding conventions and idioms.
56+
* Don't use hard tabs, and don't leave trailing whitespace on any line.
57+
* Do document every method you add using [YARD][] annotations. Read the [tutorial][YARD-GS] or just look at the existing code for examples.
58+
* Don't touch the `.gemspec`, `VERSION` or `AUTHORS` files. If you need to change them, do so on your private branch only.
59+
* Do feel free to add yourself to the `CREDITS` file and the corresponding list in the the `README`. Alphabetical order applies.
60+
* Do note that in order for us to merge any non-trivial changes (as a rule of thumb, additions larger than about 15 lines of code), we need an explicit [public domain dedication][PDD] on record from you.
61+
62+
## License
63+
This is free and unencumbered public domain software. For more information,
64+
see <http://unlicense.org/> or the accompanying {file:LICENSE} file.
65+
66+
A copy of the [LD Patch EBNF](file:etc/ld-patch.ebnf) and derived parser files are included in the repository, which are not covered under the UNLICENSE. These files are covered via the [W3C Document License](http://www.w3.org/Consortium/Legal/2002/copyright-documents-20021231).
67+
68+
[Ruby]: http://ruby-lang.org/
69+
[RDF]: http://www.w3.org/RDF/
70+
[YARD]: http://yardoc.org/
71+
[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
72+
[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
73+
[RDF.rb]: http://rubygems.org/gems/rdf
74+
[RDF::XSD]: http://rubygems.org/gems/rdf-xsd
75+
[EBNF]: http://rubygems.org/gems/ebnf
76+
[SPARQL]: http://rubygems.org/gems/sparql
77+
[Linked Data]: http://rubygems.org/gems/linkeddata
78+
[SSE]: http://openjena.org/wiki/SSE
79+
[SXP]: http://rubygems.org/gems/sxp-ruby
80+
[LD Patch]: http://www.w3.org/TR/ldpatch/
81+
[LD-Patch doc]: http://rubydoc.info/github/ruby-rdf/ld-patch

Rakefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env ruby
2+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'lib')))
3+
require 'rubygems'
4+
require 'yard'
5+
require 'rspec/core/rake_task'
6+
7+
task default: :spec
8+
task specs: :spec
9+
10+
namespace :gem do
11+
desc "Build the ld-patch-#{File.read('VERSION').chomp}.gem file"
12+
task :build do
13+
sh "gem build ld-patch.gemspec && mv ld-patch-#{File.read('VERSION').chomp}.gem pkg/"
14+
end
15+
16+
desc "Release the ld-patch-#{File.read('VERSION').chomp}.gem file"
17+
task :release do
18+
sh "gem push pkg/ld-patch-#{File.read('VERSION').chomp}.gem"
19+
end
20+
end
21+
22+
RSpec::Core::RakeTask.new(:spec)
23+
24+
desc "Run specs through RCov"
25+
RSpec::Core::RakeTask.new("spec:rcov") do |spec|
26+
spec.rcov = true
27+
spec.rcov_opts = %q[--exclude "spec"]
28+
end
29+
30+
namespace :doc do
31+
YARD::Rake::YardocTask.new
32+
end
33+
34+
desc 'Create versions of ebnf files in etc'
35+
task etc: %w{etc/ld-patch.sxp etc/ld-patch.html etc/ld-patch.ll1.sxp}
36+
37+
desc 'Build first, follow and branch tables'
38+
task meta: "lib/ld/patch/meta.rb"
39+
40+
file "lib/ld/patch/meta.rb" => "etc/ld-patch.ebnf" do |t|
41+
sh %{
42+
ebnf --ll1 ldpatch --format rb \
43+
--mod-name LD::Patch::Meta \
44+
--output lib/ld/patch/meta.rb \
45+
etc/ld-patch.ebnf
46+
}
47+
end
48+
49+
file "etc/ld-patch.ll1.sxp" => "etc/ld-patch.ebnf" do |t|
50+
sh %{
51+
ebnf --ll1 ldpatch --format sxp \
52+
--output etc/ld-patch.ll1.sxp \
53+
etc/ld-patch.ebnf
54+
}
55+
end
56+
57+
file "etc/ld-patch.sxp" => "etc/ld-patch.ebnf" do |t|
58+
sh %{
59+
ebnf --bnf --format sxp \
60+
--output etc/ld-patch.sxp \
61+
etc/ld-patch.ebnf
62+
}
63+
end
64+
65+
file "etc/ld-patch.html" => "etc/ld-patch.ebnf" do |t|
66+
sh %{
67+
ebnf --format html \
68+
--output etc/ld-patch.html \
69+
etc/ld-patch.ebnf
70+
}
71+
end

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

bin/ldpatch

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/usr/bin/env ruby
2+
require 'rubygems'
3+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
4+
require 'ld/patch'
5+
begin
6+
require 'linkeddata'
7+
rescue LoadError
8+
require 'rdf/ntriples'
9+
require 'rdf/turtle'
10+
end
11+
require 'getoptlong'
12+
13+
def run(input, options = {})
14+
if options[:debug]
15+
puts "input graph:\n#{options[:graph].dump(:ttl, standard_prefixes: true)}\n" if options[:graph]
16+
puts "query:\n#{input}\n"
17+
end
18+
options[:graph] ||= RDF::Graph.new
19+
20+
if options[:verbose]
21+
puts ("\nPATCH:\n" + input)
22+
end
23+
24+
patch = if options[:sse]
25+
SPARQL::Algebra.parse(input, options)
26+
else
27+
# Only do grammar debugging if we're generating SSE
28+
LD::Patch.parse(input, options)
29+
end
30+
31+
puts ("\nSSE:\n" + patch.to_sse) if options[:debug] || options[:to_sse]
32+
33+
unless options[:to_sse]
34+
res = patch.execute(options[:graph], debug: options[:debug])
35+
puts res.inspect if options[:verbose]
36+
puts res.dump(:ttl, base_uri: patch.base_uri, prefixes: patch.prefixes, standard_prefixes: true)
37+
end
38+
end
39+
40+
opts = GetoptLong.new(
41+
["--debug", GetoptLong::NO_ARGUMENT],
42+
["--dump", GetoptLong::NO_ARGUMENT],
43+
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
44+
["--progress", GetoptLong::NO_ARGUMENT],
45+
["--sse", GetoptLong::NO_ARGUMENT],
46+
["--to-sse", GetoptLong::NO_ARGUMENT],
47+
["--validate", GetoptLong::NO_ARGUMENT],
48+
["--verbose", GetoptLong::NO_ARGUMENT],
49+
["--help", "-?", GetoptLong::NO_ARGUMENT]
50+
)
51+
52+
options = {
53+
graph: RDF::Repository.new,
54+
}
55+
56+
input = nil
57+
58+
opts.each do |opt, arg|
59+
case opt
60+
when '--debug' then options[:debug] = true
61+
when '--dump' then $dump = true
62+
when '--execute' then input = arg
63+
when '--progress' then options[:debug] ||= 2
64+
when '--sse' then options[:sse] = true
65+
when '--to-sse' then options[:to_sse] = true
66+
when '--validate' then options[:validate] = true
67+
when '--verbose' then options[:verbose] = true
68+
when "--help"
69+
puts "Usage: #{$0} [options] file-or-uri ..."
70+
puts "Options:"
71+
puts " --execute,-e: Use option argument as the SPARQL input if no files are given"
72+
puts " --dump: Dump raw output, otherwise serialize to SSE"
73+
puts " --debug: Display detailed debug output"
74+
puts " --sse: Input is in SSE format"
75+
puts " --to-sse: Generate SSE instead of running query"
76+
puts " --verbose: Display details of processing"
77+
puts " --help,-?: This message"
78+
exit(0)
79+
end
80+
end
81+
82+
if ARGV.empty?
83+
s = input ? input : $stdin.read
84+
run(s, options)
85+
else
86+
ARGV.each do |test_file|
87+
puts "parse #{test_file}"
88+
run(RDF::Util::File.open_file(test_file).read, options.merge(base_uri: RDF::URI(test_file)))
89+
end
90+
end
91+
puts

etc/.earl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
:format: :json
3+
:manifest:
4+
- https://raw.githubusercontent.com/pchampin/ld-patch-testsuite/master/manifest.ttl
5+
- https://raw.githubusercontent.com/pchampin/ld-patch-testsuite/master/manifest-syntax.ttl
6+
- https://raw.githubusercontent.com/pchampin/ld-patch-testsuite/master/turtle/manifest-ldpatch.ttl
7+
:bibRef: ! '[[LDPATCH]]'
8+
:name: Linked Data Patch Format

0 commit comments

Comments
 (0)