ld-patch 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/VERSION +1 -1
- data/bin/ldpatch +30 -40
- data/lib/ld/patch.rb +4 -2
- data/lib/ld/patch/algebra/update_list.rb +1 -1
- data/lib/ld/patch/parser.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a82bb5a30058fd674000f4764eafb4671940af39
|
4
|
+
data.tar.gz: 65d86b62bb418c2437618ab376ab0a06859fc503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b45ab3f99dd9bbd00bd6c355d9bc920e42e48fb419c37f30c6db745b489fde41bc0fdef6b7bf192985bee6be71f4f8c8d1a190b6737492d3f27af46a181e58a
|
7
|
+
data.tar.gz: 84fdef8b2d24fad8bfa3f85b6091e6227b276575f69038b5fbf1b9f183b38353ab8977e40ce5f4677f6375e98cfdc6efa08a89627321d4fd09331300fd70f437
|
data/README.md
CHANGED
@@ -29,6 +29,30 @@ This gem implements the [LD Patch][] specification with a couple of changes and/
|
|
29
29
|
## Documentation
|
30
30
|
Full documentation available on [Rubydoc.info][LD-Patch doc]
|
31
31
|
|
32
|
+
## Examples
|
33
|
+
|
34
|
+
require 'rubygems'
|
35
|
+
require 'ld/patch'
|
36
|
+
|
37
|
+
### Example Patch
|
38
|
+
|
39
|
+
queryable = RDF::Repository.load("etc/doap.ttl")
|
40
|
+
patch = %(
|
41
|
+
@prefix doap: <http://usefulinc.com/ns/doap#> .
|
42
|
+
@prefix earl: <http://www.w3.org/ns/earl#> .
|
43
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
|
44
|
+
|
45
|
+
Delete { <> a earl:TestSubject, earl:Software } .
|
46
|
+
Add {
|
47
|
+
<http://greggkellogg.net/foaf#me> a foaf:Person;
|
48
|
+
foaf:name "Gregg Kellogg"
|
49
|
+
} .
|
50
|
+
Bind ?ruby <> / doap:programming-language .
|
51
|
+
Cut ?ruby .
|
52
|
+
)
|
53
|
+
operator = LD::Patch.parse(patch, base_uri: "http://rubygems.org/gems/ld-patch")
|
54
|
+
operator.execute(queryable) # alternatively queryable.query(operator)
|
55
|
+
|
32
56
|
## Implementation Notes
|
33
57
|
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
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/ldpatch
CHANGED
@@ -10,82 +10,72 @@ rescue LoadError
|
|
10
10
|
end
|
11
11
|
require 'getoptlong'
|
12
12
|
|
13
|
-
def run(
|
13
|
+
def run(graph, options = {})
|
14
14
|
if options[:debug]
|
15
|
-
puts "
|
16
|
-
puts "
|
15
|
+
puts "target graph:\n#{graph.dump(:ttl, standard_prefixes: true)}\n"
|
16
|
+
puts "patch:\n#{options[:patch]}\n"
|
17
17
|
end
|
18
|
-
options[:graph] ||= RDF::Graph.new
|
19
18
|
|
20
19
|
if options[:verbose]
|
21
|
-
puts ("\
|
20
|
+
puts ("\npatch:\n" + options[:patch])
|
22
21
|
end
|
23
22
|
|
24
|
-
patch =
|
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
|
23
|
+
patch = LD::Patch.parse(options[:patch], options)
|
30
24
|
|
31
25
|
puts ("\nSSE:\n" + patch.to_sse) if options[:debug] || options[:to_sse]
|
32
26
|
|
33
27
|
unless options[:to_sse]
|
34
|
-
res = patch.execute(
|
35
|
-
puts res.inspect if options[:verbose]
|
28
|
+
res = patch.execute(graph, options)
|
36
29
|
puts res.dump(:ttl, base_uri: patch.base_uri, prefixes: patch.prefixes, standard_prefixes: true)
|
37
30
|
end
|
38
31
|
end
|
39
32
|
|
40
33
|
opts = GetoptLong.new(
|
41
34
|
["--debug", GetoptLong::NO_ARGUMENT],
|
42
|
-
["--dump", GetoptLong::NO_ARGUMENT],
|
43
35
|
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
|
36
|
+
["--patch", GetoptLong::REQUIRED_ARGUMENT],
|
44
37
|
["--progress", GetoptLong::NO_ARGUMENT],
|
45
|
-
["--sse", GetoptLong::NO_ARGUMENT],
|
46
38
|
["--to-sse", GetoptLong::NO_ARGUMENT],
|
47
39
|
["--validate", GetoptLong::NO_ARGUMENT],
|
48
40
|
["--verbose", GetoptLong::NO_ARGUMENT],
|
49
41
|
["--help", "-?", GetoptLong::NO_ARGUMENT]
|
50
42
|
)
|
51
43
|
|
52
|
-
options = {
|
53
|
-
graph: RDF::Repository.new,
|
54
|
-
}
|
55
|
-
|
56
|
-
input = nil
|
44
|
+
options = {}
|
57
45
|
|
58
46
|
opts.each do |opt, arg|
|
59
47
|
case opt
|
60
|
-
when '--
|
61
|
-
when '--
|
62
|
-
when '--execute'
|
63
|
-
when '--
|
64
|
-
when '--
|
65
|
-
when '--to-sse'
|
66
|
-
when '--validate'
|
67
|
-
when '--verbose'
|
48
|
+
when '--base' then options[:base_uri] = arg
|
49
|
+
when '--debug' then options[:debug] = true
|
50
|
+
when '--execute' then options[:patch] = arg
|
51
|
+
when '--patch' then options[:patch] = RDF::Util::File.open_file(arg).read
|
52
|
+
when '--progress' then options[:debug] ||= 2
|
53
|
+
when '--to-sse' then options[:to_sse] = true
|
54
|
+
when '--validate' then options[:validate] = true
|
55
|
+
when '--verbose' then options[:verbose] = true
|
68
56
|
when "--help"
|
69
|
-
puts "Usage: #{$0} [options] file-or-uri ..."
|
57
|
+
puts "Usage: #{$0} [options] target graph file-or-uri ..."
|
70
58
|
puts "Options:"
|
71
|
-
puts " --
|
72
|
-
puts " --
|
73
|
-
puts " --
|
74
|
-
puts " --
|
75
|
-
puts " --
|
76
|
-
puts " --
|
77
|
-
puts " --
|
59
|
+
puts " --base: Base URI of target graph, if different from graph location"
|
60
|
+
puts " --debug: Display detailed debug output"
|
61
|
+
puts " --execute,-e: Use option argument as the patch input"
|
62
|
+
puts " --patch: Location of patch document"
|
63
|
+
puts " --progress Display parse tree"
|
64
|
+
puts " --to-sse: Generate SSE for patch instead of running query"
|
65
|
+
puts " --validate: Validate patch document"
|
66
|
+
puts " --verbose: Display details of processing"
|
67
|
+
puts " --help,-?: This message"
|
78
68
|
exit(0)
|
79
69
|
end
|
80
70
|
end
|
81
71
|
|
72
|
+
raise "No patch defined" unless options[:patch]
|
82
73
|
if ARGV.empty?
|
83
|
-
|
84
|
-
run(s, options)
|
74
|
+
run(RDF::Graph.new, options)
|
85
75
|
else
|
86
76
|
ARGV.each do |test_file|
|
87
|
-
puts "
|
88
|
-
run(RDF::
|
77
|
+
puts "patch #{test_file}"
|
78
|
+
run(RDF::Graph.load(test_file), options.merge(base_uri: RDF::URI(test_file)))
|
89
79
|
end
|
90
80
|
end
|
91
81
|
puts
|
data/lib/ld/patch.rb
CHANGED
@@ -23,8 +23,10 @@ module LD
|
|
23
23
|
#
|
24
24
|
# @param [IO, StringIO, String, #to_s] input
|
25
25
|
# @param [Hash{Symbol => Object}] options
|
26
|
-
# @
|
27
|
-
#
|
26
|
+
# @option options [#to_s] :base_uri (nil)
|
27
|
+
# the base URI to use when resolving relative URIs
|
28
|
+
# @option (see LD::Patch::Parser#initialize)
|
29
|
+
# @return [SPARQL::Algebra::Operator] The executable parsed Patch
|
28
30
|
def self.parse(input, options = {})
|
29
31
|
LD::Patch::Parser.new(input, options).parse
|
30
32
|
end
|
@@ -32,7 +32,7 @@ module LD::Patch::Algebra
|
|
32
32
|
# Bind variables to path
|
33
33
|
if var_or_iri.variable?
|
34
34
|
raise LD::Patch::Error("Operand uses unbound variable #{var_or_iri.inspect}", code: 400) unless solution.bound?(var_or_iri)
|
35
|
-
var_or_iri = solution[
|
35
|
+
var_or_iri = solution[var_or_iri]
|
36
36
|
end
|
37
37
|
|
38
38
|
list_heads = queryable.query(subject: var_or_iri, predicate: predicate).map {|s| s.object}
|
data/lib/ld/patch/parser.rb
CHANGED
@@ -383,7 +383,7 @@ module LD::Patch
|
|
383
383
|
#
|
384
384
|
# @param [Symbol, #to_s] prod The starting production for the parser.
|
385
385
|
# It may be a URI from the grammar, or a symbol representing the local_name portion of the grammar URI.
|
386
|
-
# @return [SPARQL::Algebra::Operator,
|
386
|
+
# @return [SPARQL::Algebra::Operator, Object]
|
387
387
|
# @raise [ParseError] when illegal grammar detected.
|
388
388
|
def parse(prod = START)
|
389
389
|
ll1_parse(@input, prod.to_sym, @options.merge(branch: BRANCH,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ld-patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregg Kellogg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdf
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '1.1'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.1.
|
22
|
+
version: 1.1.15
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '1.1'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.1.
|
32
|
+
version: 1.1.15
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: ebnf
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
267
|
version: '0'
|
268
268
|
requirements: []
|
269
269
|
rubyforge_project: ld-patch
|
270
|
-
rubygems_version: 2.4.
|
270
|
+
rubygems_version: 2.4.3
|
271
271
|
signing_key:
|
272
272
|
specification_version: 4
|
273
273
|
summary: W3C Linked Data Patch Format for RDF.rb.
|