rsinger-rdfobjects 0.1.3 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rdf_objects/curies.rb +62 -0
- data/lib/rdf_objects/data_types.rb +30 -0
- data/lib/rdf_objects/http_client.rb +54 -0
- data/lib/rdf_objects/parsers.rb +173 -0
- data/lib/rdf_objects/rdf_resource.rb +216 -0
- data/lib/rdf_objects/serializers.rb +7 -0
- data/lib/rdf_objects.rb +11 -0
- data/lib/xsl/RDFa2RDFXML.xsl +677 -0
- data/lib/xsl/rdf2nt.xsl +308 -0
- metadata +24 -13
data/lib/xsl/rdf2nt.xsl
ADDED
@@ -0,0 +1,308 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
|
3
|
+
<!-- RDFT 2.0 by Jason Diamond <http://injektilo.org/>
|
4
|
+
|
|
5
|
+
| Transforms RDF/XML into N-Triples. See <http://www.w3.org/TR/rdf-syntax-grammar>
|
6
|
+
| and <http://www.w3.org/TR/rdf-testcases/#ntriples> for more information.
|
7
|
+
|
|
8
|
+
| This version requires that all RDF attributes be qualified!
|
9
|
+
|
|
10
|
+
| Specify the base-uri parameter as the URI for the source document in
|
11
|
+
| order to resolve relative URIs (currently just rdf:ID attributes).
|
12
|
+
|
|
13
|
+
| Import this transform and override the output-statement and
|
14
|
+
| output-literal-statement named templates to create your own output
|
15
|
+
| formats.
|
16
|
+
|
|
17
|
+
| TODO:
|
18
|
+
|
|
19
|
+
| * Reification.
|
20
|
+
| * Correct URI resolution.
|
21
|
+
| * Fix bugs.
|
22
|
+
| * Track RDF Working Draft changes.
|
23
|
+
| * More helpful error checking.
|
24
|
+
| * Documentation.
|
25
|
+
| * More?
|
26
|
+
|
|
27
|
+
| HISTORY:
|
28
|
+
|
|
29
|
+
| 2002-01-02:
|
30
|
+
| * First Draft.
|
31
|
+
+-->
|
32
|
+
|
33
|
+
<xsl:transform version="1.0"
|
34
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
35
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
36
|
+
>
|
37
|
+
<xsl:output method="text" encoding="utf-8" />
|
38
|
+
|
39
|
+
<xsl:param name="base-uri" />
|
40
|
+
|
41
|
+
<xsl:template match="text()" />
|
42
|
+
<xsl:template match="text()" mode="node" />
|
43
|
+
<xsl:template match="text()" mode="property" />
|
44
|
+
|
45
|
+
<xsl:template match="rdf:RDF">
|
46
|
+
<xsl:apply-templates mode="node" />
|
47
|
+
</xsl:template>
|
48
|
+
|
49
|
+
<!-- node elements -->
|
50
|
+
|
51
|
+
<xsl:template match="*" mode="node">
|
52
|
+
<xsl:param name="subject" />
|
53
|
+
<xsl:param name="predicate" />
|
54
|
+
|
55
|
+
<xsl:variable name="id">
|
56
|
+
<xsl:choose>
|
57
|
+
<xsl:when test="@rdf:ID">
|
58
|
+
<xsl:value-of select="concat($base-uri, '#', @rdf:ID)" />
|
59
|
+
</xsl:when>
|
60
|
+
<xsl:when test="@rdf:about">
|
61
|
+
<xsl:value-of select="@rdf:about" />
|
62
|
+
</xsl:when>
|
63
|
+
<xsl:when test="@ID">
|
64
|
+
<xsl:message terminate="yes">error: encountered unqualified ID attribute!</xsl:message>
|
65
|
+
</xsl:when>
|
66
|
+
<xsl:when test="@about">
|
67
|
+
<xsl:message terminate="yes">error: encountered unqualified about attribute!</xsl:message>
|
68
|
+
</xsl:when>
|
69
|
+
<xsl:otherwise>
|
70
|
+
<xsl:value-of select="concat('_:', generate-id())" />
|
71
|
+
</xsl:otherwise>
|
72
|
+
</xsl:choose>
|
73
|
+
</xsl:variable>
|
74
|
+
|
75
|
+
<xsl:if test="not(self::rdf:Description)">
|
76
|
+
<xsl:call-template name="output-type-statement">
|
77
|
+
<xsl:with-param name="subject" select="$id" />
|
78
|
+
<xsl:with-param name="object">
|
79
|
+
<xsl:call-template name="check-li" />
|
80
|
+
</xsl:with-param>
|
81
|
+
</xsl:call-template>
|
82
|
+
</xsl:if>
|
83
|
+
|
84
|
+
<xsl:if test="$subject and $predicate">
|
85
|
+
<xsl:call-template name="output-statement">
|
86
|
+
<xsl:with-param name="subject" select="$subject" />
|
87
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
88
|
+
<xsl:with-param name="object" select="$id" />
|
89
|
+
</xsl:call-template>
|
90
|
+
</xsl:if>
|
91
|
+
|
92
|
+
<xsl:apply-templates select="@*" mode="property">
|
93
|
+
<xsl:with-param name="subject" select="$id" />
|
94
|
+
</xsl:apply-templates>
|
95
|
+
|
96
|
+
<xsl:apply-templates mode="property">
|
97
|
+
<xsl:with-param name="subject" select="$id" />
|
98
|
+
</xsl:apply-templates>
|
99
|
+
|
100
|
+
</xsl:template>
|
101
|
+
|
102
|
+
<!-- property elements -->
|
103
|
+
|
104
|
+
<xsl:template match="*[*]" mode="property">
|
105
|
+
<xsl:param name="subject" />
|
106
|
+
|
107
|
+
<xsl:variable name="predicate">
|
108
|
+
<xsl:call-template name="check-li" />
|
109
|
+
</xsl:variable>
|
110
|
+
|
111
|
+
<xsl:apply-templates mode="node">
|
112
|
+
<xsl:with-param name="subject" select="$subject" />
|
113
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
114
|
+
</xsl:apply-templates>
|
115
|
+
|
116
|
+
</xsl:template>
|
117
|
+
|
118
|
+
<xsl:template match="*[not(*)][text()]" mode="property">
|
119
|
+
<xsl:param name="subject" />
|
120
|
+
|
121
|
+
<xsl:variable name="predicate">
|
122
|
+
<xsl:call-template name="check-li" />
|
123
|
+
</xsl:variable>
|
124
|
+
|
125
|
+
<xsl:call-template name="output-literal-statement">
|
126
|
+
<xsl:with-param name="subject" select="$subject" />
|
127
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
128
|
+
<xsl:with-param name="object" select="." />
|
129
|
+
</xsl:call-template>
|
130
|
+
|
131
|
+
</xsl:template>
|
132
|
+
|
133
|
+
<xsl:template match="*[not(node())]" mode="property">
|
134
|
+
<xsl:param name="subject" />
|
135
|
+
|
136
|
+
<xsl:variable name="predicate">
|
137
|
+
<xsl:call-template name="check-li" />
|
138
|
+
</xsl:variable>
|
139
|
+
|
140
|
+
<xsl:choose>
|
141
|
+
|
142
|
+
<xsl:when test="not(@*) or (@rdf:ID and count(@*) = 1)">
|
143
|
+
<xsl:call-template name="output-literal-statement">
|
144
|
+
<xsl:with-param name="subject" select="$subject" />
|
145
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
146
|
+
<xsl:with-param name="object" select="''" />
|
147
|
+
</xsl:call-template>
|
148
|
+
</xsl:when>
|
149
|
+
|
150
|
+
<xsl:when test="@rdf:resource and count(@*) = 1">
|
151
|
+
<xsl:call-template name="output-statement">
|
152
|
+
<xsl:with-param name="subject" select="$subject" />
|
153
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
154
|
+
<xsl:with-param name="object" select="@rdf:resource" />
|
155
|
+
</xsl:call-template>
|
156
|
+
</xsl:when>
|
157
|
+
|
158
|
+
<xsl:otherwise>
|
159
|
+
<xsl:variable name="id">
|
160
|
+
<xsl:choose>
|
161
|
+
<xsl:when test="@rdf:resource">
|
162
|
+
<xsl:value-of select="@rdf:resource" />
|
163
|
+
</xsl:when>
|
164
|
+
<xsl:when test="@rdf:ID">
|
165
|
+
<xsl:value-of select="concat($base-uri, '#', @rdf:ID)" />
|
166
|
+
</xsl:when>
|
167
|
+
<xsl:otherwise>
|
168
|
+
<xsl:value-of select="concat('_:', generate-id())" />
|
169
|
+
</xsl:otherwise>
|
170
|
+
</xsl:choose>
|
171
|
+
</xsl:variable>
|
172
|
+
<xsl:variable name="property-attributes">
|
173
|
+
<xsl:apply-templates select="@*" mode="property">
|
174
|
+
<xsl:with-param name="subject" select="$id" />
|
175
|
+
</xsl:apply-templates>
|
176
|
+
</xsl:variable>
|
177
|
+
<xsl:if test="$property-attributes">
|
178
|
+
<xsl:call-template name="output-statement">
|
179
|
+
<xsl:with-param name="subject" select="$subject" />
|
180
|
+
<xsl:with-param name="predicate" select="$predicate" />
|
181
|
+
<xsl:with-param name="object" select="$id" />
|
182
|
+
</xsl:call-template>
|
183
|
+
<xsl:copy-of select="$property-attributes" />
|
184
|
+
</xsl:if>
|
185
|
+
</xsl:otherwise>
|
186
|
+
|
187
|
+
</xsl:choose>
|
188
|
+
|
189
|
+
</xsl:template>
|
190
|
+
|
191
|
+
<!-- property attributes -->
|
192
|
+
|
193
|
+
<xsl:template match="@rdf:RDF" mode="property" />
|
194
|
+
<xsl:template match="@rdf:Description" mode="property" />
|
195
|
+
<xsl:template match="@rdf:ID" mode="property" />
|
196
|
+
<xsl:template match="@rdf:about" mode="property" />
|
197
|
+
<xsl:template match="@rdf:bagID" mode="property" />
|
198
|
+
<xsl:template match="@rdf:parseType" mode="property" />
|
199
|
+
<xsl:template match="@rdf:resource" mode="property" />
|
200
|
+
<xsl:template match="@rdf:li" mode="property" />
|
201
|
+
|
202
|
+
<xsl:template match="@rdf:type" mode="property">
|
203
|
+
<xsl:param name="subject" />
|
204
|
+
|
205
|
+
<xsl:call-template name="output-type-statement">
|
206
|
+
<xsl:with-param name="subject" select="$subject" />
|
207
|
+
<xsl:with-param name="object" select="." />
|
208
|
+
</xsl:call-template>
|
209
|
+
|
210
|
+
</xsl:template>
|
211
|
+
|
212
|
+
<xsl:template match="@*" mode="property">
|
213
|
+
<xsl:param name="subject" />
|
214
|
+
|
215
|
+
<xsl:call-template name="output-literal-statement">
|
216
|
+
<xsl:with-param name="subject" select="$subject" />
|
217
|
+
<xsl:with-param name="predicate" select="concat(namespace-uri(), local-name())" />
|
218
|
+
<xsl:with-param name="object" select="." />
|
219
|
+
</xsl:call-template>
|
220
|
+
|
221
|
+
</xsl:template>
|
222
|
+
|
223
|
+
<!-- helper templates -->
|
224
|
+
|
225
|
+
<xsl:template name="check-li">
|
226
|
+
|
227
|
+
<xsl:variable name="id" select="concat(namespace-uri(), local-name())" />
|
228
|
+
|
229
|
+
<xsl:choose>
|
230
|
+
<xsl:when test="$id = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#li'">
|
231
|
+
<xsl:value-of select="concat('http://www.w3.org/1999/02/22-rdf-syntax-ns#_', 1 + count(preceding-sibling::rdf:li))" />
|
232
|
+
</xsl:when>
|
233
|
+
<xsl:otherwise>
|
234
|
+
<xsl:value-of select="$id" />
|
235
|
+
</xsl:otherwise>
|
236
|
+
</xsl:choose>
|
237
|
+
|
238
|
+
</xsl:template>
|
239
|
+
|
240
|
+
<xsl:template name="output-type-statement">
|
241
|
+
<xsl:param name="subject" />
|
242
|
+
<xsl:param name="object" />
|
243
|
+
|
244
|
+
<xsl:call-template name="output-statement">
|
245
|
+
<xsl:with-param name="subject" select="$subject" />
|
246
|
+
<xsl:with-param name="predicate" select="'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'" />
|
247
|
+
<xsl:with-param name="object" select="$object" />
|
248
|
+
</xsl:call-template>
|
249
|
+
|
250
|
+
</xsl:template>
|
251
|
+
|
252
|
+
<xsl:template name="output-statement">
|
253
|
+
<xsl:param name="subject" />
|
254
|
+
<xsl:param name="predicate" />
|
255
|
+
<xsl:param name="object" />
|
256
|
+
|
257
|
+
<xsl:if test="not(starts-with($subject, '_:'))">
|
258
|
+
<xsl:text><</xsl:text>
|
259
|
+
</xsl:if>
|
260
|
+
|
261
|
+
<xsl:value-of select="$subject" />
|
262
|
+
|
263
|
+
<xsl:if test="not(starts-with($subject, '_:'))">
|
264
|
+
<xsl:text>></xsl:text>
|
265
|
+
</xsl:if>
|
266
|
+
|
267
|
+
<xsl:text> <</xsl:text>
|
268
|
+
<xsl:value-of select="$predicate" />
|
269
|
+
<xsl:text>> </xsl:text>
|
270
|
+
|
271
|
+
<xsl:if test="not(starts-with($object, '_:'))">
|
272
|
+
<xsl:text><</xsl:text>
|
273
|
+
</xsl:if>
|
274
|
+
|
275
|
+
<xsl:value-of select="$object" />
|
276
|
+
|
277
|
+
<xsl:if test="not(starts-with($object, '_:'))">
|
278
|
+
<xsl:text>></xsl:text>
|
279
|
+
</xsl:if>
|
280
|
+
|
281
|
+
<xsl:text> . </xsl:text>
|
282
|
+
|
283
|
+
</xsl:template>
|
284
|
+
|
285
|
+
<xsl:template name="output-literal-statement">
|
286
|
+
<xsl:param name="subject" />
|
287
|
+
<xsl:param name="predicate" />
|
288
|
+
<xsl:param name="object" />
|
289
|
+
|
290
|
+
<xsl:if test="not(starts-with($subject, '_:'))">
|
291
|
+
<xsl:text><</xsl:text>
|
292
|
+
</xsl:if>
|
293
|
+
|
294
|
+
<xsl:value-of select="$subject" />
|
295
|
+
|
296
|
+
<xsl:if test="not(starts-with($subject, '_:'))">
|
297
|
+
<xsl:text>></xsl:text>
|
298
|
+
</xsl:if>
|
299
|
+
|
300
|
+
<xsl:text> <</xsl:text>
|
301
|
+
<xsl:value-of select="$predicate" />
|
302
|
+
<xsl:text>> "</xsl:text>
|
303
|
+
<xsl:value-of select="$object" />
|
304
|
+
<xsl:text>" . </xsl:text>
|
305
|
+
|
306
|
+
</xsl:template>
|
307
|
+
|
308
|
+
</xsl:transform>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsinger-rdfobjects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ross Singer
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08
|
12
|
+
date: 2009-09-08 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,29 +42,40 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: "0"
|
44
44
|
version:
|
45
|
-
description:
|
45
|
+
description: RDFObjects are intended to simplify working with RDF data by providing a (more) Ruby-like interface to resources (thanks to OpenStruct).
|
46
46
|
email: rossfsinger@gmail.com
|
47
47
|
executables: []
|
48
48
|
|
49
49
|
extensions: []
|
50
50
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
53
|
-
files:
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
54
53
|
- README
|
54
|
+
files:
|
55
55
|
- LICENSE
|
56
|
-
|
56
|
+
- README
|
57
|
+
- lib/rdf_objects.rb
|
58
|
+
- lib/rdf_objects/curies.rb
|
59
|
+
- lib/rdf_objects/data_types.rb
|
60
|
+
- lib/rdf_objects/http_client.rb
|
61
|
+
- lib/rdf_objects/parsers.rb
|
62
|
+
- lib/rdf_objects/rdf_resource.rb
|
63
|
+
- lib/rdf_objects/serializers.rb
|
64
|
+
- lib/xsl/RDFa2RDFXML.xsl
|
65
|
+
- lib/xsl/rdf2nt.xsl
|
66
|
+
has_rdoc: false
|
57
67
|
homepage: http://github.com/rsinger/RDFObjects/tree
|
68
|
+
licenses:
|
58
69
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
61
72
|
require_paths:
|
62
73
|
- lib
|
63
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
75
|
requirements:
|
65
76
|
- - ">="
|
66
77
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
78
|
+
version: "0"
|
68
79
|
version:
|
69
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
81
|
requirements:
|
@@ -75,9 +86,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
86
|
requirements: []
|
76
87
|
|
77
88
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.
|
89
|
+
rubygems_version: 1.3.5
|
79
90
|
signing_key:
|
80
|
-
specification_version:
|
81
|
-
summary:
|
91
|
+
specification_version: 3
|
92
|
+
summary: A DSL for working with RDF resources.
|
82
93
|
test_files: []
|
83
94
|
|