ld-patch 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eb0185c5e3d87a311c57b6460363bf5e479fd0a
4
- data.tar.gz: fd9772612616488a2ce9c595fa01ff3ebfff3879
3
+ metadata.gz: a82bb5a30058fd674000f4764eafb4671940af39
4
+ data.tar.gz: 65d86b62bb418c2437618ab376ab0a06859fc503
5
5
  SHA512:
6
- metadata.gz: 9a0aece9207a9d91d34706b19051f54c95934ca4cd017555eefda8aa0a032f1c2c4cbbddd4cdb2492ba966f3866e3ba8af30df806b420c8b76612a54d73b19d2
7
- data.tar.gz: 98914c762b9fc8152c5399727c374dce01364d9ce6416e829c1ca3c4fbef686ef6dc78b4558cf9ce917b6f7f22da560f064bf0d4f1d2e18951a487978eac760f
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.0
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(input, options = {})
13
+ def run(graph, options = {})
14
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"
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 ("\nPATCH:\n" + input)
20
+ puts ("\npatch:\n" + options[:patch])
22
21
  end
23
22
 
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
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(options[:graph], debug: options[:debug])
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 '--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
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 " --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"
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
- s = input ? input : $stdin.read
84
- run(s, options)
74
+ run(RDF::Graph.new, options)
85
75
  else
86
76
  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)))
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
- # @return [Object]
27
- # The parsed Patch
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[variable]
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}
@@ -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, Array]
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.0
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-23 00:00:00.000000000 Z
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.13
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.13
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.7
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.