iq_rdf 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -85,7 +85,7 @@ module IqRdf
85
85
 
86
86
  render_resource = lambda do |res, lang| # XXX: does not belong here
87
87
  if res.is_a?(IqRdf::Literal)
88
- return res.to_s(lang)
88
+ return res.to_ntriples(lang)
89
89
  elsif res.is_a?(IqRdf::BlankNode)
90
90
  return render_blank_node.call(res)
91
91
  elsif res.is_a?(IqRdf::Collection)
@@ -11,6 +11,10 @@ module IqRdf
11
11
  "<#{@obj.to_s}>"
12
12
  end
13
13
 
14
+ def to_ntriples(parent_lang = nil)
15
+ "<#{@obj.to_s}>"
16
+ end
17
+
14
18
  def build_xml(xml, &block)
15
19
  block.call("rdf:resource" => @obj.to_s)
16
20
  end
@@ -49,6 +49,20 @@ module IqRdf
49
49
  "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}#{lang}#{datatype}"
50
50
  end
51
51
 
52
+ def to_ntriples(parent_lang = nil)
53
+ quote = @obj.to_s.include?("\n") ? '"""' : '"'
54
+ suffix = if @datatype.is_a?(::URI)
55
+ "^^<#{@datatype.to_s}>"
56
+ elsif @datatype.is_a?(IqRdf::Uri)
57
+ "^^<#{@datatype.full_uri}>"
58
+ else
59
+ lang = @lang || parent_lang # Use the Literals lang when given
60
+ (lang && lang != :none) ? "@#{lang}" : ""
61
+ end
62
+
63
+ "#{quote}#{@obj.to_s.gsub("\\", "\\\\\\\\").gsub(/"/, "\\\"")}#{quote}#{suffix}"
64
+ end
65
+
52
66
  def build_xml(xml, &block)
53
67
  opts = {}
54
68
  if @datatype.is_a?(::URI)
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module IqRdf
16
- VERSION = "0.1.7"
16
+ VERSION = "0.1.8"
17
17
  end
data/lib/iq_rdf.rb CHANGED
@@ -22,7 +22,6 @@ require 'iq_rdf/literal/boolean'
22
22
  require 'iq_rdf/literal/string'
23
23
  require 'iq_rdf/literal/uri'
24
24
  require 'iq_rdf/literal/numeric'
25
- require 'iq_rdf/plain_turtle_literal'
26
25
  require 'iq_rdf/namespace'
27
26
  require 'iq_rdf/collection'
28
27
  require 'iq_rdf/predicate_namespace'
@@ -52,7 +52,7 @@ class NTriplesTest < Test::Unit::TestCase
52
52
  document = IqRdf::Document.new('http://www.test.de/')
53
53
 
54
54
  document << IqRdf::build_full_uri_subject(URI.parse('http://www.xyz.de/#test'),
55
- IqRdf::build_uri('SomeType')) do |t|
55
+ IqRdf::build_uri('SomeType')) do |t|
56
56
  t.sometest("testvalue")
57
57
  end
58
58
 
@@ -69,7 +69,7 @@ class NTriplesTest < Test::Unit::TestCase
69
69
  build_full_uri_predicate(URI.parse("http://www.test.org/hoho"), 42)
70
70
 
71
71
  assert_equal(<<-rdf.strip, document.to_ntriples.strip)
72
- <http://www.test.de/testemann> <http://www.test.org/hoho> 42 .
72
+ <http://www.test.de/testemann> <http://www.test.org/hoho> "42"^^<http://www.w3.org/2001/XMLSchema#integer> .
73
73
  rdf
74
74
  end
75
75
 
@@ -171,16 +171,50 @@ _:b2 <http://www.umweltprobenbank.de/title> "blubb"@de .
171
171
  rdf
172
172
  end
173
173
 
174
- def test_supress_if_empty_option
175
- document = IqRdf::Document.new('http://www.test.de/')
174
+ def test_literals
175
+ document = IqRdf::Document.new('http://www.test.de/', :lang => :de)
176
176
  document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
