lightrdf 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/lightrdf/graph.rb +17 -4
- data/lib/lightrdf/node_proxy.rb +6 -2
- data/lib/lightrdf.rb +1 -1
- data/lightrdf.gemspec +1 -1
- data/test/test_lightrdf.rb +1 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/lightrdf/graph.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module RDF
|
2
2
|
class Graph < Hash
|
3
3
|
include Parser
|
4
|
+
|
4
5
|
# Namespace set stored when parsing a file. Can be used for reference
|
5
6
|
attr_accessor :ns
|
7
|
+
|
8
|
+
# Set of initialized RDF::NodeProxy objects
|
9
|
+
attr_accessor :pool
|
10
|
+
|
6
11
|
def initialize triples=[]
|
7
12
|
super(nil)
|
8
|
-
@ns
|
13
|
+
@ns = {}
|
14
|
+
@pool = {}
|
9
15
|
self.triples = triples
|
10
16
|
end
|
11
17
|
|
@@ -42,9 +48,16 @@ module RDF
|
|
42
48
|
end
|
43
49
|
|
44
50
|
# This is equivalent to [], but tries to return a NodeProxy
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
# It stores created objects in a pool
|
52
|
+
def node id, type=nil
|
53
|
+
id = ID(id)
|
54
|
+
@pool[id] ||= begin
|
55
|
+
node = self[id]
|
56
|
+
type ||= node.rdf::type.first
|
57
|
+
klass = Node.classes[type]
|
58
|
+
raise Exception, "Unknown RDF-mapped type #{type}" unless klass
|
59
|
+
klass.new(node)
|
60
|
+
end
|
48
61
|
end
|
49
62
|
|
50
63
|
def find subject, predicate, object
|
data/lib/lightrdf/node_proxy.rb
CHANGED
@@ -4,10 +4,14 @@ module RDF
|
|
4
4
|
def self.included base
|
5
5
|
base.extend ClassMethods
|
6
6
|
base.send :attr_reader, :node
|
7
|
-
base.maps
|
7
|
+
base.maps(base.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase })
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
+
def inherited subclass
|
12
|
+
subclass.maps(subclass.to_s.gsub("::",":").gsub(/\A.*:/) { |a| a.downcase })
|
13
|
+
end
|
14
|
+
|
11
15
|
def maps id
|
12
16
|
@rdf_type = Node(id)
|
13
17
|
Node.classes.delete Node.classes.invert[self]
|
@@ -60,7 +64,7 @@ module RDF
|
|
60
64
|
|
61
65
|
# Any other method (including any predicate) delegated to node
|
62
66
|
def method_missing method, *args
|
63
|
-
@node.send method, args
|
67
|
+
@node.send method, *args
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|
data/lib/lightrdf.rb
CHANGED
data/lightrdf.gemspec
CHANGED
data/test/test_lightrdf.rb
CHANGED