@@ -10,82 +10,72 @@ rescue LoadError
1010end
1111require 'getoptlong'
1212
13- def run ( input , options = { } )
13+ def run ( graph , options = { } )
1414 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 "
1717 end
18- options [ :graph ] ||= RDF ::Graph . new
1918
2019 if options [ :verbose ]
21- puts ( "\n PATCH :\n " + input )
20+ puts ( "\n patch :\n " + options [ :patch ] )
2221 end
2322
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 )
3024
3125 puts ( "\n SSE:\n " + patch . to_sse ) if options [ :debug ] || options [ :to_sse ]
3226
3327 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 )
3629 puts res . dump ( :ttl , base_uri : patch . base_uri , prefixes : patch . prefixes , standard_prefixes : true )
3730 end
3831end
3932
4033opts = GetoptLong . new (
4134 [ "--debug" , GetoptLong ::NO_ARGUMENT ] ,
42- [ "--dump" , GetoptLong ::NO_ARGUMENT ] ,
4335 [ "--execute" , "-e" , GetoptLong ::REQUIRED_ARGUMENT ] ,
36+ [ "--patch" , GetoptLong ::REQUIRED_ARGUMENT ] ,
4437 [ "--progress" , GetoptLong ::NO_ARGUMENT ] ,
45- [ "--sse" , GetoptLong ::NO_ARGUMENT ] ,
4638 [ "--to-sse" , GetoptLong ::NO_ARGUMENT ] ,
4739 [ "--validate" , GetoptLong ::NO_ARGUMENT ] ,
4840 [ "--verbose" , GetoptLong ::NO_ARGUMENT ] ,
4941 [ "--help" , "-?" , GetoptLong ::NO_ARGUMENT ]
5042)
5143
52- options = {
53- graph : RDF ::Repository . new ,
54- }
55-
56- input = nil
44+ options = { }
5745
5846opts . each do |opt , arg |
5947 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
6856 when "--help"
69- puts "Usage: #{ $0} [options] file-or-uri ..."
57+ puts "Usage: #{ $0} [options] target graph file-or-uri ..."
7058 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"
7868 exit ( 0 )
7969 end
8070end
8171
72+ raise "No patch defined" unless options [ :patch ]
8273if ARGV . empty?
83- s = input ? input : $stdin. read
84- run ( s , options )
74+ run ( RDF ::Graph . new , options )
8575else
8676 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 ) ) )
8979 end
9080end
9181puts
0 commit comments