Class: RoadForest::RDF::GraphFocus
- Inherits:
-
Object
- Object
- RoadForest::RDF::GraphFocus
show all
- Includes:
- Normalization
- Defined in:
- lib/roadforest/rdf/graph-focus.rb
Constant Summary
Normalization::Vocabs
Instance Attribute Summary collapse
-
#access_manager ⇒ Object
attr_accessor :source_graph, :target_graph, :subject, :root_url, :source_rigor.
-
#subject ⇒ Object
(also: #rdf)
attr_accessor :source_graph, :target_graph, :subject, :root_url, :source_rigor.
Instance Method Summary
collapse
-
#add(property, value, extra = nil) ⇒ Object
-
#add_list(property, extra = nil) {|list| ... } ⇒ Object
-
#add_node(property, url = nil) ⇒ Object
-
#all(prefix, property = nil) ⇒ Object
-
#as_list ⇒ Object
-
#create_node(url = nil) {|node| ... } ⇒ Object
Create a subject node without relationship to the rest of the graph.
-
#delete(property, extra = nil) ⇒ Object
-
#dup ⇒ Object
-
#find_or_add(property, url = nil, &block) ⇒ Object
(also: #first_or_add)
-
#first(prefix, property = nil) ⇒ Object
-
#forward_properties ⇒ Object
-
#get(prefix, property = nil) ⇒ Object
(also: #[])
-
#initialize(access_manager, subject = nil) ⇒ GraphFocus
constructor
A new instance of GraphFocus.
-
#inspect ⇒ Object
(also: #to_s)
-
#normalize_triple(property, value, extra = nil) ⇒ Object
-
#relevant_prefixes ⇒ Object
XXX This probably wants to be handled completely in the MediaType handler.
-
#rev(prefix, property = nil) ⇒ Object
XXX Maybe rev should return a decorator, so it looks like: focus.rev.get(…) or focus.rev.all(…).
-
#rev_all(prefix, property = nil) ⇒ Object
-
#rev_first(prefix, property = nil) ⇒ Object
-
#reverse_properties ⇒ Object
-
#root_url ⇒ Object
-
#root_url=(*value) ⇒ Object
-
#set(property, value, extra = nil) ⇒ Object
(also: #[]=)
-
#set_node(property, url = nil) ⇒ Object
(also: #node_at)
-
#to_context ⇒ Object
-
#unwrap_value(value) ⇒ Object
-
#wrap_node(value) ⇒ Object
#expand_curie, #expand_curie_pair, #interned_uri, #literal, #normalize_context, #normalize_property, #normalize_resource, #normalize_statement, #normalize_term, #normalize_tuple, #normalize_uri, #relevant_prefixes_for_graph, #uri, #vocabularies_in_graph
Constructor Details
#initialize(access_manager, subject = nil) ⇒ GraphFocus
Returns a new instance of GraphFocus.
63
64
65
66
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 63
def initialize(access_manager, subject = nil)
@access_manager = access_manager
self.subject = subject unless subject.nil?
end
|
Instance Attribute Details
#access_manager ⇒ Object
attr_accessor :source_graph, :target_graph, :subject, :root_url, :source_rigor
59
60
61
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 59
def access_manager
@access_manager
end
|
#subject ⇒ Object
Also known as:
rdf
attr_accessor :source_graph, :target_graph, :subject, :root_url, :source_rigor
59
60
61
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 59
def subject
@subject
end
|
Instance Method Details
#add(property, value, extra = nil) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 109
def add(property, value, =nil)
property, value = normalize_triple(property, value, )
access_manager.insert([subject, property, value])
return value
end
|
#add_list(property, extra = nil) {|list| ... } ⇒ Object
153
154
155
156
157
158
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 153
def add_list(property, =nil)
list = FocusList.new(::RDF::Node.new, access_manager)
access_manager.insert([subject, normalize_property(property, ), list.subject])
yield list if block_given?
return list
end
|
#add_node(property, url = nil) ⇒ Object
139
140
141
142
143
144
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 139
def add_node(property, url=nil)
create_node(url) do |node|
add(property, node.subject)
yield node if block_given?
end
end
|
#all(prefix, property = nil) ⇒ Object
209
210
211
212
213
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 209
def all(prefix, property = nil)
return maybe_null( prefix, property,
forward_query_value( prefix, property )
)
end
|
#as_list ⇒ Object
235
236
237
238
239
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 235
def as_list
list = FocusList.new(subject, access_manager)
list.base_node = self
list
end
|
#create_node(url = nil) {|node| ... } ⇒ Object
Create a subject node without relationship to the rest of the graph
147
148
149
150
151
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 147
def create_node(url=nil)
node = wrap_node(normalize_resource(url))
yield node if block_given?
node
end
|
#delete(property, extra = nil) ⇒ Object
116
117
118
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 116
def delete(property, =nil)
access_manager.delete(:subject => subject, :predicate => normalize_property(property, ))
end
|
#dup ⇒ Object
85
86
87
88
89
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 85
def dup
other = self.class.new(access_manager.dup)
other.subject = subject
other
end
|
#find_or_add(property, url = nil, &block) ⇒ Object
Also known as:
first_or_add
120
121
122
123
124
125
126
127
128
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 120
def find_or_add(property, url=nil, &block)
value = first(property)
if value.nil?
value = add_node(property, url, &block)
else
yield value if block_given?
end
value
end
|
#first(prefix, property = nil) ⇒ Object
203
204
205
206
207
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 203
def first(prefix, property = nil)
return maybe_null( prefix, property,
forward_query_value( prefix, property ).first
)
end
|
#forward_properties ⇒ Object
241
242
243
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 241
def forward_properties
query_properties( build_query{|q| q.pattern([ normalize_resource(subject), :property, :value ])} )
end
|
#get(prefix, property = nil) ⇒ Object
Also known as:
[]
196
197
198
199
200
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 196
def get(prefix, property = nil)
return maybe_null( prefix, property,
single_or_enum(forward_query_value( prefix, property))
)
end
|
#inspect ⇒ Object
Also known as:
to_s
80
81
82
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 80
def inspect
"#<#{self.class.name}:0x#{"%x" % object_id} s:(#{subject.to_s}) p->o:#{forward_properties.inspect}>" end
|
#normalize_triple(property, value, extra = nil) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 92
def normalize_triple(property, value, =nil)
if not .nil?
property = [property, value]
value =
end
return normalize_property(property), normalize_term(value)
end
|
#relevant_prefixes ⇒ Object
XXX This probably wants to be handled completely in the MediaType handler
192
193
194
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 192
def relevant_prefixes
access_manager.relevant_prefixes
end
|
#rev(prefix, property = nil) ⇒ Object
XXX Maybe rev should return a decorator, so it looks like: focus.rev.get(…) or focus.rev.all(…)
217
218
219
220
221
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 217
def rev(prefix, property = nil)
return maybe_null( prefix, property,
single_or_enum(reverse_query_value( prefix, property))
)
end
|
#rev_all(prefix, property = nil) ⇒ Object
229
230
231
232
233
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 229
def rev_all(prefix, property = nil)
return maybe_null( prefix, property,
reverse_query_value(prefix, property)
)
end
|
#rev_first(prefix, property = nil) ⇒ Object
223
224
225
226
227
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 223
def rev_first(prefix, property = nil)
return maybe_null( prefix, property,
reverse_query_value(prefix, property).first
)
end
|
#reverse_properties ⇒ Object
245
246
247
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 245
def reverse_properties
query_properties( build_query{|q| q.pattern([ :value, :property, normalize_resource(subject)])} )
end
|
#root_url ⇒ Object
68
69
70
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 68
def root_url
@access_manager.resource
end
|
#root_url=(*value) ⇒ Object
187
188
189
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 187
def root_url=(*value) @root_url = normalize_resource(value)
end
|
#set(property, value, extra = nil) ⇒ Object
Also known as:
[]=
100
101
102
103
104
105
106
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 100
def set(property, value, =nil)
property, value = normalize_triple(property, value, )
delete(property)
add(property, value)
return value
end
|
#set_node(property, url = nil) ⇒ Object
Also known as:
node_at
131
132
133
134
135
136
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 131
def set_node(property, url=nil)
create_node(url) do |node|
set(property, node.subject)
yield node if block_given?
end
end
|
#to_context ⇒ Object
183
184
185
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 183
def to_context
normalize_context(subject)
end
|
#unwrap_value(value) ⇒ Object
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 172
def unwrap_value(value)
return nil if value.nil?
if RDF::Literal === value
value.object
elsif value == RDF.nil
nil
else
wrap_node(value)
end
end
|
#wrap_node(value) ⇒ Object
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/roadforest/rdf/graph-focus.rb', line 161
def wrap_node(value)
next_step = dup
if ::RDF::Node === value
next_step.root_url = self.root_url
else
next_step.root_url = normalize_context(value)
end
next_step.subject = value
next_step
end
|