iq_rdf 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module ActionView::TemplateHandlers
16
+
17
+ class IqRdf < ActionView::TemplateHandler
18
+ include ActionView::TemplateHandlers::Compilable
19
+
20
+ def compile(template)
21
+ <<-EOV
22
+
23
+ document = IqRdf::Document.new()
24
+ #{template.source}
25
+ if params[:format].to_s == "ttl"
26
+ controller.response.headers["Content-Type"] ||= 'text/turtle'
27
+ document.to_turtle
28
+ elsif params[:format].to_s == "nt"
29
+ controller.response.headers["Content-Type"] ||= 'text/plain'
30
+ document.to_ntriples
31
+ elsif params[:format].to_s == "rdf"
32
+ controller.response.headers["Content-Type"] ||= 'application/xml+rdf'
33
+ document.to_xml
34
+ else # Default => turtle
35
+ controller.response.headers["Content-Type"] ||= 'text/turtle'
36
+ document.to_turtle
37
+ end
38
+ EOV
39
+ end
40
+ end
41
+
42
+ end
data/lib/iq_rdf/uri.rb ADDED
@@ -0,0 +1,69 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module IqRdf
16
+ class Uri < Node
17
+
18
+ attr_reader :namespace, :uri_postfix
19
+ attr_reader :rdf_type
20
+
21
+ def initialize(namespace, uri_postfix, rdf_type = nil, lang = nil)
22
+ raise "rdf_type has to be an IqRdf::Uri" unless rdf_type.nil? || rdf_type.is_a?(IqRdf::Uri)
23
+ @namespace = namespace
24
+ @uri_postfix = uri_postfix
25
+ @rdf_type = rdf_type
26
+ super(lang)
27
+ end
28
+
29
+ def full_uri(parent_lang = nil)
30
+ # URI::join etc won't work since uri_postfix has not to be a valid URI itself.
31
+ "#{self.namespace.uri_prefix.to_s}#{self.uri_postfix.to_s}"
32
+ end
33
+
34
+ def to_s(parent_lang = nil)
35
+ if namespace.token # There is a dummy_empty_namespace without token => postfix is a full uri!
36
+ "#{namespace.turtle_token}:#{self.uri_postfix.to_s}"
37
+ else
38
+ "<#{self.uri_postfix.to_s}>"
39
+ end
40
+ end
41
+
42
+ def is_subject?()
43
+ if (nodes.size > 0) # walk through the nodes: a blank node is an object (but has nodes)
44
+ nodes.each do |node|
45
+ return true unless node.is_a?(BlankNode)
46
+ end
47
+ end
48
+ return !rdf_type.nil?
49
+ end
50
+
51
+ def build_xml(xml, &block)
52
+ if (is_subject?)
53
+ attrs = {"rdf:about" => self.full_uri}
54
+ attrs["xml:lang"] = self.lang if self.lang
55
+ xml.rdf(:Description, attrs) do
56
+ if self.rdf_type
57
+ xml.rdf(:type, "rdf:resource" => self.rdf_type.full_uri)
58
+ end
59
+ self.nodes.each do |predicate|
60
+ predicate.build_xml(xml)
61
+ end
62
+ end
63
+ elsif block
64
+ block.call("rdf:resource" => self.full_uri)
65
+ end
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module IqRdf
16
+ VERSION = "0.0.14"
17
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,15 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'iq_rdf'
@@ -0,0 +1,54 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test/test_helper'
16
+
17
+ class IqRdfTest < Test::Unit::TestCase
18
+
19
+ def test_namespace_definitions
20
+ assert_raise(URI::InvalidURIError) { IqRdf::Document.new(12345) }
21
+
22
+ document = IqRdf::Document.new("http://default-namespace.com/")
23
+
24
+ assert_raise(ArgumentError) { document.namespaces :nohash }
25
+ assert_raise(ArgumentError) { document.namespaces "wrong" => "http://www.innoq.com/" }
26
+ assert_raise(URI::InvalidURIError) { document.namespaces :correct => 12 }
27
+
28
+ document.namespaces :innoq => "http://www.innoq.com/"
29
+ document.namespaces :uba => "http://www.uba.de/"
30
+
31
+ IqRdf::Innoq::uri_prefix
32
+
33
+ assert_equal("http://default-namespace.com/", IqRdf::uri_prefix.to_s)
34
+ assert_equal("http://www.innoq.com/", IqRdf::Innoq::uri_prefix.to_s)
35
+ assert_equal("http://www.uba.de/", IqRdf::Uba::uri_prefix.to_s)
36
+
37
+ end
38
+
39
+ def test_uri_definitions
40
+ IqRdf::Document.new("http://default-namespace.com/").namespaces :innoq => 'http://www.innoq.com/'
41
+
42
+ IqRdf::Innoq::tillsc
43
+
44
+ assert_equal("http://default-namespace.com/foo", IqRdf::foo.full_uri)
45
+ assert_equal("http://www.innoq.com/tillsc", IqRdf::Innoq::tillsc.full_uri)
46
+ end
47
+
48
+ def test_disallow_nested_definitions
49
+ IqRdf::Document.new('http://www.umweltprobenbank.de/').namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
50
+
51
+ assert_raise(ArgumentError) {IqRdf::testemann.Foaf::knows(IqRdf::testefrau.Foaf::knows(IqRdf::someone_else)) }
52
+ end
53
+
54
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'rubygems'
16
+ require 'test/unit'
17
+
18
+ require 'iq_rdf'
@@ -0,0 +1,215 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test/test_helper'
16
+
17
+ class TurtleTest < Test::Unit::TestCase
18
+
19
+ def test_basic_turtle_output
20
+ document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
21
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
22
+
23
+ document << IqRdf::testemann do |t|
24
+ t.Foaf::knows(IqRdf::testefrau)
25
+ t.Foaf.nick("Testy")
26
+ t.Foaf.lastname("Testemann", :lang => :none)
27
+ end
28
+
29
+ assert_equal(<<rdf, document.to_turtle)
30
+ @prefix : <http://www.test.de/>.
31
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
32
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
33
+
34
+ :testemann foaf:knows :testefrau;
35
+ foaf:nick "Testy"@de;
36
+ foaf:lastname "Testemann".
37
+ rdf
38
+ end
39
+
40
+ def test_full_uri_subject_turtle_output
41
+ document = IqRdf::Document.new('http://www.test.de/')
42
+
43
+ assert_raise RuntimeError do
44
+ IqRdf::build_full_uri_subject("bla")
45
+ end
46
+
47
+ document << IqRdf::build_full_uri_subject(URI.parse('http://www.xyz.de/#test'), IqRdf::build_uri('SomeType')) do |t|
48
+ t.test("testvalue")
49
+ end
50
+
51
+ assert_equal(<<rdf, document.to_turtle)
52
+ @prefix : <http://www.test.de/>.
53
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
54
+
55
+ <http://www.xyz.de/#test> a :SomeType;
56
+ :test "testvalue".
57
+ rdf
58
+ end
59
+
60
+ def test_complex_features
61
+ document = IqRdf::Document.new('http://www.umweltprobenbank.de/', :lang => :de)
62
+
63
+ document.namespaces :skos => 'http://www.w3.org/2008/05/skos#', :foaf => 'http://xmlns.com/foaf/0.1/', :upb => 'http://www.upb.de/'
64
+
65
+ document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en) # :testemann :myCustomNote "This is an example"@en.
66
+
67
+ document << IqRdf::testemann(IqRdf::Foaf::build_uri("Person")).Foaf::name("Heinz Peter Testemann", :lang => :none) # :testemann a foaf:Person; foaf:name "Heinz Peter Testemann" .
68
+ document << IqRdf::testemann.Foaf::knows(IqRdf::testefrau) # :testemann foaf:knows :testefrau .
69
+ document << IqRdf::testemann.Foaf::nick("Crash test dummy") # :testemann foaf:nick "Crash test dummy"@de .
70
+
71
+ ["u1023", "xkfkrl"].each do |id|
72
+ document << IqRdf::Upb::build_uri(id, IqRdf::Skos::build_uri(:Concept)) do |doc| # upb:#{id} a skos:Concept;
73
+ doc.Skos::prefLabel("Test", :lang => :en) # skos:prefLabel "Test"@en;
74
+ doc.Skos::related(IqRdf::Rdf.anotherThing) # skos:related test:another_thing;
75
+
76
+ doc.test1("bla") # :test1 "bla"@de;
77
+ doc.testIt(:hello, :goodbye, "bla") # :testIt :hallo, :goodbye, "bla"@de;
78
+ doc.testIt([IqRdf::hello, IqRdf::goodbye, "bla"], "blubb") # :testIt (:hallo :goodbye "bla"@de), "blubb"@de; # XML: rdf:list
79
+ doc.anotherTest(URI.parse("http://www.test.de/foo")) # :anotherTest <http://www.test.de/foo>;
80
+
81
+ end # .
82
+ end
83
+
84
+ document << IqRdf::Skos::testnode.test32 do |blank_node| # Blank nodes # skos:testnode :test32 [
85
+ blank_node.title("dies ist ein test") # :title "dies ist ein test"@de;
86
+ blank_node.sub do |subnode| # sub [
87
+ subnode.title("blubb") # title "blubb"
88
+ end # ]
89
+ end # ]
90
+
91
+ assert_equal(<<rdf, document.to_turtle)
92
+ @prefix : <http://www.umweltprobenbank.de/>.
93
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
94
+ @prefix skos: <http://www.w3.org/2008/05/skos#>.
95
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
96
+ @prefix upb: <http://www.upb.de/>.
97
+
98
+ :testemann :myCustomNote "This is an example"@en.
99
+ :testemann a foaf:Person;
100
+ foaf:name "Heinz Peter Testemann".
101
+ :testemann foaf:knows :testefrau.
102
+ :testemann foaf:nick "Crash test dummy"@de.
103
+ upb:u1023 a skos:Concept;
104
+ skos:prefLabel "Test"@en;
105
+ skos:related rdf:anotherThing;
106
+ :test1 "bla"@de;
107
+ :testIt :hello, :goodbye, "bla"@de;
108
+ :testIt (:hello :goodbye "bla"@de), "blubb"@de;
109
+ :anotherTest <http://www.test.de/foo>.
110
+ upb:xkfkrl a skos:Concept;
111
+ skos:prefLabel "Test"@en;
112
+ skos:related rdf:anotherThing;
113
+ :test1 "bla"@de;
114
+ :testIt :hello, :goodbye, "bla"@de;
115
+ :testIt (:hello :goodbye "bla"@de), "blubb"@de;
116
+ :anotherTest <http://www.test.de/foo>.
117
+ skos:testnode :test32 [
118
+ :title "dies ist ein test"@de;
119
+ :sub [
120
+ :title "blubb"@de
121
+ ]
122
+ ].
123
+ rdf
124
+ end
125
+
126
+ def test_literals
127
+ document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
128
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
129
+
130
+ document << IqRdf::testemann do |t|
131
+ t.Foaf::knows(:testefrau)
132
+ t.Foaf.nick("Testy")
133
+ t.Foaf.lastname("Testemann", :lang => :none)
134
+ t.age(32)
135
+ t.married(false)
136
+ t.weight(65.8)
137
+ t.quotes("\"I'm \\quoted\"")
138
+ t.line_breaks("I'm written\nover two lines")
139
+ t.some_literal(IqRdf::Literal.new("text", :de))
140
+ t.messy(IqRdf::PlainTurtleLiteral.new('"this_already_is_in_turtle_format"@en'))
141
+ end
142
+
143
+ assert_equal(<<rdf, document.to_turtle)
144
+ @prefix : <http://www.test.de/>.
145
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
146
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
147
+
148
+ :testemann foaf:knows :testefrau;
149
+ foaf:nick "Testy"@de;
150
+ foaf:lastname "Testemann";
151
+ :age 32;
152
+ :married false;
153
+ :weight 65.8;
154
+ :quotes "\\"I'm \\\\quoted\\""@de;
155
+ :line_breaks """I'm written
156
+ over two lines"""@de;
157
+ :some_literal "text"@de;
158
+ :messy "this_already_is_in_turtle_format"@en.
159
+ rdf
160
+ end
161
+
162
+ def test_supress_if_empty_otpion
163
+ document = IqRdf::Document.new('http://www.test.de/')
164
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
165
+
166
+ document << IqRdf::testemann.Foaf::knows(:suppress_if_empty => true)
167
+ document << IqRdf::testemann.Foaf::knows(nil, :suppress_if_empty => true)
168
+ document << IqRdf::testemann.Foaf::knows("", :suppress_if_empty => true)
169
+ document << IqRdf::testemann.Foaf::knows([], :suppress_if_empty => true)
170
+ assert_equal(<<rdf, document.to_turtle)
171
+ @prefix : <http://www.test.de/>.
172
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
173
+ @prefix foaf: <http://xmlns.com/foaf/0.1/>.
174
+
175
+ rdf
176
+ end
177
+
178
+ def test_full_uri_predicates
179
+ document = IqRdf::Document.new('http://www.test.de/')
180
+
181
+ document << IqRdf::testemann.build_full_uri_predicate(URI.parse("http://www.test.org/hoho"), 42)
182
+
183
+ assert_equal(<<rdf, document.to_turtle)
184
+ @prefix : <http://www.test.de/>.
185
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
186
+
187
+ :testemann <http://www.test.org/hoho> 42.
188
+ rdf
189
+ end
190
+
191
+ def test_blank_nodes
192
+ document = IqRdf::Document.new('http://www.test.de/')
193
+
194
+ document << IqRdf::testnode.test32 do |blank_node| # Blank nodes # :testnode :test32 [
195
+ blank_node.title("dies ist ein test") # :title "dies ist ein test";
196
+ blank_node.build_predicate(:test, "Another test") # :test "Another test";
197
+ blank_node.sub do |subnode| # sub [
198
+ subnode.title("blubb") # title "blubb"
199
+ end # ]
200
+ end # ]
201
+ assert_equal(<<rdf, document.to_turtle)
202
+ @prefix : <http://www.test.de/>.
203
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
204
+
205
+ :testnode :test32 [
206
+ :title "dies ist ein test";
207
+ :test "Another test";
208
+ :sub [
209
+ :title "blubb"
210
+ ]
211
+ ].
212
+ rdf
213
+ end
214
+
215
+ end
data/test/xml_test.rb ADDED
@@ -0,0 +1,203 @@
1
+ # Copyright 2011 Till Schulte-Coerne (innoQ Deutschland GmbH)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'test/test_helper'
16
+
17
+ class XmlTest < Test::Unit::TestCase
18
+
19
+ def test_basic_xml_output
20
+ document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
21
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
22
+
23
+ document << IqRdf::testemann do |t|
24
+ t.Foaf::knows(IqRdf::testefrau)
25
+ t.Foaf.nick("Testy")
26
+ t.Foaf.lastname("Testemann", :lang => :none)
27
+ end
28
+
29
+ assert_equal(<<rdf, document.to_xml)
30
+ <?xml version="1.0" encoding="UTF-8"?>
31
+ <rdf:RDF xmlns="http://www.test.de/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xml:lang="de">
32
+ <rdf:Description rdf:about="http://www.test.de/testemann">
33
+ <foaf:knows rdf:resource="http://www.test.de/testefrau"/>
34
+ <foaf:nick>Testy</foaf:nick>
35
+ <foaf:lastname xml:lang="">Testemann</foaf:lastname>
36
+ </rdf:Description>
37
+ </rdf:RDF>
38
+ rdf
39
+ end
40
+
41
+ def test_full_uri_subject_xml_output
42
+ document = IqRdf::Document.new('http://www.test.de/')
43
+
44
+ assert_raise RuntimeError do
45
+ IqRdf::build_full_uri_subject("bla")
46
+ end
47
+
48
+ document << IqRdf::build_full_uri_subject(URI.parse('http://www.xyz.de/#test'), IqRdf::build_uri('SomeType')) do |t|
49
+ t.test("testvalue")
50
+ end
51
+
52
+ assert_equal(<<rdf, document.to_xml)
53
+ <?xml version="1.0" encoding="UTF-8"?>
54
+ <rdf:RDF xmlns="http://www.test.de/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
55
+ <rdf:Description rdf:about="http://www.xyz.de/#test">
56
+ <rdf:type rdf:resource="http://www.test.de/SomeType"/>
57
+ <test>testvalue</test>
58
+ </rdf:Description>
59
+ </rdf:RDF>
60
+ rdf
61
+ end
62
+
63
+ def test_complex_features
64
+ document = IqRdf::Document.new('http://www.umweltprobenbank.de/', :lang => :de)
65
+
66
+ document.namespaces :skos => 'http://www.w3.org/2008/05/skos#', :foaf => 'http://xmlns.com/foaf/0.1/', :upb => 'http://www.upb.de/'
67
+
68
+ document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en) # :testemann :myCustomNote "This is an example"@en.
69
+
70
+ document << IqRdf::testemann(IqRdf::Foaf::build_uri("Person")).Foaf::name("Heinz Peter Testemann", :lang => :none) # :testemann a foaf:Person; foaf:name "Heinz Peter Testemann" .
71
+ document << IqRdf::testemann.Foaf::knows(IqRdf::testefrau) # :testemann foaf:knows :testefrau .
72
+ document << IqRdf::testemann.Foaf::nick("Crash test dummy") # :testemann foaf:nick "Crash test dummy"@de .
73
+
74
+ document << IqRdf::testemann.testIt([IqRdf::hello, "bla"]) # :testIt (:hallo :goodbye "bla"@de), "blubb"@de; # XML: rdf:list
75
+
76
+ ["u1023", "xkfkrl"].each do |id|
77
+ document << IqRdf::Upb::build_uri(id, IqRdf::Skos::build_uri(:Concept)) do |doc| # upb:#{id} a skos:Concept;
78
+ doc.Skos::prefLabel("Test", :lang => :en) # skos:prefLabel "Test"@en;
79
+ doc.Skos::related(IqRdf::Rdf.anotherThing) # skos:related test:another_thing;
80
+
81
+ doc.test1("bla") # :test1 "bla"@de;
82
+ doc.testIt(:hello, :goodbye, "bla") # :testIt :hallo, :goodbye, "bla"@de;
83
+ doc.anotherTest(URI.parse("http://www.test.de/foo")) # :anotherTest <http://www.test.de/foo>;
84
+
85
+ end # .
86
+ end
87
+ document << IqRdf::Skos::testnode.test32 do |blank_node| # Blank nodes # skos:testnode :test32 [
88
+ blank_node.title("dies ist ein test") # :title "dies ist ein test"@de;
89
+ blank_node.sub do |subnode| # sub [
90
+ subnode.title("blubb") # title "blubb"
91
+ end # ]
92
+ end # ]
93
+
94
+ assert_equal(<<rdf, document.to_xml)
95
+ <?xml version="1.0" encoding="UTF-8"?>
96
+ <rdf:RDF xmlns="http://www.umweltprobenbank.de/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2008/05/skos#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:upb="http://www.upb.de/" xml:lang="de">
97
+ <rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
98
+ <myCustomNote xml:lang="en">This is an example</myCustomNote>
99
+ </rdf:Description>
100
+ <rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
101
+ <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
102
+ <foaf:name xml:lang="">Heinz Peter Testemann</foaf:name>
103
+ </rdf:Description>
104
+ <rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
105
+ <foaf:knows rdf:resource="http://www.umweltprobenbank.de/testefrau"/>
106
+ </rdf:Description>
107
+ <rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
108
+ <foaf:nick>Crash test dummy</foaf:nick>
109
+ </rdf:Description>
110
+ <rdf:Description rdf:about="http://www.umweltprobenbank.de/testemann">
111
+ <testIt>
112
+ <rdf:List>
113
+ <rdf:first rdf:resource="http://www.umweltprobenbank.de/hello"/>
114
+ <rdf:rest>
115
+ <rdf:List>
116
+ <rdf:first>bla</rdf:first>
117
+ <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
118
+ </rdf:List>
119
+ </rdf:rest>
120
+ </rdf:List>
121
+ </testIt>
122
+ </rdf:Description>
123
+ <rdf:Description rdf:about="http://www.upb.de/u1023">
124
+ <rdf:type rdf:resource="http://www.w3.org/2008/05/skos#Concept"/>
125
+ <skos:prefLabel xml:lang="en">Test</skos:prefLabel>
126
+ <skos:related rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#anotherThing"/>
127
+ <test1>bla</test1>
128
+ <testIt rdf:resource="http://www.umweltprobenbank.de/hello"/>
129
+ <testIt rdf:resource="http://www.umweltprobenbank.de/goodbye"/>
130
+ <testIt>bla</testIt>
131
+ <anotherTest rdf:resource="http://www.test.de/foo"/>
132
+ </rdf:Description>
133
+ <rdf:Description rdf:about="http://www.upb.de/xkfkrl">
134
+ <rdf:type rdf:resource="http://www.w3.org/2008/05/skos#Concept"/>
135
+ <skos:prefLabel xml:lang="en">Test</skos:prefLabel>
136
+ <skos:related rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#anotherThing"/>
137
+ <test1>bla</test1>
138
+ <testIt rdf:resource="http://www.umweltprobenbank.de/hello"/>
139
+ <testIt rdf:resource="http://www.umweltprobenbank.de/goodbye"/>
140
+ <testIt>bla</testIt>
141
+ <anotherTest rdf:resource="http://www.test.de/foo"/>
142
+ </rdf:Description>
143
+ <rdf:Description rdf:about="http://www.w3.org/2008/05/skos#testnode">
144
+ <test32>
145
+ <rdf:Description>
146
+ <title>dies ist ein test</title>
147
+ <sub>
148
+ <rdf:Description>
149
+ <title>blubb</title>
150
+ </rdf:Description>
151
+ </sub>
152
+ </rdf:Description>
153
+ </test32>
154
+ </rdf:Description>
155
+ </rdf:RDF>
156
+ rdf
157
+
158
+ =begin
159
+ skos:testnode :test32 [
160
+ :title "dies ist ein test"@de;
161
+ :sub [
162
+ :title "blubb"@de
163
+ ]
164
+ ].
165
+ =end
166
+ end
167
+
168
+ def test_literals
169
+ document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
170
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
171
+
172
+ document << IqRdf::testemann do |t|
173
+ t.Foaf::knows(:testefrau)
174
+ t.Foaf.nick("Testy")
175
+ t.Foaf.lastname("Testemann", :lang => :none)
176
+ t.age(32)
177
+ t.married(false)
178
+ t.weight(65.8)
179
+ t.quotes("\"I'm \\quoted\"")
180
+ t.line_breaks("I'm written\nover two lines")
181
+ t.some_literal(IqRdf::Literal.new("text", :de))
182
+ end
183
+
184
+ assert_equal(<<rdf, document.to_xml)
185
+ <?xml version="1.0" encoding="UTF-8"?>
186
+ <rdf:RDF xmlns="http://www.test.de/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xml:lang="de">
187
+ <rdf:Description rdf:about="http://www.test.de/testemann">
188
+ <foaf:knows rdf:resource="http://www.test.de/testefrau"/>
189
+ <foaf:nick>Testy</foaf:nick>
190
+ <foaf:lastname xml:lang="">Testemann</foaf:lastname>
191
+ <age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">32</age>
192
+ <married rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</married>
193
+ <weight rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal">65.8</weight>
194
+ <quotes>"I'm \\quoted"</quotes>
195
+ <line_breaks>I'm written
196
+ over two lines</line_breaks>
197
+ <some_literal xml:lang="de">text</some_literal>
198
+ </rdf:Description>
199
+ </rdf:RDF>
200
+ rdf
201
+ end
202
+
203
+ end