lightrdf 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/lib/lightrdf/graph.rb +11 -0
- data/lib/lightrdf/node.rb +15 -0
- data/lib/lightrdf/node_proxy.rb +5 -0
- data/lib/lightrdf.rb +1 -1
- data/lightrdf.gemspec +2 -2
- data/test/test_lightrdf.rb +61 -30
- metadata +3 -3
data/History.txt
CHANGED
data/lib/lightrdf/graph.rb
CHANGED
@@ -93,6 +93,17 @@ module RDF
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
def clone
|
97
|
+
graph = self.class.new
|
98
|
+
each do |id, node|
|
99
|
+
new_node = graph[id]
|
100
|
+
node.each do |predicate, objects|
|
101
|
+
new_node[predicate] = objects.map { |object| object.is_a?(Node) ? graph[object] : object }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
graph
|
105
|
+
end
|
106
|
+
|
96
107
|
def find subject, predicate, object
|
97
108
|
# Convert nodes into IDs
|
98
109
|
subject = subject.id if subject.is_a?(Node)
|
data/lib/lightrdf/node.rb
CHANGED
@@ -88,6 +88,21 @@ module RDF
|
|
88
88
|
end
|
89
89
|
self
|
90
90
|
end
|
91
|
+
|
92
|
+
def rename new_id=nil
|
93
|
+
clone.rename! new_id
|
94
|
+
end
|
95
|
+
|
96
|
+
def rename! new_id=nil
|
97
|
+
self.graph.delete id
|
98
|
+
self.id = ID(new_id)
|
99
|
+
self.graph[id] = self
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
def clone
|
104
|
+
self.graph.clone[id]
|
105
|
+
end
|
91
106
|
|
92
107
|
def bnode?
|
93
108
|
ID.bnode?(id)
|
data/lib/lightrdf/node_proxy.rb
CHANGED
data/lib/lightrdf.rb
CHANGED
data/lightrdf.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{lightrdf}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.8"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jose Ignacio"]
|
9
|
-
s.date = %q{2011-
|
9
|
+
s.date = %q{2011-04-04}
|
10
10
|
s.default_executable = %q{yarfp}
|
11
11
|
s.description = %q{RDF library}
|
12
12
|
s.email = %q{joseignacio.fernandez@gmail.com}
|
data/test/test_lightrdf.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
2
|
|
3
3
|
Namespace :ex, 'http://www.example.com/ontology#'
|
4
|
-
Namespace :foaf, 'http://xmlns.com/foaf/0.1/'
|
5
|
-
|
6
|
-
module Foaf
|
7
|
-
class Person
|
8
|
-
include RDF::NodeProxy
|
9
|
-
|
10
|
-
# Adds 1 year to the person's age
|
11
|
-
def happy_birthday!
|
12
|
-
foaf::age = (foaf::age.first.to_i + 1).to_s
|
13
|
-
end
|
14
|
-
end
|
4
|
+
Namespace :foaf, 'http://xmlns.com/foaf/0.1/'
|
5
|
+
|
6
|
+
module Foaf
|
7
|
+
class Person
|
8
|
+
include RDF::NodeProxy
|
9
|
+
|
10
|
+
# Adds 1 year to the person's age
|
11
|
+
def happy_birthday!
|
12
|
+
foaf::age = (foaf::age.first.to_i + 1).to_s
|
13
|
+
end
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
|
-
module Foaf
|
17
|
+
module Foaf
|
18
18
|
class Thing
|
19
|
-
include RDF::NodeProxy
|
20
|
-
maps 'http://xmlns.com/foaf/0.1/Agent'
|
21
|
-
end
|
19
|
+
include RDF::NodeProxy
|
20
|
+
maps 'http://xmlns.com/foaf/0.1/Agent'
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
class TestLightRDF < Test::Unit::TestCase
|
@@ -98,6 +98,37 @@ class TestLightRDF < Test::Unit::TestCase
|
|
98
98
|
assert_equal 1, [g[Node('ex:bob')].graph.object_id, g[Node('ex:bob')].foaf::weblog.map(&:graph).map(&:object_id)].flatten.uniq.size
|
99
99
|
end
|
100
100
|
|
101
|
+
def test_rename
|
102
|
+
a = Node('ex:alice')
|
103
|
+
a.foaf::name = "Alice"
|
104
|
+
b = Node('ex:bob')
|
105
|
+
b.foaf::knows = a
|
106
|
+
a.graph << b
|
107
|
+
a.foaf::knows = b
|
108
|
+
|
109
|
+
c = a.rename 'ex:ana'
|
110
|
+
|
111
|
+
assert a.graph['ex:alice'].foaf::knows.include?(Node('ex:bob'))
|
112
|
+
assert a.foaf::knows.first.foaf::knows.include?(Node('ex:alice'))
|
113
|
+
|
114
|
+
assert c.graph['ex:ana'].foaf::knows.include?(Node('ex:bob'))
|
115
|
+
assert c.foaf::knows.first.foaf::knows.include?(Node('ex:ana'))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_rename!
|
119
|
+
a = Node('ex:alice')
|
120
|
+
a.foaf::name = "Alice"
|
121
|
+
b = Node('ex:bob')
|
122
|
+
b.foaf::knows = a
|
123
|
+
a.graph << b
|
124
|
+
a.foaf::knows = b
|
125
|
+
|
126
|
+
a.rename! 'ex:ana'
|
127
|
+
|
128
|
+
assert a.graph['ex:ana'].foaf::knows.include?(Node('ex:bob'))
|
129
|
+
assert a.foaf::knows.first.foaf::knows.include?(Node('ex:ana'))
|
130
|
+
end
|
131
|
+
|
101
132
|
def test_node_merge
|
102
133
|
a = Node('ex:alice')
|
103
134
|
a.foaf::name = "Alice"
|
@@ -249,9 +280,9 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
249
280
|
|
250
281
|
def test_repository
|
251
282
|
repository = RDF::Repository.new
|
252
|
-
triple = [ID("http://testuri.org"), ID('rdf:type'), ID('rdf:Class')]
|
253
|
-
graph = RDF::Graph.new [triple]
|
254
|
-
context = "http://test_context.org"
|
283
|
+
triple = [ID("http://testuri.org"), ID('rdf:type'), ID('rdf:Class')]
|
284
|
+
graph = RDF::Graph.new [triple]
|
285
|
+
context = "http://test_context.org"
|
255
286
|
repository.data = graph, context
|
256
287
|
|
257
288
|
# Check if the added data is there
|
@@ -264,10 +295,10 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
264
295
|
end
|
265
296
|
|
266
297
|
def test_repository_contexts
|
267
|
-
repository = RDF::Repository.new
|
268
|
-
graph = RDF::Graph.new [[Node("http://testuri.org"), Node('rdf:type'), Node('rdf:Class')]]
|
269
|
-
context = "http://test_repository_contexts.org"
|
270
|
-
repository.data = graph, context
|
298
|
+
repository = RDF::Repository.new
|
299
|
+
graph = RDF::Graph.new [[Node("http://testuri.org"), Node('rdf:type'), Node('rdf:Class')]]
|
300
|
+
context = "http://test_repository_contexts.org"
|
301
|
+
repository.data = graph, context
|
271
302
|
contexts = repository.contexts
|
272
303
|
|
273
304
|
# Check if the added context is there
|
@@ -279,12 +310,12 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
279
310
|
assert_equal Node("foaf:Agent"), Foaf::Thing.new.rdf::type.first
|
280
311
|
|
281
312
|
person_node = Node(nil)
|
282
|
-
person_node.foaf::age = "19"
|
283
|
-
person = Foaf::Person.new(person_node)
|
284
|
-
assert_equal ["19"], person.foaf::age
|
285
|
-
|
313
|
+
person_node.foaf::age = "19"
|
314
|
+
person = Foaf::Person.new(person_node)
|
315
|
+
assert_equal ["19"], person.foaf::age
|
316
|
+
|
286
317
|
person = Foaf::Person.new('foaf:age'=>"25", 'rdf:type'=>Node('rdf:Resource'))
|
287
|
-
person.happy_birthday!
|
318
|
+
person.happy_birthday!
|
288
319
|
assert_equal ["26"], person.foaf::age
|
289
320
|
assert_equal Node("foaf:Person"), person.rdf::type.first
|
290
321
|
end
|
@@ -293,11 +324,11 @@ foaf: http://xmlns.com/foaf/0.1/
|
|
293
324
|
graph = RDF::Graph.new
|
294
325
|
person_node = Node(nil)
|
295
326
|
person_node.rdf::type = Node('foaf:Person')
|
296
|
-
person_node.foaf::age = "25"
|
297
|
-
graph << person_node
|
327
|
+
person_node.foaf::age = "25"
|
328
|
+
graph << person_node
|
298
329
|
|
299
330
|
person = graph.node(person_node)
|
300
|
-
person.happy_birthday!
|
331
|
+
person.happy_birthday!
|
301
332
|
assert_equal ["26"], person.foaf::age
|
302
333
|
assert_equal person.object_id, graph.node(person_node).object_id
|
303
334
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 8
|
9
|
+
version: 0.3.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jose Ignacio
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|