177
177
 
178
- document << IqRdf::testemann.Foaf::knows(:suppress_if_empty => true)
179
- document << IqRdf::testemann.Foaf::knows(nil, :suppress_if_empty => true)
180
- document << IqRdf::testemann.Foaf::knows("", :suppress_if_empty => true)
181
- document << IqRdf::testemann.Foaf::knows([], :suppress_if_empty => true)
178
+ document << IqRdf::testemann do |t|
179
+ t.Foaf::knows(:testefrau)
180
+ t.Foaf.nick("Testy")
181
+ t.Foaf.lastname("Testemann", :lang => :none)
182
+ t.age(32)
183
+ t.married(false)
184
+ t.weight(65.8)
185
+ t.complex(IqRdf::Literal.new("A very complex type", :none, URI.parse("http://this.com/is#complex")))
186
+ t.complex2(IqRdf::Literal.new("Shorter form", :none, IqRdf::myDatatype))
187
+ t.quotes("\"I'm \\quoted\"")
188
+ t.line_breaks("I'm written\nover two lines")
189
+ t.some_literal(IqRdf::Literal.new("text", :de))
190
+ end
182
191
 
183
- assert_equal("", document.to_ntriples.strip)
184
- end
192
+ assert_equal(<<rdf.strip, document.to_ntriples.strip)
193
+ <http://www.test.de/testemann> <http://xmlns.com/foaf/0.1/knows> <http://www.test.de/testefrau> .
194
+ <http://www.test.de/testemann> <http://xmlns.com/foaf/0.1/nick> "Testy"@de .
195
+ <http://www.test.de/testemann> <http://xmlns.com/foaf/0.1/lastname> "Testemann" .
196
+ <http://www.test.de/testemann> <http://www.test.de/age> "32"^^<http://www.w3.org/2001/XMLSchema#integer> .
197
+ <http://www.test.de/testemann> <http://www.test.de/married> "false"^^<http://www.w3.org/2001/XMLSchema#boolean> .
198
+ <http://www.test.de/testemann> <http://www.test.de/weight> "65.8"^^<http://www.w3.org/2001/XMLSchema#decimal> .
199
+ <http://www.test.de/testemann> <http://www.test.de/complex> "A very complex type"^^<http://this.com/is#complex> .
200
+ <http://www.test.de/testemann> <http://www.test.de/complex2> "Shorter form"^^<http://www.test.de/myDatatype> .
201
+ <http://www.test.de/testemann> <http://www.test.de/quotes> "\\"I'm \\\\quoted\\""@de .
202
+ <http://www.test.de/testemann> <http://www.test.de/line_breaks> """I'm written
203
+ over two lines"""@de .
204
+ <http://www.test.de/testemann> <http://www.test.de/some_literal> "text"@de .
205
+ rdf
206
+ end
207
+
208
+ def test_supress_if_empty_option
209
+ document = IqRdf::Document.new('http://www.test.de/')
210
+ document.namespaces :foaf => 'http://xmlns.com/foaf/0.1/'
185
211
 
186
- end
212
+ document << IqRdf::testemann.Foaf::knows(:suppress_if_empty => true)
213
+ document << IqRdf::testemann.Foaf::knows(nil, :suppress_if_empty => true)
214
+ document << IqRdf::testemann.Foaf::knows("", :suppress_if_empty => true)
215
+ document << IqRdf::testemann.Foaf::knows([], :suppress_if_empty => true)
216
+
217
+ assert_equal("", document.to_ntriples.strip)
218
+ end
219
+
220
+ end
data/test/turtle_test.rb CHANGED
@@ -141,7 +141,6 @@ rdf
141
141
  t.quotes("\"I'm \\quoted\"")
142
142
  t.line_breaks("I'm written\nover two lines")
143
143
  t.some_literal(IqRdf::Literal.new("text", :de))
144
- t.messy(IqRdf::PlainTurtleLiteral.new('"this_already_is_in_turtle_format"@en'))
145
144
  end
146
145
 
147
146
  assert_equal(<<rdf, document.to_turtle)
@@ -160,8 +159,7 @@ rdf
160
159
  :quotes "\\"I'm \\\\quoted\\""@de;
161
160
  :line_breaks """I'm written
