iq_rdf 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/iq_rdf/predicate.rb +10 -2
- data/lib/iq_rdf/version.rb +1 -1
- data/test/xml_test.rb +64 -46
- metadata +3 -8
data/lib/iq_rdf/predicate.rb
CHANGED
@@ -23,11 +23,19 @@ module IqRdf
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def build_xml(xml)
|
26
|
-
raise "XML Output won't work with full URIs as predicates yet" unless namespace.token # There is a dummy_empty_namespace without token => postfix is a full uri!
|
27
26
|
nodes.each do |node|
|
28
27
|
node.build_xml(xml) do |*args|
|
29
28
|
block = args.pop if args.last.is_a?(Proc)
|
30
|
-
params = namespace.token
|
29
|
+
params = if namespace.token.nil? # Full uri
|
30
|
+
nameStartChar = "[A-Z]|_|[a-z]|[\u{00C0}-\u{00D6}]|[\u{00D8}-\u{00F6}]|[\u{00F8}-\u{02FF}]|[\u{0370}-\u{037D}]|[\u{037F}-\u{1FFF}]|[\u{200C}-\u{200D}]|[\u{2070}-\u{218F}]|[\u{2C00}-\u{2FEF}]|[\u{3001}-\u{D7FF}]|[\u{F900}-\u{FDCF}]|[\u{FDF0}-\u{FFFD}]|[\u{10000}-\u{EFFFF}]"
|
31
|
+
name = Regexp.new("^(.*?)((#{nameStartChar})(#{nameStartChar}|-|[0-9]|\u{00B7}|[\u{0300}-\u{036F}]|[\u{203F}-\u{2040}])*)$")
|
32
|
+
unless matches = name.match(self.uri_postfix.to_s)
|
33
|
+
raise "Coudln't extract namespace and postfix from URI '#{self.uri_postfix}'"
|
34
|
+
end
|
35
|
+
["ns0", matches[2].to_sym, {"xmlns:ns0" => matches[1]}]
|
36
|
+
else
|
37
|
+
namespace.token == :default ? [self.uri_postfix.to_s] : [namespace.token.to_s, self.uri_postfix.to_sym]
|
38
|
+
end
|
31
39
|
params += args
|
32
40
|
params << {"xml:lang" => xml_lang} if xml_lang
|
33
41
|
if block
|
data/lib/iq_rdf/version.rb
CHANGED
data/test/xml_test.rb
CHANGED
@@ -54,40 +54,40 @@ rdf
|
|
54
54
|
<sometest>testvalue</sometest>
|
55
55
|
</rdf:Description>
|
56
56
|
rdf
|
57
|
-
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
def test_complex_features
|
60
|
+
document = IqRdf::Document.new('http://www.umweltprobenbank.de/', :lang => :de)
|
61
61
|
|
62
|
-
|
62
|
+
document.namespaces :skos => 'http://www.w3.org/2008/05/skos#', :foaf => 'http://xmlns.com/foaf/0.1/', :upb => 'http://www.upb.de/'
|
63
63
|
|
64
|
-
|
64
|
+
document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en) # :testemann :myCustomNote "This is an example"@en.
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
document << IqRdf::testemann(IqRdf::Foaf::build_uri("Person")).Foaf::name("Heinz Peter Testemann", :lang => :none) # :testemann a foaf:Person; foaf:name "Heinz Peter Testemann" .
|
67
|
+
document << IqRdf::testemann.Foaf::knows(IqRdf::testefrau) # :testemann foaf:knows :testefrau .
|
68
|
+
document << IqRdf::testemann.Foaf::nick("Crash test dummy") # :testemann foaf:nick "Crash test dummy"@de .
|
69
69
|
|
70
|
-
|
70
|
+
document << IqRdf::testemann.testIt([IqRdf::hello, "bla"]) # :testIt (:hallo :goodbye "bla"@de), "blubb"@de; # XML: rdf:list
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
["u1023", "xkfkrl"].each do |id|
|
73
|
+
document << IqRdf::Upb::build_uri(id, IqRdf::Skos::build_uri(:Concept)) do |doc| # upb:#{id} a skos:Concept;
|
74
|
+
doc.Skos::prefLabel("Test", :lang => :en) # skos:prefLabel "Test"@en;
|
75
|
+
doc.Skos::related(IqRdf::Rdf.anotherThing) # skos:related test:another_thing;
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
doc.test1("bla") # :test1 "bla"@de;
|
78
|
+
doc.testIt(:hello, :goodbye, "bla") # :testIt :hallo, :goodbye, "bla"@de;
|
79
|
+
doc.anotherTest(URI.parse("http://www.test.de/foo")) # :anotherTest <http://www.test.de/foo>;
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end # ]
|
81
|
+
end # .
|
82
|
+
end
|
83
|
+
document << IqRdf::Skos::testnode.test32 do |blank_node| # Blank nodes # skos:testnode :test32 [
|
84
|
+
blank_node.title("dies ist ein test") # :title "dies ist ein test"@de;
|
85
|
+
blank_node.sub do |subnode| # sub [
|
86
|
+
subnode.title("blubb") # title "blubb"
|
88
87
|
end # ]
|
88
|
+
end # ]
|
89
89
|
|
90
|
-
|
90
|
+
assert_match(<<rdf, document.to_xml)
|
91
91
|
<rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
|
92
92
|
<myCustomNote xml:lang="en">This is an example</myCustomNote>
|
93
93
|
</rdf:Description>
|
@@ -156,27 +156,27 @@ skos:testnode :test32 [
|
|
156
156
|
]
|
157
157
|
].
|
158
158
|
=end
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_literals
|
162
|
+
document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
|
163
|
+
document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
|
164
|
+
|
165
|
+
document << IqRdf::testemann do |t|
|
166
|
+
t.Foaf::knows(:testefrau)
|
167
|
+
t.Foaf.nick("Testy")
|
168
|
+
t.Foaf.lastname("Testemann", :lang => :none)
|
169
|
+
t.age(32)
|
170
|
+
t.married(false)
|
171
|
+
t.weight(65.8)
|
172
|
+
t.complex(IqRdf::Literal.new("A very complex type", nil, URI.parse("http://this.com/is#complex")))
|
173
|
+
t.complex2(IqRdf::Literal.new("Shorter form", nil, IqRdf::myDatatype))
|
174
|
+
t.quotes("\"I'm \\quoted\"")
|
175
|
+
t.line_breaks("I'm written\nover two lines")
|
176
|
+
t.some_literal(IqRdf::Literal.new("text", :de))
|
159
177
|
end
|
160
178
|
|
161
|
-
|
162
|
-
document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
|
163
|
-
document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
|
164
|
-
|
165
|
-
document << IqRdf::testemann do |t|
|
166
|
-
t.Foaf::knows(:testefrau)
|
167
|
-
t.Foaf.nick("Testy")
|
168
|
-
t.Foaf.lastname("Testemann", :lang => :none)
|
169
|
-
t.age(32)
|
170
|
-
t.married(false)
|
171
|
-
t.weight(65.8)
|
172
|
-
t.complex(IqRdf::Literal.new("A very complex type", nil, URI.parse("http://this.com/is#complex")))
|
173
|
-
t.complex2(IqRdf::Literal.new("Shorter form", nil, IqRdf::myDatatype))
|
174
|
-
t.quotes("\"I'm \\quoted\"")
|
175
|
-
t.line_breaks("I'm written\nover two lines")
|
176
|
-
t.some_literal(IqRdf::Literal.new("text", :de))
|
177
|
-
end
|
178
|
-
|
179
|
-
assert_match(<<rdf, document.to_xml)
|
179
|
+
assert_match(<<rdf, document.to_xml)
|
180
180
|
<rdf:Description rdf:about="http://www.test.de/testemann">
|
181
181
|
<foaf:knows rdf:resource="http://www.test.de/testefrau"/>
|
182
182
|
<foaf:nick>Testy</foaf:nick>
|
@@ -192,8 +192,26 @@ over two lines</line_breaks>
|
|
192
192
|
<some_literal xml:lang="de">text</some_literal>
|
193
193
|
</rdf:Description>
|
194
194
|
rdf
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_full_uri_predicates
|
198
|
+
assert_raise RuntimeError do
|
199
|
+
document = IqRdf::Document.new('http://www.test.de/')
|
200
|
+
document << IqRdf::testemann.build_full_uri_predicate(URI.parse("http://www.test.org/12"), 42)
|
201
|
+
document.to_xml
|
195
202
|
end
|
196
203
|
|
204
|
+
document = IqRdf::Document.new('http://www.test.de/')
|
205
|
+
|
206
|
+
document << IqRdf::testemann.build_full_uri_predicate(URI.parse("http://www.test.org/hoho"), 42)
|
207
|
+
|
208
|
+
assert_match(<<-rdf, document.to_xml)
|
209
|
+
<rdf:Description rdf:about="http://www.test.de/testemann">
|
210
|
+
<ns0:hoho xmlns:ns0="http://www.test.org/" rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">42</ns0:hoho>
|
211
|
+
</rdf:Description>
|
212
|
+
rdf
|
213
|
+
end
|
214
|
+
|
197
215
|
def test_blank_nodes
|
198
216
|
document = IqRdf::Document.new('http://www.test.de/')
|
199
217
|
|
@@ -204,7 +222,7 @@ rdf
|
|
204
222
|
subnode.title("blubb") # title "blubb"
|
205
223
|
end # ]
|
206
224
|
end # ]
|
207
|
-
assert_match(
|
225
|
+
assert_match(<<-rdf, document.to_xml)
|
208
226
|
<rdf:Description rdf:about=\"http://www.test.de/testnode\">
|
209
227
|
<test32>
|
210
228
|
<rdf:Description>
|
@@ -218,7 +236,7 @@ rdf
|
|
218
236
|
</rdf:Description>
|
219
237
|
</test32>
|
220
238
|
</rdf:Description>
|
221
|
-
rdf
|
239
|
+
rdf
|
222
240
|
end
|
223
241
|
|
224
|
-
|
242
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iq_rdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -106,18 +106,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- - ! '>='
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
hash: -3899584830229943406
|
112
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
110
|
none: false
|
114
111
|
requirements:
|
115
112
|
- - ! '>='
|
116
113
|
- !ruby/object:Gem::Version
|
117
114
|
version: '0'
|
118
|
-
segments:
|
119
|
-
- 0
|
120
|
-
hash: -3899584830229943406
|
121
115
|
requirements: []
|
122
116
|
rubyforge_project:
|
123
117
|
rubygems_version: 1.8.23
|
@@ -130,3 +124,4 @@ test_files:
|
|
130
124
|
- test/test_helper.rb
|
131
125
|
- test/turtle_test.rb
|
132
126
|
- test/xml_test.rb
|
127
|
+
has_rdoc:
|