rdf_context 0.5.8.1 → 0.5.8.2
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.
- data/History.rdoc +12 -1
- data/Rakefile +16 -14
- data/VERSION +1 -1
- data/bin/rdf_context +1 -1
- data/lib/rdf_context/conjunctive_graph.rb +22 -0
- data/lib/rdf_context/graph.rb +3 -1
- data/lib/rdf_context/n3parser.rb +1 -0
- data/lib/rdf_context/parser.rb +8 -11
- data/lib/rdf_context/rdfaparser.rb +36 -13
- data/lib/rdf_context/rdfxmlparser.rb +1 -1
- data/lib/rdf_context/serializer/abstract_serializer.rb +1 -1
- data/lib/rdf_context/serializer/turtle_serializer.rb +2 -2
- data/lib/rdf_context/serializer/xml_serializer.rb +1 -2
- data/spec/rdfa_parser_spec.rb +107 -1
- data/spec/xml_serializer_spec.rb +1 -1
- metadata +4 -4
data/History.rdoc
CHANGED
@@ -1,4 +1,15 @@
|
|
1
|
-
=== 0.5.8.
|
1
|
+
=== 0.5.8.2
|
2
|
+
* Don't create unnecessary namespaces when serializing RDF/XML.
|
3
|
+
* Don't use regexp to substitute base URI in URI serialization.
|
4
|
+
* Added :profile_graph option to RdfaParser#parse. This MUST be a ConjunctiveGraph and will be used to save profiles that are encountered.
|
5
|
+
* Fixme, for now, retrieval should include HTTP headers and perform appropriate HTTP cache control and check for potential updates.
|
6
|
+
* Added ConjunctiveGraph#add_quad. Adds a quad from the intended subject, predicate, object, and context.
|
7
|
+
@example
|
8
|
+
g = Graph.new
|
9
|
+
cg = ConjunctiveGraph.new
|
10
|
+
cg.add_quad(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new, g)
|
11
|
+
=> results in the triple being added to g
|
12
|
+
|
2
13
|
=== 0.5.8
|
3
14
|
* Remove dependency on whatlanguage.
|
4
15
|
* Added support for Processor Graphs.
|
data/Rakefile
CHANGED
@@ -69,22 +69,24 @@ task :spec => :check_dependencies
|
|
69
69
|
|
70
70
|
task :default => :spec
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
72
|
+
namespace :doc do
|
73
|
+
require 'rake/rdoctask'
|
74
|
+
Rake::RDocTask.new("rdoc") do |rdoc|
|
75
|
+
if File.exist?('VERSION')
|
76
|
+
version = File.read('VERSION')
|
77
|
+
else
|
78
|
+
version = RdfContext::VERSION
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
81
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
82
|
+
rdoc.title = "rdf_context #{version}"
|
83
|
+
rdoc.rdoc_files.include('README*', "History.rdoc")
|
84
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
85
|
+
end
|
85
86
|
|
86
|
-
YARD::Rake::YardocTask.new do |t|
|
87
|
-
|
87
|
+
YARD::Rake::YardocTask.new do |t|
|
88
|
+
t.files = %w(lib/**/*.rb README.rdoc History.rdoc) # optional
|
89
|
+
end
|
88
90
|
end
|
89
91
|
|
90
92
|
desc "Generate RDF Core Manifest.yml"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.8.
|
1
|
+
0.5.8.2
|
data/bin/rdf_context
CHANGED
@@ -15,7 +15,7 @@ class Parse
|
|
15
15
|
rescue RdfException => e
|
16
16
|
puts "Parse failure: #{e.message}"
|
17
17
|
puts parser.debug if $verbose && parser
|
18
|
-
|
18
|
+
raise if RdfContext.debug?
|
19
19
|
rescue Exception => e
|
20
20
|
puts "Parser fault: #{e.message}"
|
21
21
|
puts parser.debug if parser && !$quiet
|
@@ -42,6 +42,28 @@ module RdfContext
|
|
42
42
|
@store.triples(triple, nil, &block) || []
|
43
43
|
end
|
44
44
|
|
45
|
+
# Adds a quad from the intended subject, predicate, object, and context.
|
46
|
+
#
|
47
|
+
# @example
|
48
|
+
# g = Graph.new
|
49
|
+
# cg = ConjunctiveGraph.new
|
50
|
+
# cg.add_quad(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new, g)
|
51
|
+
# # => results in the triple being added to g
|
52
|
+
#
|
53
|
+
# @param [URIRef, BNode] subject the subject of the triple
|
54
|
+
# @param [URIRef] predicate the predicate of the triple
|
55
|
+
# @param [URIRef, BNode, Literal] object the object of the triple
|
56
|
+
# @param [Graph, URIRef] context Graph or URIRef of graph context
|
57
|
+
# @return [Graph] Returns the graph
|
58
|
+
# @raise [Error] Checks parameter types and raises if they are incorrect.
|
59
|
+
def add_quad(subject, predicate, object, context)
|
60
|
+
graph = context if context.is_a?(Graph)
|
61
|
+
graph ||= contexts.detect {|g| g.identifier == context}
|
62
|
+
graph ||= Graph.new(:identifier => context, :store => @store)
|
63
|
+
graph.add_triple(subject, predicate, object)
|
64
|
+
graph
|
65
|
+
end
|
66
|
+
|
45
67
|
# Parse source into a new context.
|
46
68
|
#
|
47
69
|
# Create a new context (Graph) and parse into that.
|
data/lib/rdf_context/graph.rb
CHANGED
@@ -214,7 +214,9 @@ module RdfContext
|
|
214
214
|
# Adds a triple to a graph directly from the intended subject, predicate, and object.
|
215
215
|
#
|
216
216
|
# @example
|
217
|
-
# g = Graph.new
|
217
|
+
# g = Graph.new
|
218
|
+
# g.add_triple(BNode.new, URIRef.new("http://xmlns.com/foaf/0.1/knows"), BNode.new)
|
219
|
+
# # => results in the triple being added to g
|
218
220
|
#
|
219
221
|
# @param [URIRef, BNode] subject the subject of the triple
|
220
222
|
# @param [URIRef] predicate the predicate of the triple
|
data/lib/rdf_context/n3parser.rb
CHANGED
@@ -15,6 +15,7 @@ module RdfContext
|
|
15
15
|
#
|
16
16
|
# @param [String] n3_str:: the Notation3/Turtle string
|
17
17
|
# @param [String] uri:: the URI of the document
|
18
|
+
# @option options [Graph] :graph (Graph.new) Graph to parse into, otherwise a new Graph instance is created
|
18
19
|
# @option options [Array] :debug (nil) Array to place debug messages
|
19
20
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
20
21
|
# @return [Graph]
|
data/lib/rdf_context/parser.rb
CHANGED
@@ -17,20 +17,18 @@ module RdfContext
|
|
17
17
|
# @return [RdfContext::Graph]
|
18
18
|
attr_accessor :graph
|
19
19
|
|
20
|
-
# Graph instance containing
|
20
|
+
# Graph instance containing informational, warning and error statements
|
21
21
|
# @return [RdfContext::Graph]
|
22
22
|
attr_accessor :processor_graph
|
23
23
|
|
24
24
|
##
|
25
25
|
# Creates a new parser
|
26
26
|
#
|
27
|
-
# @option options [Graph] :graph (nil) Graph to parse into, otherwise a new RdfContext::Graph instance is created
|
28
27
|
# @option options [Graph] :processor_graph (nil) Graph to record information, warnings and errors.
|
29
28
|
# @option options [:rdfxml, :html, :n3] :type (nil)
|
30
29
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
31
30
|
def initialize(options = {})
|
32
31
|
# initialize the triplestore
|
33
|
-
@graph = options[:graph]
|
34
32
|
@processor_graph = options[:processor_graph] if options[:processor_graph]
|
35
33
|
@debug = options[:debug] # XXX deprecated
|
36
34
|
@strict = options[:strict]
|
@@ -41,6 +39,7 @@ module RdfContext
|
|
41
39
|
#
|
42
40
|
# @param [#read, #to_s] stream the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
43
41
|
# @param [String] uri (nil) the URI of the document
|
42
|
+
# @option options [Graph] :graph (Graph.new) Graph to parse into, otherwise a new Graph instance is created
|
44
43
|
# @option options [Graph] :processor_graph (nil) Graph to record information, warnings and errors.
|
45
44
|
# @option options [:rdfxml, :html, :n3] :type (nil)
|
46
45
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
@@ -64,6 +63,7 @@ module RdfContext
|
|
64
63
|
#
|
65
64
|
# @param [#read, #to_s] stream the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
66
65
|
# @param [String] uri (nil) the URI of the document
|
66
|
+
# @option options [Graph] :graph (Graph.new) Graph to parse into, otherwise a new Graph instance is created
|
67
67
|
# @option options [Graph] :processor_graph (nil) Graph to record information, warnings and errors.
|
68
68
|
# @option options [:rdfxml, :html, :n3] :type (nil)
|
69
69
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
@@ -74,22 +74,21 @@ module RdfContext
|
|
74
74
|
# @return [Graph]:: Returns the graph containing parsed triples
|
75
75
|
# @raise [Error]:: Raises RdfError if _strict_
|
76
76
|
def parse(stream, uri = nil, options = {}, &block) # :yields: triple
|
77
|
+
@graph = options[:graph] || Graph.new(:identifier => @uri)
|
77
78
|
if self.class == Parser
|
78
79
|
|
79
80
|
options[:strict] ||= @strict if @strict
|
80
|
-
options[:graph] ||= @graph
|
81
|
+
options[:graph] ||= @graph
|
81
82
|
options[:debug] ||= @debug if @debug # XXX deprecated
|
82
|
-
@processor_graph = options[:processor_graph] if options[:processor_graph]
|
83
83
|
# Intuit type, if not provided
|
84
84
|
options[:type] ||= detect_format(stream, uri)
|
85
85
|
|
86
86
|
# Create a delegate of a specific parser class
|
87
87
|
@delegate ||= case options[:type].to_s
|
88
88
|
when "n3", "ntriples", "turtle", "ttl", "n3", "notation3" then N3Parser.new(options)
|
89
|
-
when "rdfa", "html", "xhtml"
|
90
|
-
when "xml", "rdf", "rdfxml"
|
91
|
-
else
|
92
|
-
RdfXmlParser.new(options)
|
89
|
+
when "rdfa", "html", "xhtml" then RdfaParser.new(options)
|
90
|
+
when "xml", "rdf", "rdfxml" then RdfXmlParser.new(options)
|
91
|
+
else RdfXmlParser.new(options)
|
93
92
|
# raise ParserException.new("type option must be one of :rdfxml, :html, or :n3")
|
94
93
|
end
|
95
94
|
@delegate.parse(stream, uri, options, &block)
|
@@ -98,8 +97,6 @@ module RdfContext
|
|
98
97
|
@uri = URIRef.new(uri.to_s) unless uri.nil?
|
99
98
|
@strict = options[:strict] if options.has_key?(:strict)
|
100
99
|
@debug = options[:debug] if options.has_key?(:debug)
|
101
|
-
|
102
|
-
@graph ||= Graph.new(:identifier => @uri)
|
103
100
|
end
|
104
101
|
end
|
105
102
|
|
@@ -33,6 +33,10 @@ module RdfContext
|
|
33
33
|
# @return [:rdfa_1_0, :rdfa_1_1]
|
34
34
|
attr_reader :version
|
35
35
|
|
36
|
+
# Graph instance containing parsed profiles
|
37
|
+
# @return [RdfContext::Graph]
|
38
|
+
attr_accessor :profile_graph
|
39
|
+
|
36
40
|
# The Recursive Baggage
|
37
41
|
# @private
|
38
42
|
class EvaluationContext # :nodoc:
|
@@ -136,11 +140,13 @@ module RdfContext
|
|
136
140
|
#
|
137
141
|
# @option options [Graph] :graph (nil) Graph to parse into, otherwise a new RdfContext::Graph instance is created
|
138
142
|
# @option options [Graph] :processor_graph (nil) Graph to record information, warnings and errors.
|
143
|
+
# @option options [Graph] :profile_graph (nil) Graph to save profile graphs.
|
139
144
|
# @option options [Array] :debug (nil) Array to place debug messages
|
140
145
|
# @option options [:rdfxml, :html, :n3] :type (nil)
|
141
146
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
142
147
|
def initialize(options = {})
|
143
148
|
super
|
149
|
+
@profile_graph = options[:profile_graph]
|
144
150
|
@@vocabulary_cache ||= {}
|
145
151
|
end
|
146
152
|
|
@@ -154,6 +160,9 @@ module RdfContext
|
|
154
160
|
#
|
155
161
|
# @param [Nokogiri::HTML::Document, Nokogiri::XML::Document, #read, #to_s] stream the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
156
162
|
# @param [String] uri (nil) the URI of the document
|
163
|
+
# @option options [Graph] :graph (Graph.new) Graph to parse into, otherwise a new Graph
|
164
|
+
# @option options [Graph] :processor_graph (nil) Graph to record information, warnings and errors.
|
165
|
+
# @option options [ConjunctiveGraph] :profile_graph (nil) Graph to save profile graphs.
|
157
166
|
# @option options [Array] :debug (nil) Array to place debug messages
|
158
167
|
# @option options [:rdfa_1_0, :rdfa_1_1] :version (:rdfa_1_1) Parser version information
|
159
168
|
# @option options [:xhtml] :host_language (:xhtml) Host Language
|
@@ -167,8 +176,8 @@ module RdfContext
|
|
167
176
|
|
168
177
|
@doc = case stream
|
169
178
|
when Nokogiri::HTML::Document then stream
|
170
|
-
when Nokogiri::XML::Document
|
171
|
-
else
|
179
|
+
when Nokogiri::XML::Document then stream
|
180
|
+
else Nokogiri::XML.parse(stream, uri.to_s)
|
172
181
|
end
|
173
182
|
|
174
183
|
add_error(nil, "Empty document", RDFA_NS.HostLanguageMarkupError) if @doc.nil?
|
@@ -201,6 +210,7 @@ module RdfContext
|
|
201
210
|
end
|
202
211
|
|
203
212
|
@host_defaults.delete(:vocabulary) if @version == :rdfa_1_0
|
213
|
+
@profile_graph ||= options[:profile_graph] if options.has_key?(:profile_graph)
|
204
214
|
|
205
215
|
add_debug(@doc.root, "version = #{@version.inspect}, host_language = #{@host_language}")
|
206
216
|
# parse
|
@@ -242,6 +252,30 @@ module RdfContext
|
|
242
252
|
add_debug(element, "process_profile: skip previously parsed profile <#{profile}>")
|
243
253
|
else
|
244
254
|
begin
|
255
|
+
p_graph = @profile_graph.contexts.detect {|g| g.identifier == profile} if @profile_graph
|
256
|
+
unless p_graph
|
257
|
+
add_debug(element, "process_profile: retrieve profile <#{profile}>")
|
258
|
+
# Fixme: Should using HTTP cache and conditional gets to make sure resource is up-to-date
|
259
|
+
prof_body = OpenURI.open_uri(profile)
|
260
|
+
raise ParserException, "Empty profile #{profile}" if prof_body.to_s.empty?
|
261
|
+
|
262
|
+
# Parse profile, and extract mappings from graph
|
263
|
+
add_debug(element, "process_profile: parse profile <#{profile}>")
|
264
|
+
old_debug, old_verbose, = ::RdfContext::debug?, $verbose
|
265
|
+
parse_options = {}
|
266
|
+
if @profile_graph
|
267
|
+
parse_options[:profile_graph] = @profile_graph
|
268
|
+
parse_options[:graph] = Graph.new(:identifier => profile, :store => @profile_graph.store)
|
269
|
+
end
|
270
|
+
|
271
|
+
::RdfContext::debug, $verbose = false, false
|
272
|
+
p_graph = Parser.parse(prof_body, profile, parse_options)
|
273
|
+
ttl = p_graph.serialize(:format => :ttl) if @debug || ::RdfContext::debug?
|
274
|
+
::RdfContext::debug, $verbose = old_debug, old_verbose
|
275
|
+
add_debug(element, ttl) if ttl
|
276
|
+
end
|
277
|
+
|
278
|
+
add_debug(element, "process_profile: extract mappings from <#{profile}>")
|
245
279
|
@@vocabulary_cache[profile] = {
|
246
280
|
:uri_mappings => {},
|
247
281
|
:term_mappings => {},
|
@@ -249,17 +283,6 @@ module RdfContext
|
|
249
283
|
}
|
250
284
|
um = @@vocabulary_cache[profile][:uri_mappings]
|
251
285
|
tm = @@vocabulary_cache[profile][:term_mappings]
|
252
|
-
add_debug(element, "process_profile: parse profile <#{profile}>")
|
253
|
-
prof_body = OpenURI.open_uri(profile)
|
254
|
-
raise ParserException, "Empty profile #{profile}" if prof_body.to_s.empty?
|
255
|
-
|
256
|
-
# Parse profile, and extract mappings from graph
|
257
|
-
old_debug, old_verbose, = ::RdfContext::debug?, $verbose
|
258
|
-
::RdfContext::debug, $verbose = false, false
|
259
|
-
p_graph = Parser.parse(prof_body, profile)
|
260
|
-
ttl = p_graph.serialize(:format => :ttl) if @debug || ::RdfContext::debug?
|
261
|
-
::RdfContext::debug, $verbose = old_debug, old_verbose
|
262
|
-
add_debug(element, ttl) if ttl
|
263
286
|
p_graph.subjects.each do |subject|
|
264
287
|
props = p_graph.properties(subject)
|
265
288
|
#puts props.inspect
|
@@ -36,7 +36,6 @@ module RdfContext
|
|
36
36
|
|
37
37
|
# @param [String] base Base URI for creating absolute URIs from relative URIs
|
38
38
|
# @param [Nokogiri::XML::Element] element XML Element context
|
39
|
-
# @param [Graph] graph Graph for binding Namespaces
|
40
39
|
# @return [RdfXmlParser::EvaluationContext]
|
41
40
|
def initialize(base, element, graph)
|
42
41
|
# Initialize the evaluation context, [5.1]
|
@@ -141,6 +140,7 @@ module RdfContext
|
|
141
140
|
#
|
142
141
|
# @param [Nokogiri::XML::Document, #read, #to_s] stream the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
|
143
142
|
# @param [String] uri (nil) the URI of the document
|
143
|
+
# @option options [Graph] :graph (Graph.new) Graph to parse into, otherwise a new Graph
|
144
144
|
# @option options [Array] :debug (nil) Array to place debug messages
|
145
145
|
# @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
|
146
146
|
# @return [Graph] Returns the graph containing parsed triples
|
@@ -39,10 +39,9 @@ module RdfContext
|
|
39
39
|
preprocess
|
40
40
|
|
41
41
|
predicates = @graph.predicates.uniq
|
42
|
-
possible = predicates + @graph.objects.uniq
|
43
42
|
namespaces = {}
|
44
43
|
required_namespaces = {}
|
45
|
-
|
44
|
+
predicates.each do |res|
|
46
45
|
next unless res.is_a?(URIRef)
|
47
46
|
if res.namespace
|
48
47
|
add_namespace(res.namespace)
|
data/spec/rdfa_parser_spec.rb
CHANGED
@@ -77,7 +77,6 @@ describe "RDFa parser" do
|
|
77
77
|
xml.should include("E = mc<sup xmlns=\"http://www.w3.org/1999/xhtml\">2</sup>: The Most Urgent Problem of Our Time")
|
78
78
|
end
|
79
79
|
|
80
|
-
|
81
80
|
it "should parse BNodes" do
|
82
81
|
sampledoc = <<-EOF
|
83
82
|
<?xml version="1.0" encoding="UTF-8"?>
|
@@ -108,6 +107,113 @@ describe "RDFa parser" do
|
|
108
107
|
xml.should include("Manu Sporny")
|
109
108
|
end
|
110
109
|
|
110
|
+
describe :profiles do
|
111
|
+
before(:all) do
|
112
|
+
@prof = %(<?xml version="1.0" encoding="UTF-8"?>
|
113
|
+
<!DOCTYPE html>
|
114
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
115
|
+
<head>
|
116
|
+
<title>Test mappings</title>
|
117
|
+
</head>
|
118
|
+
<body prefix="rdfa: http://www.w3.org/ns/rdfa#">
|
119
|
+
<p typeof=""><span property="rdfa:uri">#{DC_NS.uri}</span><span property="rdfa:prefix">dc</span></p>
|
120
|
+
<p typeof=""><span property="rdfa:uri">#{DC_NS.title}</span><span property="rdfa:term">title</span></p>
|
121
|
+
</body>
|
122
|
+
</html>
|
123
|
+
)
|
124
|
+
@doc = %(<?xml version="1.0" encoding="UTF-8"?>
|
125
|
+
<!DOCTYPE html>
|
126
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
127
|
+
<body profile="http://example.com/profile">
|
128
|
+
<div about ="http://example.com/doc" typeof="dc:Agent">
|
129
|
+
<p property="title">A particular agent</p>
|
130
|
+
</div>
|
131
|
+
</body>
|
132
|
+
</html>
|
133
|
+
)
|
134
|
+
end
|
135
|
+
|
136
|
+
before(:each) do
|
137
|
+
@profile_graph = ConjunctiveGraph.new(:store => MemoryStore.new)
|
138
|
+
@parser = RdfaParser.new(:profile_graph => @profile_graph)
|
139
|
+
OpenURI.stub!(:open_uri).with("http://example.com/profile").and_return(@prof)
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "new profile" do
|
143
|
+
before(:each) do
|
144
|
+
# Clear vocabulary cache
|
145
|
+
#RdfContext.debug = true
|
146
|
+
RdfaParser.send(:class_variable_set, :@@vocabulary_cache, {})
|
147
|
+
@parser.parse(@doc, "http://example.com/doc")
|
148
|
+
#RdfContext.debug = false
|
149
|
+
end
|
150
|
+
|
151
|
+
describe "profile graph" do
|
152
|
+
it "should have context http://example.com/profile" do
|
153
|
+
@profile_graph.contexts.map(&:identifier).should include("http://example.com/profile")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "processed graph" do
|
158
|
+
it "should have type dc:Agent" do
|
159
|
+
@parser.graph.should be_contains(Triple.new("http://example.com/doc", RDF_TYPE, DC_NS.Agent))
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should have property dc:title" do
|
163
|
+
@parser.graph.should be_contains(Triple.new("http://example.com/doc", DC_NS.title, nil))
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "cached profile" do
|
169
|
+
before(:each) do
|
170
|
+
# Clear vocabulary cache
|
171
|
+
RdfaParser.send(:class_variable_set, :@@vocabulary_cache, {})
|
172
|
+
@parser.parse(@doc, "http://example.com/doc")
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should not re-parse profile" do
|
176
|
+
RdfaParser.send(:class_variable_set, :@@vocabulary_cache, {})
|
177
|
+
Parser.should_not_receive(:parse).with(@prof, "http://example.com/profile", :profile_graph => @parser.profile_graph).and_return(@prof_graph)
|
178
|
+
RdfaParser.new.parse(@doc, "http://example.com/doc")
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should create vocab_cache" do
|
182
|
+
RdfaParser.send(:class_variable_get, :@@vocabulary_cache).should be_a(Hash)
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "profile content" do
|
188
|
+
before(:each) do
|
189
|
+
@prof_graph = Graph.new
|
190
|
+
bn_p = BNode.new("prefix")
|
191
|
+
bn_t = BNode.new("term")
|
192
|
+
@prof_graph.add(
|
193
|
+
Triple.new(bn_p, RDFA_NS.prefix_, "dc"),
|
194
|
+
Triple.new(bn_p, RDFA_NS.uri_, Literal.untyped(DC_NS.uri.to_s)),
|
195
|
+
Triple.new(bn_t, RDFA_NS.term_, "title"),
|
196
|
+
Triple.new(bn_t, RDFA_NS.uri_, Literal.untyped(DC_NS.title.to_s))
|
197
|
+
)
|
198
|
+
Parser.should_receive(:parse).with(@prof, "http://example.com/profile", :profile_graph => @profile_graph, :graph => instance_of(Graph)).and_return(@prof_graph)
|
199
|
+
|
200
|
+
# Clear vocabulary cache
|
201
|
+
RdfaParser.send(:class_variable_set, :@@vocabulary_cache, {})
|
202
|
+
#RdfContext.debug = true
|
203
|
+
@parser.parse(@doc, "http://example.com/doc")
|
204
|
+
#RdfContext.debug = false
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should have type dc:Agent" do
|
208
|
+
@parser.graph.should be_contains(Triple.new("http://example.com/doc", RDF_TYPE, DC_NS.Agent))
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should have property dc:title" do
|
212
|
+
@parser.graph.should be_contains(Triple.new("http://example.com/doc", DC_NS.title, nil))
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
111
217
|
def self.test_cases(suite)
|
112
218
|
RdfaHelper::TestCase.test_cases(suite)
|
113
219
|
end
|
data/spec/xml_serializer_spec.rb
CHANGED
@@ -357,7 +357,7 @@ describe "XML Serializer" do
|
|
357
357
|
doc.should be_a(Nokogiri::XML::Document)
|
358
358
|
paths.each_pair do |path, value|
|
359
359
|
puts "xpath: #{path.inspect}" if ::RdfContext::debug?
|
360
|
-
puts doc.root.at_xpath(path,
|
360
|
+
puts doc.root.at_xpath(path, doc.namespaces).inspect if ::RdfContext::debug?
|
361
361
|
case value
|
362
362
|
when false
|
363
363
|
doc.root.at_xpath(path, doc.namespaces).should be_nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdf_context
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 67
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
9
|
- 8
|
10
|
-
-
|
11
|
-
version: 0.5.8.
|
10
|
+
- 2
|
11
|
+
version: 0.5.8.2
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Gregg Kellogg
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-09-
|
19
|
+
date: 2010-09-11 00:00:00 -07:00
|
20
20
|
default_executable: rdf_context
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|