rdf-rdfxml 1.1.0p0 → 1.1.0
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 +7 -0
- data/README.md +32 -23
- data/VERSION +1 -1
- data/lib/rdf/rdfxml/format.rb +5 -0
- data/lib/rdf/rdfxml/reader/nokogiri.rb +1 -0
- data/lib/rdf/rdfxml/reader.rb +7 -10
- data/lib/rdf/rdfxml/writer/haml_templates.rb +86 -0
- data/lib/rdf/rdfxml/writer.rb +256 -455
- data/lib/rdf/rdfxml.rb +0 -1
- metadata +47 -60
- data/lib/rdf/rdfxml/patches/array_hacks.rb +0 -53
- data/lib/rdf/rdfxml/patches/graph_properties.rb +0 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6998ff50cd28297520f5141f5b4bd06afc7208eb
|
4
|
+
data.tar.gz: 6b446b7d8d586debd5063f9a8e5c728c4f4a7e9e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 011b3251a3f25d692dc46bca35cfab75982e223b87904c6aac4d48628e7b9cace7afac59377a696a3921be52f60003a0f26b0581a3b1f4b57eb29c89c714a09e
|
7
|
+
data.tar.gz: 32ee1dc0dda497897e6e9d3aa1d1abe4030af232574233297d12f626d4c8d59fdf476cf2cca311d5bd9432f7909d507a009bf166c45b0c1b2160b2a3b525ed54
|
data/README.md
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
# RDF::RDFXML reader/writer
|
2
2
|
|
3
|
-
[RDF/XML][
|
3
|
+
[RDF/XML][] reader/writer for [RDF.rb][].
|
4
4
|
|
5
5
|
[](http://badge.fury.io/rb/rdf-rdfxml)
|
6
6
|
[](http://travis-ci.org/ruby-rdf/rdf-rdfxml)
|
7
7
|
|
8
8
|
## DESCRIPTION
|
9
9
|
|
10
|
-
RDF::RDFXML is an [RDF/XML][RDF/XML] reader/writer for Ruby using the [RDF.rb][RDF.rb] library suite.
|
10
|
+
RDF::RDFXML is an [RDF/XML][RDF/XML] reader/writer for [Ruby][] using the [RDF.rb][RDF.rb] library suite.
|
11
11
|
|
12
12
|
## FEATURES
|
13
|
-
RDF::RDFXML parses [RDF/XML][
|
13
|
+
RDF::RDFXML parses [RDF/XML][] into statements or triples and serializes triples, statements or graphs. It also serializes graphs to [RDF/XML][].
|
14
14
|
|
15
|
-
Fully compliant [RDF/XML][
|
15
|
+
Fully compliant [RDF/XML][] parser and serializer.
|
16
16
|
|
17
17
|
Install with `gem install rdf-rdfxml`
|
18
18
|
|
19
|
+
* 100% free and unencumbered [public domain](http://unlicense.org/) software.
|
20
|
+
* Implements a complete parser for [RDF/XML][].
|
21
|
+
* Compatible with Ruby >= 1.9.2.
|
22
|
+
|
19
23
|
## Usage:
|
20
24
|
Instantiate a parser and parse source, specifying type and base-URL
|
21
25
|
|
@@ -25,13 +29,22 @@ Instantiate a parser and parse source, specifying type and base-URL
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
Define `xml:base` and `xmlns` definitions, and use for serialization using `:base_uri` an `:prefixes` options.
|
33
|
+
|
34
|
+
Canonicalize and validate using `:canonicalize` and `:validate` options.
|
35
|
+
|
36
|
+
Write a graph to a file:
|
37
|
+
|
38
|
+
RDF::RDFXML::Writer.open("etc/test.ttl") do |writer|
|
39
|
+
writer << graph
|
40
|
+
end
|
41
|
+
|
28
42
|
## Dependencies
|
29
43
|
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 1.1)
|
30
|
-
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.
|
31
|
-
* Does not run properly on jRuby due to [Nokogiri][] issues.
|
44
|
+
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.6.0)
|
32
45
|
|
33
46
|
## Documentation
|
34
|
-
Full documentation available on [
|
47
|
+
Full documentation available on [Rubydoc.info][RDF/XML doc])
|
35
48
|
|
36
49
|
### Principle Classes
|
37
50
|
* {RDF::RDFXML}
|
@@ -42,22 +55,14 @@ Full documentation available on [RubyForge](http://rubydoc.info/github/ruby-rdf/
|
|
42
55
|
### Additional vocabularies
|
43
56
|
* {RDF::XML}
|
44
57
|
|
45
|
-
### Patches
|
46
|
-
* {Array}
|
47
|
-
* {RDF::Queryable}
|
48
|
-
* {Nokogiri::XML::Node}
|
49
|
-
|
50
58
|
## TODO
|
51
|
-
* Add support for LibXML and REXML bindings, and use the best available
|
52
59
|
* Consider a SAX-based parser for improved performance
|
53
|
-
* jRuby integration awaiting improvements in Nokogiri
|
54
60
|
|
55
61
|
## Resources
|
56
62
|
* [RDF.rb][RDF.rb]
|
57
63
|
* [RDF/XML][RDF/XML]
|
58
|
-
* [Distiller](http://
|
59
|
-
* [Documentation]
|
60
|
-
* [History](file:file.History.html)
|
64
|
+
* [Distiller](http://rdf.greggkellogg.net)
|
65
|
+
* [Documentation][RDF/XML doc]
|
61
66
|
* [RDF Tests](http://www.w3.org/2000/10/rdf-tests/rdfcore/allTestCases.html)
|
62
67
|
|
63
68
|
## Author
|
@@ -67,6 +72,7 @@ Full documentation available on [RubyForge](http://rubydoc.info/github/ruby-rdf/
|
|
67
72
|
* [Nicholas Humfrey](http://github.com/njh) - <http://njh.me/>
|
68
73
|
|
69
74
|
## Contributing
|
75
|
+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to mange development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
|
70
76
|
|
71
77
|
* Do your best to adhere to the existing coding conventions and idioms.
|
72
78
|
* Don't use hard tabs, and don't leave trailing whitespace on any line.
|
@@ -87,13 +93,16 @@ see <http://unlicense.org/> or the accompanying {file:UNLICENSE} file.
|
|
87
93
|
|
88
94
|
## FEEDBACK
|
89
95
|
|
90
|
-
* gregg@
|
96
|
+
* gregg@greggkellogg.net
|
91
97
|
* <http://rubygems.org/rdf-rdfxml>
|
92
98
|
* <http://github.com/ruby-rdf/rdf-rdfxml>
|
93
99
|
* <http://lists.w3.org/Archives/Public/public-rdf-ruby/>
|
94
100
|
|
95
|
-
[
|
96
|
-
[RDF
|
97
|
-
[
|
98
|
-
[
|
99
|
-
[
|
101
|
+
[Ruby]: http://ruby-lang.org/
|
102
|
+
[RDF]: http://www.w3.org/RDF/
|
103
|
+
[RDF.rb]: http://rubygems.org/gems/rdf
|
104
|
+
[RDF/XML]: http://www.w3.org/TR/REC-rdf-syntax/ "RDF/XML Syntax Specification"
|
105
|
+
[YARD]: http://yardoc.org/
|
106
|
+
[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
|
107
|
+
[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
|
108
|
+
[RDF/XML doc]: http://rubydoc.info/github/ruby-rdf/rdf-rdfxml/master/frames
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.0
|
data/lib/rdf/rdfxml/format.rb
CHANGED
@@ -215,6 +215,7 @@ module RDF::RDFXML
|
|
215
215
|
|
216
216
|
# Otherwise, default is utf-8
|
217
217
|
options[:encoding] ||= 'utf-8'
|
218
|
+
options[:encoding] = options[:encoding].to_s if options[:encoding]
|
218
219
|
|
219
220
|
::Nokogiri::XML.parse(input, base_uri.to_s, options[:encoding]) do |config|
|
220
221
|
config.noent
|
data/lib/rdf/rdfxml/reader.rb
CHANGED
@@ -76,13 +76,10 @@ module RDF::RDFXML
|
|
76
76
|
mappings = {}
|
77
77
|
|
78
78
|
# look for xmlns
|
79
|
-
element.namespaces.each do |
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
mappings[prefix] = attr_value
|
84
|
-
cb.call(prefix, attr_value) if block_given?
|
85
|
-
end
|
79
|
+
element.namespaces.each do |prefix, value|
|
80
|
+
value = base.join(value)
|
81
|
+
mappings[prefix] = value
|
82
|
+
cb.call(prefix, value) if block_given?
|
86
83
|
end
|
87
84
|
mappings
|
88
85
|
end
|
@@ -196,7 +193,7 @@ module RDF::RDFXML
|
|
196
193
|
ec = EvaluationContext.new(base_uri, root, @graph) do |prefix, value|
|
197
194
|
prefix(prefix, value)
|
198
195
|
end
|
199
|
-
|
196
|
+
|
200
197
|
nodeElement(root, ec)
|
201
198
|
else
|
202
199
|
rdf_nodes.each do |node|
|
@@ -204,10 +201,10 @@ module RDF::RDFXML
|
|
204
201
|
# XXX Skip this element if it's contained within another rdf:RDF element
|
205
202
|
|
206
203
|
# Extract base, lang and namespaces from parents to create proper evaluation context
|
207
|
-
ec = EvaluationContext.new(base_uri, nil, @graph)
|
204
|
+
ec = EvaluationContext.new(base_uri, nil, @graph)
|
205
|
+
ec.extract_from_ancestors(node) do |prefix, value|
|
208
206
|
prefix(prefix, value)
|
209
207
|
end
|
210
|
-
ec.extract_from_ancestors(node)
|
211
208
|
node.children.each {|el|
|
212
209
|
next unless el.elem?
|
213
210
|
raise "el must be a proxy not a #{el.class}" unless el.is_a?(@implementation::NodeProxy)
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Default HAML templates used for generating RDF/XML output from the writer
|
2
|
+
module RDF::RDFXML
|
3
|
+
class Writer
|
4
|
+
# The default set of HAML templates used for RDFa code generation
|
5
|
+
BASE_HAML = {
|
6
|
+
:identifier => "base",
|
7
|
+
# Document
|
8
|
+
# Locals: lang, title, prefix, base, subjects
|
9
|
+
# Yield: subjects.each
|
10
|
+
:doc => %q(
|
11
|
+
= %(<?xml version='1.0' encoding='utf-8' ?>)
|
12
|
+
- if stylesheet
|
13
|
+
= %(<?xml-stylesheet type="text/xsl" href="#{stylesheet}"?>)
|
14
|
+
%rdf:RDF{prefix_attrs.merge("xml:lang" => lang, "xml:base" => base)}
|
15
|
+
- subjects.each do |subject|
|
16
|
+
!= yield(subject)
|
17
|
+
),
|
18
|
+
|
19
|
+
# Output for non-leaf resources
|
20
|
+
# Note that @about may be omitted for Nodes that are not referenced
|
21
|
+
#
|
22
|
+
# If _rel_ and _resource_ are not nil, the tag will be written relative
|
23
|
+
# to a previous subject. If _element_ is :li, the tag will be written
|
24
|
+
# with <li> instead of <div>.
|
25
|
+
#
|
26
|
+
# Locals: subject, typeof, predicates, rel, element, inlist, attr_props
|
27
|
+
# Yield: predicates.each
|
28
|
+
:subject => %q(
|
29
|
+
- first_type, *types = typeof.to_s.split(' ')
|
30
|
+
- (types.unshift(first_type); first_type = nil) if first_type && (first_type.include?('/') || first_type.start_with?('_:'))
|
31
|
+
- first_type ||= get_qname(RDF.Description)
|
32
|
+
- first_type = first_type[1..-1] if first_type.to_s.start_with?(":")
|
33
|
+
- attr_props = attr_props.merge(get_qname(RDF.nodeID) => subject.id) if subject.node? && ref_count(subject) > 1
|
34
|
+
- attr_props = attr_props.merge(get_qname(RDF.about) => relativize(subject)) if subject.uri?
|
35
|
+
- haml_tag(first_type, attr_props) do
|
36
|
+
- types.each do |type|
|
37
|
+
- expanded_type = expand_curie(type)
|
38
|
+
- if expanded_type.start_with?('_:')
|
39
|
+
- haml_tag(get_qname(RDF.type), "rdf:nodeID" => expanded_type[2..-1])
|
40
|
+
-else
|
41
|
+
- haml_tag(get_qname(RDF.type), "rdf:resource" => expanded_type)
|
42
|
+
- predicates.each do |p|
|
43
|
+
= yield(p)
|
44
|
+
),
|
45
|
+
|
46
|
+
# Output for single-valued properties
|
47
|
+
# Locals: predicate, object, inlist
|
48
|
+
# Yields: object
|
49
|
+
# If nil is returned, render as a leaf
|
50
|
+
# Otherwise, render result
|
51
|
+
:property_value => %q(
|
52
|
+
- if res = yield(object)
|
53
|
+
- haml_tag(property) do
|
54
|
+
= res
|
55
|
+
- elsif object.literal? && object.datatype == RDF.XMLLiteral
|
56
|
+
- haml_tag(property, :"<", "rdf:parseType" => "Literal") do
|
57
|
+
= object.value
|
58
|
+
- elsif object.literal?
|
59
|
+
- haml_tag(property, :"<", "xml:lang" => object.language, "rdf:datatype" => (object.datatype unless object.plain?)) do
|
60
|
+
= object.value
|
61
|
+
- elsif object.node?
|
62
|
+
- haml_tag(property, :"/", "rdf:nodeID" => object.id)
|
63
|
+
- else
|
64
|
+
- haml_tag(property, :"/", "rdf:resource" => relativize(object))
|
65
|
+
),
|
66
|
+
|
67
|
+
# Outpust for a list
|
68
|
+
# Locals: predicate, list
|
69
|
+
# Yields: object
|
70
|
+
# If nil is returned, render as a leaf
|
71
|
+
# Otherwise, render result
|
72
|
+
:collection => %q(
|
73
|
+
- haml_tag(property, get_qname(RDF.parseType) => "Collection") do
|
74
|
+
- list.each do |object|
|
75
|
+
- if res = yield(object)
|
76
|
+
= res
|
77
|
+
- elsif object.node?
|
78
|
+
- haml_tag(get_qname(RDF.Description), :"/", "rdf:nodeID" => (object.id if ref_count(object) > 1))
|
79
|
+
- else
|
80
|
+
- haml_tag(get_qname(RDF.Description), :"/", "rdf:about" => relativize(object))
|
81
|
+
),
|
82
|
+
}
|
83
|
+
HAML_TEMPLATES = {:base => BASE_HAML}
|
84
|
+
DEFAULT_HAML = BASE_HAML
|
85
|
+
end
|
86
|
+
end
|