rdf-n3 0.3.4.1 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/rdf-n3.gemspec DELETED
@@ -1,111 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{rdf-n3}
8
- s.version = "0.3.4.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Gregg Kellogg"]
12
- s.date = %q{2011-07-11}
13
- s.description = %q{RDF::N3 is an Notation-3 and Turtle reader/writer for the RDF.rb library suite.}
14
- s.email = %q{gregg@kellogg-assoc.com}
15
- s.extra_rdoc_files = [
16
- "AUTHORS",
17
- "History.md",
18
- "README.md",
19
- "UNLICENSE",
20
- "VERSION"
21
- ]
22
- s.files = [
23
- ".yardopts",
24
- "AUTHORS",
25
- "History.md",
26
- "README",
27
- "README.md",
28
- "Rakefile",
29
- "UNLICENSE",
30
- "VERSION",
31
- "example-files/arnau-registered-vocab.rb",
32
- "example-files/arnau-stack-overflow.ttl",
33
- "example-files/best-buy.nt",
34
- "example-files/dwbutler-mj.n3",
35
- "example-files/dwbutler-mj.ttl",
36
- "example-files/lee-reilly-list.rb",
37
- "example-files/recipe.ttl",
38
- "example-files/sp2b.n3",
39
- "example.rb",
40
- "lib/rdf/n3.rb",
41
- "lib/rdf/n3/format.rb",
42
- "lib/rdf/n3/patches/array_hacks.rb",
43
- "lib/rdf/n3/patches/graph_properties.rb",
44
- "lib/rdf/n3/reader.rb",
45
- "lib/rdf/n3/reader/bnf-rules.n3",
46
- "lib/rdf/n3/reader/meta.rb",
47
- "lib/rdf/n3/reader/n3-selectors.n3",
48
- "lib/rdf/n3/reader/n3.n3",
49
- "lib/rdf/n3/reader/parser.rb",
50
- "lib/rdf/n3/version.rb",
51
- "lib/rdf/n3/vocab.rb",
52
- "lib/rdf/n3/writer.rb",
53
- "rdf-n3.gemspec",
54
- "script/build_meta",
55
- "script/console",
56
- "script/parse",
57
- "script/tc",
58
- "script/yard-to-rubyforge",
59
- "spec/.gitignore",
60
- "spec/cwm_spec.rb",
61
- "spec/cwm_test.rb",
62
- "spec/format_spec.rb",
63
- "spec/matchers.rb",
64
- "spec/reader_spec.rb",
65
- "spec/spec.opts",
66
- "spec/spec_helper.rb",
67
- "spec/swap_spec.rb",
68
- "spec/swap_test.rb",
69
- "spec/turtle_spec.rb",
70
- "spec/turtle_test.rb",
71
- "spec/writer_spec.rb"
72
- ]
73
- s.homepage = %q{http://github.com/gkellogg/rdf-n3}
74
- s.require_paths = ["lib"]
75
- s.rubygems_version = %q{1.5.0}
76
- s.summary = %q{N3/Turtle reader/writer for RDF.rb.}
77
-
78
- if s.respond_to? :specification_version then
79
- s.specification_version = 3
80
-
81
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
- s.add_runtime_dependency(%q<rdf>, [">= 0.3.3"])
83
- s.add_development_dependency(%q<open-uri-cached>, [">= 0"])
84
- s.add_development_dependency(%q<spira>, [">= 0.0.12"])
85
- s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
86
- s.add_development_dependency(%q<rdf-spec>, [">= 0.3.3"])
87
- s.add_development_dependency(%q<rdf-rdfxml>, [">= 0.3.3"])
88
- s.add_development_dependency(%q<rdf-isomorphic>, [">= 0.3.4"])
89
- s.add_development_dependency(%q<yard>, [">= 0"])
90
- else
91
- s.add_dependency(%q<rdf>, [">= 0.3.3"])
92
- s.add_dependency(%q<open-uri-cached>, [">= 0"])
93
- s.add_dependency(%q<spira>, [">= 0.0.12"])
94
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
95
- s.add_dependency(%q<rdf-spec>, [">= 0.3.3"])
96
- s.add_dependency(%q<rdf-rdfxml>, [">= 0.3.3"])
97
- s.add_dependency(%q<rdf-isomorphic>, [">= 0.3.4"])
98
- s.add_dependency(%q<yard>, [">= 0"])
99
- end
100
- else
101
- s.add_dependency(%q<rdf>, [">= 0.3.3"])
102
- s.add_dependency(%q<open-uri-cached>, [">= 0"])
103
- s.add_dependency(%q<spira>, [">= 0.0.12"])
104
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
105
- s.add_dependency(%q<rdf-spec>, [">= 0.3.3"])
106
- s.add_dependency(%q<rdf-rdfxml>, [">= 0.3.3"])
107
- s.add_dependency(%q<rdf-isomorphic>, [">= 0.3.4"])
108
- s.add_dependency(%q<yard>, [">= 0"])
109
- end
110
- end
111
-
data/script/build_meta DELETED
@@ -1,249 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # build_meta --- generator of parser tables for SPARQL::Grammar::Parser
3
- # Derived from:
4
- # http://www.w3.org/2000/10/swap/grammar/predictiveParser.py
5
- # - predictiveParser.py, Tim Berners-Lee, 2004
6
- #
7
- require 'rubygems'
8
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
9
- require 'rdf/n3'
10
- require 'getoptlong'
11
-
12
- # Build rdf/n3/parser/meta.rb from http://www.w3.org/2000/10/swap/grammar/n3-selectors.n3
13
-
14
- class BNF < RDF::Vocabulary("http://www.w3.org/2000/10/swap/grammar/bnf#"); end
15
- class REGEX < RDF::Vocabulary("http://www.w3.org/2000/10/swap/grammar/regex#"); end
16
- class N3 < RDF::Vocabulary("http://www.w3.org/2000/10/swap/grammar/n3#"); end
17
-
18
- class PredictiveParser
19
- attr_accessor :already, :agenda, :errors, :literalTerminals, :branchTable, :tokenRegexps
20
- attr_accessor :graph
21
-
22
- def initialize
23
- @already = []
24
- @agenda = []
25
- @errors = []
26
- @literalTerminals = {}
27
- @branchTable = {}
28
- @tokenRegexps = {}
29
- end
30
-
31
- def parse(file)
32
- progress("Loading " + file)
33
- @graph = RDF::Graph.load(file)
34
- progress("Loaded #{@graph.count} statements.")
35
- end
36
-
37
- def recordError(str)
38
- errors << str
39
- "##### ERROR: #{str}"
40
- end
41
-
42
- def progress(str); puts(str); end
43
- def chatty(str); progress(str) if $verbose; end
44
-
45
- def runProduction(lhs)
46
- doProduction(lhs)
47
- while !@agenda.empty?
48
- x = @agenda.shift
49
- @already << x
50
- doProduction(x)
51
- end
52
-
53
- if !@errors.empty?
54
- progress("###### FAILED with #{errors.length} errors.")
55
- @errors.each {|s| progress(" #{s}")}
56
- exit(-2)
57
- else
58
- progress("Ok for predictive parsing")
59
- end
60
- end
61
-
62
- # Generate branch tables for one production
63
- def doProduction(lhs)
64
- if lhs == BNF.void
65
- progress("\nvoid")
66
- return
67
- end
68
- if lhs == BNF.eof
69
- progress( "\nEOF")
70
- return
71
- end
72
- if lhs.is_a?(RDF::Literal)
73
- literalTerminals[lhs.value()] = 1
74
- return
75
- end
76
-
77
- branchDict = {}
78
-
79
- rhs = graph.first_object(:subject => lhs, :predicate => BNF.matches)
80
- if rhs
81
- chatty("\nToken #{lhs} matches regexp #{rhs}")
82
- tokenRegexps[lhs] = rhs.value
83
-
84
- cc = graph.query(:subject => lhs, :predicate => BNF.canStartWith)
85
- progress(recordError("No record of what token #{lhs} can start with")) if cc.empty?
86
- cc.each {|statement| chatty(" Can start with: #{statement.object}")}
87
- return
88
- end
89
-
90
- rhs = graph.first_object(:subject => lhs, :predicate => BNF.mustBeOneSequence)
91
- unless rhs
92
- progress(recordError("No definition of #{lhs}"))
93
- # raise RuntimeError("No definition of %s in\n %s" %(`lhs`, `g`))
94
- return
95
- end
96
-
97
- options = rhs
98
- progress("\nProduction #{lhs} :: #{options}")
99
- graph.query(:subject => lhs, :predicate => BNF.canPrecede) do |statement|
100
- chatty(" Can precede '#{statement.object}'")
101
- end
102
-
103
- graph.query(:subject => lhs, :predicate => BNF.branch) do |statement|
104
- branch = statement.object
105
- sequence = graph.first_object(:subject => statement.object, :predicate => BNF.sequence)
106
- option = RDF::List.new(sequence, graph).to_a
107
- progress(" option: #{option}")
108
-
109
- option.each do |part|
110
- agenda << part unless already.include?(part) || agenda.include?(part)
111
- end
112
-
113
- conditions = graph.query(:subject => branch, :predicate => BNF.condition).map(&:object)
114
- if conditions.empty?
115
- progress(recordError("NO SELECTOR for #{lhs} option #{option}"))
116
- if option.empty?
117
- # Void case - the tricky one
118
- graph.pattern(:subject => lhs, :predicate => BNF.canPrecede) do |st|
119
- progress(" Can precede #{st.object}")
120
- end
121
- end
122
- end
123
-
124
- progress(" Conditions: #{conditions.to_a.map(&:to_s)}")
125
- conditions.each do |str1|
126
- if branchDict.has_key?(str1)
127
- progress(
128
- "Conflict: #{str1} is also the condition for #{branchDict[str1]}")
129
- end
130
- branchDict[str1] = option
131
- end
132
- end
133
-
134
- branchDict.keys.each do |str1|
135
- branchDict.keys.each do |str2|
136
- s1, s2 = str1.to_s, str2.to_s
137
- if (s1.index(s2) == 0 || s2.index(s1) == 0) && branchDict[str1] != branchDict[str2]
138
- progress("WARNING: for #{lhs}, #{str1} indicates #{branchDict[str1]}, but #{str2} indicates #{branchDict[str2]}")
139
- end
140
- end
141
- end
142
-
143
- branchTable[lhs] = branchDict
144
- end
145
-
146
- def litOrNot(value)
147
- (value.is_a?(RDF::Literal) ? "" : ":") + value.to_s.dump
148
- end
149
-
150
- def outputBranchTable(io, indent = 0)
151
- ind0 = ' ' * indent
152
- ind1 = ind0 + ' '
153
- ind2 = ind1 + ' '
154
- ind3 = ind2 + ' '
155
- io.puts "#{ind0}BRANCHES = {"
156
- branchTable.keys.sort_by(&:to_s).each do |prod|
157
- # Special case double, integer, and decimal to output just a numericliteral, due to a parser conflict
158
- next if prod.to_s =~ /numericliteral/
159
- io.puts "#{ind1}#{litOrNot(prod)} => {"
160
- branchTable[prod].keys.sort_by(&:to_s).each do |term|
161
- list = branchTable[prod][term].map {|t2| litOrNot(t2)}.join(",\n#{ind3}")
162
- io.puts "#{ind2}#{litOrNot(term)} => [#{list}],"
163
- end
164
- io.puts "#{ind1}},"
165
- end
166
- io.puts "#{ind0}}\n"
167
- end
168
-
169
- def outputRegexpTable(io, indent = 0)
170
- ind0 = ' ' * indent
171
- ind1 = ind0 + ' '
172
- io.puts "#{ind0}REGEXPS = {"
173
- tokenRegexps.keys.sort_by(&:to_s).each do |prod|
174
- # Special case double, integer, and decimal to output just a numericliteral, due to a parser conflict
175
- next if prod.to_s =~ /(integer|double|decimal)/
176
- io.puts "#{ind1}#{litOrNot(prod)} => Regexp.compile(" +
177
- case prod.to_s
178
- when /barename/ then %q(%(^[#{BARENAME_START}][#{BARENAME_TAIL}]*))
179
- when /explicituri/ then %q("^<[^>]*>")
180
- when /langcode/ then %q("^[a-zA-Z]+(-[a-zA-Z0-9]+)*")
181
- when /prefix/ then %q(%(^([#{BARENAME_START}][#{BARENAME_TAIL}]*)?:))
182
- when /qname/ then %q(%(^(([#{BARENAME_START}][#{BARENAME_TAIL}]*)?:)?([#{BARENAME_START}][#{BARENAME_TAIL}]*)?))
183
- when /variable/ then %q(%(^\\\\?[#{BARENAME_START}][#{BARENAME_TAIL}]*))
184
- else tokenRegexps[prod].dump
185
- end + "),"
186
- end
187
-
188
- io.puts "\n#{ind1}# Hack to replace integer|double|decimal with numericliteral"
189
- io.puts "#{ind1}#{litOrNot(N3.numericliteral)} => Regexp.compile(" + %q(%(^[-+]?[0-9]+(\\\\.[0-9]+)?(e[-+]?[0-9]+)?)) + ")"
190
- io.puts "#{ind0}}\n"
191
- end
192
- end
193
-
194
- $verbose = false
195
- $debug = false
196
- grammarFile = File.expand_path(File.join(File.dirname(__FILE__), "../lib/rdf/n3/reader/n3-selectors.n3"))
197
- start = N3.document
198
- output = STDOUT
199
-
200
- opts = GetoptLong.new(
201
- ["--debug", GetoptLong::NO_ARGUMENT],
202
- ["--verbose", GetoptLong::NO_ARGUMENT],
203
- ["--grammar", GetoptLong::REQUIRED_ARGUMENT],
204
- ["--start", GetoptLong::REQUIRED_ARGUMENT],
205
- ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
206
- ["--help", "-?", GetoptLong::NO_ARGUMENT]
207
- )
208
- opts.each do |opt, arg|
209
- case opt
210
- when '--verbose' then $verbose = true
211
- when '--debug' then $debug = true
212
- when '--grammar' then grammarFile = arg
213
- when '--as' then parseAs = arg
214
- when '--output' then output = File.open(arg, "w")
215
- when '--help'
216
- puts %(Usage: build_meta --grammar=file --as=uri [--output=file]
217
- --grammar=file This is the RDF augmented grammar
218
- --start=uri This is the URI of the production as which the document
219
- is to be parsed
220
- --output=file Where to save output
221
- )
222
- exit(0)
223
- end
224
- end
225
-
226
- pp = PredictiveParser.new
227
-
228
- pp.parse(grammarFile)
229
- pp.runProduction(start)
230
-
231
- unless output == STDOUT
232
- output.puts "# This file is automatically generated by #{__FILE__}"
233
- output.puts "# Branch and Regexp tables derived from #{grammarFile}"
234
- output.puts "module RDF::N3::Meta"
235
- end
236
- pp.outputBranchTable(output, 1)
237
- output.puts %q(
238
- if RUBY_VERSION >= "1.9.0"
239
- BARENAME_START = "A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\u{10000}-\u{effff}"
240
- BARENAME_TAIL = "0-9#{BARENAME_START}\u00b7\u0300-\u036f\u203f-\u2040\\\\-"
241
- else
242
- BARENAME_START = "A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\xff"
243
- BARENAME_TAIL = "0-9#{BARENAME_START}\xb7\\\\-"
244
- end
245
- )
246
- pp.outputRegexpTable(output, 1)
247
- unless output == STDOUT
248
- output.puts "end"
249
- end
data/script/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- RDF = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "rdf", "lib"))
7
- libs << " -I #{RDF}" if File.directory?(RDF)
8
- libs << " -r #{File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "rdf", "n3.rb")}"
9
- puts "Loading rdf-n3 gem"
10
- exec "#{irb} #{libs} --simple-prompt"
data/script/parse DELETED
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", 'lib')))
4
- require 'rdf/n3'
5
- require 'rdf/ntriples'
6
- require 'rdf/rdfxml' rescue nil
7
- require 'rdf/rdfa' rescue nil
8
- require 'getoptlong'
9
- require 'open-uri'
10
-
11
- def run(input, options)
12
- reader_class = RDF::Reader.for(options[:input_format].to_sym)
13
- raise "Reader not found for #{options[:input_format]}" unless reader_class
14
-
15
- prefixes = {}
16
- start = Time.new
17
- num = 0
18
- if options[:parse_only]
19
- include RDF::N3::Meta
20
- include RDF::N3::Parser
21
- puts "\nparse #{input.read}---\n\n" unless options[:quiet]
22
- input.rewind
23
- if options[:quiet]
24
- $stdout = StringIO.new
25
- end
26
- test(input, BRANCHES, REGEXPS)
27
- if options[:quiet]
28
- $stdout = STDOUT
29
- print "."
30
- end
31
- elsif options[:output_format] == :ntriples || options[:quiet]
32
- reader_class.new(input, :base_uri => options[:base_uri], :strict => true).each do |statement|
33
- num += 1
34
- if options[:quiet]
35
- #print "."
36
- else
37
- options[:output]. puts statement.to_ntriples
38
- end
39
- end
40
- elsif options[:output_format] == :inspect
41
- reader_class.new(input, :base_uri => options[:base_uri], :strict => true).each do |statement|
42
- num += 1
43
- options[:output].puts statement.inspect
44
- end
45
- else
46
- r = reader_class.new(input, :base_uri => options[:base_uri], :strict => true)
47
- g = RDF::Graph.new << r
48
- num = g.count
49
- options[:output].puts g.dump(options[:output_format], :base_uri => options[:base_uri], :prefixes => r.prefixes, :standard_prefixes => true)
50
- end
51
- puts
52
- secs = Time.new - start
53
- puts "Parsed #{num} statements in #{secs} seconds @ #{num/secs} statements/second."
54
- rescue
55
- fname = input.respond_to?(:path) ? input.path : "-stdin-"
56
- STDERR.puts("Error in #{fname}")
57
- raise
58
- end
59
-
60
- options = {
61
- :validate => false,
62
- :strict => true,
63
- :output => STDOUT,
64
- :output_format => :ntriples,
65
- :input_format => :n3,
66
- :base_uri => "http://example.com",
67
- }
68
- input = nil
69
-
70
- opts = GetoptLong.new(
71
- ["--dbg", GetoptLong::NO_ARGUMENT],
72
- ["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
73
- ["--format", GetoptLong::REQUIRED_ARGUMENT],
74
- ["--input-format", GetoptLong::REQUIRED_ARGUMENT],
75
- ["--output", "-o", GetoptLong::REQUIRED_ARGUMENT],
76
- ["--parse-only", GetoptLong::NO_ARGUMENT],
77
- ["--quiet", GetoptLong::NO_ARGUMENT],
78
- ["--uri", GetoptLong::REQUIRED_ARGUMENT],
79
- ["--verbose", GetoptLong::NO_ARGUMENT]
80
- )
81
- opts.each do |opt, arg|
82
- case opt
83
- when '--dbg' then ::RDF::N3::debug = true
84
- when '--execute' then input = arg
85
- when '--format' then options[:output_format] = arg.to_sym
86
- when '--input-format' then options[:input_format] = arg.to_sym
87
- when '--output' then options[:output] = File.open(arg, "w")
88
- when '--parse-only' then options[:parse_only] = true
89
- when '--quiet' then options[:quiet] = true
90
- when '--uri' then options[:base_uri] = arg
91
- when '--verbose' then $verbose = true
92
- end
93
- end
94
-
95
- if ARGV.empty?
96
- s = input ? input : $stdin.read
97
- run(StringIO.new(s), options)
98
- else
99
- ARGV.each do |test_file|
100
- run(Kernel.open(test_file), options)
101
- end
102
- end
103
- puts