162
161
  over two lines"""@de;
163
- :some_literal "text"@de;
164
- :messy "this_already_is_in_turtle_format"@en.
162
+ :some_literal "text"@de.
165
163
  rdf
166
164
  end
167
165
 
metadata CHANGED
@@ -1,61 +1,47 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: iq_rdf
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 7
10
- version: 0.1.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Till Schulte-Coerne
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-17 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-10-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &2161452060 !ruby/object:Gem::Requirement
22
17
  none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- requirement: *id001
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :runtime
32
- name: bundler
33
23
  prerelease: false
34
- - !ruby/object:Gem::Dependency
35
- version_requirements: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2161452060
25
+ - !ruby/object:Gem::Dependency
26
+ name: builder
27
+ requirement: &2161451340 !ruby/object:Gem::Requirement
36
28
  none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- hash: 3
41
- segments:
42
- - 0
43
- version: "0"
44
- requirement: *id002
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
45
33
  type: :runtime
46
- name: builder
47
34
  prerelease: false
35
+ version_requirements: *2161451340
48
36
  description: IqRdf - A builder like rdf library for ruby and rails
49
- email:
37
+ email:
50
38
  - till.schulte-coerne@innoq.com
51
39
  executables: []
52
-
53
40
  extensions: []
54
-
55
- extra_rdoc_files:
41
+ extra_rdoc_files:
56
42
  - README.md
57
43
  - LICENSE
58
- files:
44
+ files:
59
45
  - LICENSE
60
46
  - README.md
61
47
  - Rakefile
@@ -70,7 +56,6 @@ files:
70
56
  - lib/iq_rdf/literal.rb
71
57
  - lib/iq_rdf/namespace.rb
72
58
  - lib/iq_rdf/node.rb
73
- - lib/iq_rdf/plain_turtle_literal.rb
74
59
  - lib/iq_rdf/predicate.rb
75
60
  - lib/iq_rdf/predicate_namespace.rb
76
61
  - lib/iq_rdf/rails/iq_rdf.rb
@@ -85,38 +70,35 @@ files:
85
70
  - test/xml_test.rb
86
71
  homepage: http://github.com/innoq/iq_rdf
87
72
  licenses: []
88
-
89
73
  post_install_message:
90
74
  rdoc_options: []
91
-
92
- require_paths:
75
+ require_paths:
93
76
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
77
+ required_ruby_version: !ruby/object:Gem::Requirement
95
78
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ segments:
101
84
  - 0
102
- version: "0"
103
- required_rubygems_version: !ruby/object:Gem::Requirement
85
+ hash: 3133402933398086512
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
87
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
110
93
  - 0
111
- version: "0"
94
+ hash: 3133402933398086512
112
95
  requirements: []
113
-
114
96
  rubyforge_project:
115
97
  rubygems_version: 1.8.10
116
98
  signing_key:
117
99
  specification_version: 3
118
100
  summary: IqRdf - A builder like rdf library for ruby and rails
119
- test_files:
101
+ test_files:
120
102
  - test/iq_rdf_test.rb
121
103
  - test/ntriples_test.rb
122
104
  - test/test_helper.rb
@@ -1,30 +0,0 @@
1
- # Copyright 2011 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
- # This is a dummy class for some needs where
17
- class PlainTurtleLiteral < Literal
18
-
19
- def initialize(obj)
20
- @obj = obj
21
- end
22
-
23
- def to_s(lang = nil)
24
- @obj.to_s
25
- end
26
-
27
- alias_method :full_uri, :to_s
28
-
29
- end
30
- end