rdf_context 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.yardopts +10 -0
  2. data/{History.txt → History.rdoc} +8 -1
  3. data/Rakefile +9 -2
  4. data/VERSION +1 -1
  5. data/bin/rdf_context +5 -2
  6. data/lib/rdf_context/aggregate_graph.rb +31 -2
  7. data/lib/rdf_context/array_hacks.rb +3 -3
  8. data/lib/rdf_context/bnode.rb +3 -3
  9. data/lib/rdf_context/conjunctive_graph.rb +8 -8
  10. data/lib/rdf_context/duration.rb +17 -4
  11. data/lib/rdf_context/graph.rb +84 -46
  12. data/lib/rdf_context/literal.rb +36 -3
  13. data/lib/rdf_context/n3parser.rb +4 -4
  14. data/lib/rdf_context/namespace.rb +21 -8
  15. data/lib/rdf_context/parser.rb +31 -16
  16. data/lib/rdf_context/quoted_graph.rb +5 -4
  17. data/lib/rdf_context/rdfaparser.rb +176 -91
  18. data/lib/rdf_context/rdfxmlparser.rb +50 -13
  19. data/lib/rdf_context/serializer/abstract_serializer.rb +14 -4
  20. data/lib/rdf_context/serializer/nt_serializer.rb +5 -0
  21. data/lib/rdf_context/serializer/recursive_serializer.rb +4 -0
  22. data/lib/rdf_context/serializer/turtle_serializer.rb +28 -27
  23. data/lib/rdf_context/serializer/xml_serializer.rb +11 -9
  24. data/lib/rdf_context/store/abstract_sql_store.rb +47 -4
  25. data/lib/rdf_context/store/abstract_store.rb +73 -1
  26. data/lib/rdf_context/store/list_store.rb +25 -6
  27. data/lib/rdf_context/store/memory_store.rb +33 -1
  28. data/lib/rdf_context/store/sqlite3_store.rb +7 -4
  29. data/lib/rdf_context/term_utils.rb +6 -0
  30. data/lib/rdf_context/triple.rb +17 -6
  31. data/lib/rdf_context/uriref.rb +19 -3
  32. data/spec/html4-manifest.yml +176 -176
  33. data/spec/html5-manifest.yml +176 -176
  34. data/spec/rdfa_helper.rb +8 -2
  35. data/spec/rdfa_parser_spec.rb +1 -1
  36. data/spec/rdfcore/Manifest.yml +1561 -2626
  37. data/spec/swap_test/n3parser.yml +134 -279
  38. data/spec/swap_test/regression.yml +140 -305
  39. data/spec/turtle/manifest-bad.yml +155 -310
  40. data/spec/turtle/manifest.yml +155 -310
  41. data/spec/xhtml-manifest.yml +139 -587
  42. data/spec/xhtml11-manifest.yml +4405 -0
  43. metadata +21 -7
  44. data/.gitmodules +0 -3
@@ -6,14 +6,38 @@ module RdfContext
6
6
  OLD_TERMS = %w(aboutEach aboutEachPrefix bagID).map {|n| "http://www.w3.org/1999/02/22-rdf-syntax-ns##{n}"}
7
7
 
8
8
  # The Recursive Baggage
9
+ # @private
9
10
  class EvaluationContext # :nodoc:
11
+ # The base.
12
+ #
13
+ # This will usually be the URL of the document being processed,
14
+ # but it could be some other URL, set by some other mechanism,
15
+ # such as the (X)HTML base element. The important thing is that it establishes
16
+ # a URL against which relative paths can be resolved.
17
+ #
18
+ # @return [URIRef]
10
19
  attr_reader :base
20
+ # @return [URIRef]
11
21
  attr :subject, true
22
+ # A list of current, in-scope URI mappings.
23
+ #
24
+ # @return [Hash{String => Namespace}]
12
25
  attr :uri_mappings, true
26
+ # The language. Note that there is no default language.
27
+ #
28
+ # @return [String]
13
29
  attr :language, true
30
+ # Graph for binding Namespaces
31
+ # @return [Graph]
14
32
  attr :graph, true
33
+ # Counter for creating rdf:_n values
34
+ # @return [Integer]
15
35
  attr :li_counter, true
16
36
 
37
+ # @param [String] base Base URI for creating absolute URIs from relative URIs
38
+ # @param [Nokogiri::XML::Element] element XML Element context
39
+ # @param [Graph] graph Graph for binding Namespaces
40
+ # @return [RdfXmlParser::EvaluationContext]
17
41
  def initialize(base, element, graph)
18
42
  # Initialize the evaluation context, [5.1]
19
43
  self.base = base
@@ -27,6 +51,8 @@ module RdfContext
27
51
  end
28
52
 
29
53
  # Clone existing evaluation context adding information from element
54
+ # @param [Nokogiri::XML::Element] element XML Element context
55
+ # @return [RdfXmlParser::EvaluationContext]
30
56
  def clone(element, options = {})
31
57
  new_ec = EvaluationContext.new(@base, nil, @graph)
32
58
  new_ec.uri_mappings = self.uri_mappings.clone
@@ -39,26 +65,32 @@ module RdfContext
39
65
  end
40
66
 
41
67
  # Extract Evaluation Context from an element by looking at ancestors recurively
42
- def extract_from_ancestors(el)
43
- ancestors = el.ancestors
68
+ # @param [Nokogiri::XML::Element] element XML Element context
69
+ # @return [Hash{URIRef => Namespace}]
70
+ def extract_from_ancestors(element)
71
+ ancestors = element.ancestors
44
72
  while ancestors.length > 0
45
73
  a = ancestors.pop
46
74
  next unless a.element?
47
75
  extract_from_element(a)
48
76
  end
49
- extract_from_element(el)
77
+ extract_from_element(element)
50
78
  end
51
79
 
52
80
  # Extract Evaluation Context from an element
53
- def extract_from_element(el)
54
- b = el.attribute_with_ns("base", XML_NS.uri.to_s)
55
- lang = el.attribute_with_ns("lang", XML_NS.uri.to_s)
81
+ # @param [Nokogiri::XML::Element] element XML Element context
82
+ # @return [Hash{URIRef => Namespace}]
83
+ def extract_from_element(element)
84
+ b = element.attribute_with_ns("base", XML_NS.uri.to_s)
85
+ lang = element.attribute_with_ns("lang", XML_NS.uri.to_s)
56
86
  self.base = URIRef.new(b.to_s.rdf_unescape, self.base, :normalize => false) if b
57
87
  self.language = lang if lang
58
- self.uri_mappings.merge!(extract_mappings(el))
88
+ self.uri_mappings.merge!(extract_mappings(element))
59
89
  end
60
90
 
61
91
  # Extract the XMLNS mappings from an element
92
+ # @param [Nokogiri::XML::Element] element XML Element context
93
+ # @return [Hash{URIRef => Namespace}]
62
94
  def extract_mappings(element)
63
95
  mappings = {}
64
96
 
@@ -75,6 +107,8 @@ module RdfContext
75
107
  end
76
108
 
77
109
  # Produce the next list entry for this context
110
+ # @param [URIRef] predicate
111
+ # @return [URIRef]
78
112
  def li_next(predicate)
79
113
  @li_counter += 1
80
114
  predicate = Addressable::URI.parse(predicate.to_s)
@@ -83,6 +117,8 @@ module RdfContext
83
117
  end
84
118
 
85
119
  # Set XML base. Ignore any fragment
120
+ # @param [Nokogiri::XML::Element] b
121
+ # @return [String] b.to_s
86
122
  def base=(b)
87
123
  b = Addressable::URI.parse(b.to_s)
88
124
  b.fragment = nil
@@ -103,12 +139,13 @@ module RdfContext
103
139
  #
104
140
  # Optionally, the stream may be a string or Nokogiri::XML::Document
105
141
  #
106
- # @param [IO] stream:: the RDF/XML IO stream, string or Nokogiri::XML::Document
107
- # @param [String] uri:: the URI of the document
108
- # @param [Hash] options:: Parser options, one of
109
- # <em>options[:debug]</em>:: Array to place debug messages
110
- # <em>options[:strict]</em>:: Raise Error if true, continue with lax parsing, otherwise
111
- # @return [Graph]:: Returns the graph containing parsed triples
142
+ # @param [Nokogiri::XML::Document, #read, #to_s] stream the HTML+RDFa IO stream, string, Nokogiri::HTML::Document or Nokogiri::XML::Document
143
+ # @param [String] uri (nil) the URI of the document
144
+ # @option options [Array] :debug (nil) Array to place debug messages
145
+ # @option options [Boolean] :strict (false) Raise Error if true, continue with lax parsing, otherwise
146
+ # @return [Graph] Returns the graph containing parsed triples
147
+ # @yield [triple]
148
+ # @yieldparam [Triple] triple
112
149
  # @raise [Error]:: Raises RdfError if _strict_
113
150
  def parse(stream, uri = nil, options = {}, &block) # :yields: triple
114
151
  super
@@ -3,8 +3,15 @@ require File.join(File.dirname(__FILE__), '..', 'uriref')
3
3
  module RdfContext
4
4
  # Abstract serializer
5
5
  class AbstractSerializer
6
- attr_accessor :graph, :base
6
+ # @return [Graph]
7
+ attr_accessor :graph
7
8
 
9
+ # @return [String]
10
+ attr_accessor :base
11
+
12
+ # New AbstractSerializer
13
+ # @param [Graph] graph
14
+ # @return [AbstractSerializer]
8
15
  def initialize(graph)
9
16
  @graph = graph
10
17
  @base = nil
@@ -12,12 +19,15 @@ module RdfContext
12
19
 
13
20
  # Serialize the graph
14
21
  #
15
- # @param [IO, StreamIO] stream:: Stream in which to place serialized graph
16
- # @param [Hash] options:: Options for parser
17
- # <em>options[:base]</em>:: Base URI of graph, used to shorting URI references
22
+ # @param [IO, StreamIO] stream Stream in which to place serialized graph
23
+ # @option options [URIRef, String] :base (nil) Base URI of graph, used to shorting URI references
24
+ # @return [void]
18
25
  def serialize(stream, options = {})
19
26
  end
20
27
 
28
+ # Create a relative version of the _uri_ parameter if a _base_ URI is defined
29
+ # @param [#to_s] uri
30
+ # @return [String]
21
31
  def relativize(uri)
22
32
  uri = uri.to_s
23
33
  self.base ? uri.sub(/^#{self.base}/, "") : uri
@@ -3,6 +3,11 @@ require File.join(File.dirname(__FILE__), 'abstract_serializer')
3
3
  module RdfContext
4
4
  # Serialize RDF graphs in NTriples format
5
5
  class NTSerializer < AbstractSerializer
6
+ # Serialize the graph
7
+ #
8
+ # @param [IO, StreamIO] stream Stream in which to place serialized graph
9
+ # @option options [URIRef, String] :base (nil) Base URI of graph, used to shorting URI references
10
+ # @return [void]
6
11
  def serialize(stream, base = nil)
7
12
  @graph.triples.collect do |t|
8
13
  stream.write(t.to_ntriples + "\n")
@@ -8,12 +8,16 @@ module RdfContext
8
8
  MAX_DEPTH = 10
9
9
  INDENT_STRING = " "
10
10
 
11
+ # New RecursiveSerializer
12
+ # @param [Graph] graph
13
+ # @return [RecursiveSerializer]
11
14
  def initialize(graph)
12
15
  super(graph)
13
16
  @stream = nil
14
17
  self.reset
15
18
  end
16
19
 
20
+ protected
17
21
  def top_classes; [RDFS_NS.Class]; end
18
22
  def predicate_order; [RDF_TYPE, RDFS_NS.label, DC_NS.title]; end
19
23
 
@@ -7,6 +7,34 @@ module RdfContext
7
7
  VERB = 1
8
8
  OBJECT = 2
9
9
 
10
+ # Serialize the graph
11
+ #
12
+ # @param [IO, StreamIO] stream Stream in which to place serialized graph
13
+ # @option options [URIRef, String] :base (nil) Base URI of graph, used to shorting URI references
14
+ # @return [void]
15
+ def serialize(stream, options = {})
16
+ puts "\nserialize: #{@graph.inspect}" if $DEBUG
17
+ reset
18
+ @stream = stream
19
+ @base = options[:base]
20
+
21
+ @graph.bind(RDF_NS)
22
+ @graph.bind(RDFS_NS)
23
+
24
+ preprocess
25
+ start_document
26
+
27
+ order_subjects.each do |subject|
28
+ #puts "subj: #{subject.inspect}"
29
+ unless is_done?(subject)
30
+ statement(subject)
31
+ end
32
+ end
33
+
34
+ end_document
35
+ end
36
+
37
+ protected
10
38
  def reset
11
39
  super
12
40
  @shortNames = {}
@@ -188,32 +216,5 @@ module RdfContext
188
216
  subject_done(subject)
189
217
  s_squared(subject) || s_default(subject)
190
218
  end
191
-
192
- # Serialize the graph
193
- #
194
- # @param [IO, StreamIO] stream:: Stream in which to place serialized graph
195
- # @param [Hash] options:: Options for parser
196
- # <em>options[:base]</em>:: Base URI of graph, used to shorting URI references
197
- def serialize(stream, options = {})
198
- puts "\nserialize: #{@graph.inspect}" if $DEBUG
199
- reset
200
- @stream = stream
201
- @base = options[:base]
202
-
203
- @graph.bind(RDF_NS)
204
- @graph.bind(RDFS_NS)
205
-
206
- preprocess
207
- start_document
208
-
209
- order_subjects.each do |subject|
210
- #puts "subj: #{subject.inspect}"
211
- unless is_done?(subject)
212
- statement(subject)
213
- end
214
- end
215
-
216
- end_document
217
- end
218
219
  end
219
220
  end
@@ -5,6 +5,9 @@ module RdfContext
5
5
  class XmlSerializer < RecursiveSerializer
6
6
  VALID_ATTRIBUTES = [:none, :untyped, :typed]
7
7
 
8
+ # New XmlSerializer
9
+ # @param [Graph] graph
10
+ # @return [XmlSerializer]
8
11
  def initialize(graph)
9
12
  super
10
13
  @force_RDF_about = {}
@@ -12,16 +15,15 @@ module RdfContext
12
15
 
13
16
  # Serialize the graph
14
17
  #
15
- # @param [IO, StreamIO] stream:: Stream in which to place serialized graph
16
- # @param [Hash] options:: Options for parser
17
- # <em>options[:base]</em>:: Base URI of graph, used to shorting URI references
18
- # <em>options[:max_depth]</em>:: Maximum depth for recursively defining resources, defaults to 3
19
- # <em>options[:lang]</em>:: Output as root xml:lang attribute, and avoid generation xml:lang where possible
20
- # <em>options[:attributes]</em>:: How to use XML attributes when serializing, one of :none, :untyped, :typed. The default is none.
21
- #
22
- # -- Serialization Examples
23
- # attributes == :none
18
+ # @param [IO, StreamIO] stream Stream in which to place serialized graph
19
+ # @option options [URIRef, String] :base (nil) Base URI of graph, used to shorting URI references
20
+ # @option options [Integer] :max_depth (3) Maximum depth for recursively defining resources
21
+ # @option options [String] :lang (nil) Output as root xml:lang attribute, and avoid generation xml:lang where possible
22
+ # @option options [:none, :untyped, :typed] :attributes (:none) How to use XML attributes when serializing, one of :none, :untyped, :typed. The default is none.
23
+ # @return [void]
24
24
  #
25
+ # @example
26
+ # attributes == :none
25
27
  # serialize(io, :attributes => none)
26
28
  def serialize(stream, options = {})
27
29
  @max_depth = options[:max_depth] || 3
@@ -31,8 +31,10 @@ module RdfContext
31
31
 
32
32
  STRONGLY_TYPED_TERMS = false
33
33
 
34
- # @param[URIRef] identifier:: URIRef of the Store. Defaults to CWD
35
- # @param[Hash] configuration:: Hash containing infomation open can use to connect to datastore.
34
+ # Create a new AbstractSQLStore Store, should be subclassed
35
+ # @param [URIRef] identifier
36
+ # @param[Hash] configuration Specific to type of storage
37
+ # @return [AbstractSQLStore]
36
38
  def initialize(identifier = nil, configuration = {})
37
39
  @literalCache = {}
38
40
  @otherCache = {}
@@ -50,14 +52,20 @@ module RdfContext
50
52
  end
51
53
 
52
54
  # Supports contexts
55
+ # @return [true]
53
56
  def context_aware?; true; end
54
57
 
55
58
  # Supports formulae
59
+ # @return [true]
56
60
  def formula_aware?; true; end
57
61
 
58
62
  # Supports transactions
63
+ # @return [true]
59
64
  def transaction_aware?; true; end
60
-
65
+
66
+ # Close the store
67
+ # @param [Boolean] commit_pending_transactions (false)
68
+ # @return [void]
61
69
  def close(commit_pending_transactions = false)
62
70
  @db.commit if commit_pending_transactions && @db.transaction_active?
63
71
  @db.close
@@ -65,6 +73,11 @@ module RdfContext
65
73
 
66
74
  # Add a triple to the store
67
75
  # Add to default context, if context is nil
76
+ #
77
+ # @param [Triple] triple
78
+ # @param [Graph] context (nil)
79
+ # @param [Boolean] quoted (false) A quoted triple, for Formulae
80
+ # @return [Triple]
68
81
  def add(triple, context = nil, quoted = false)
69
82
  context ||= @identifier
70
83
  executeSQL("SET AUTOCOMMIT=0") if @autocommit_default
@@ -87,6 +100,10 @@ module RdfContext
87
100
  # Remove a triple from the context and store
88
101
  #
89
102
  # if subject, predicate and object are nil and context is not nil, the context is removed
103
+ #
104
+ # @param [Triple] triple
105
+ # @param [Graph] context (nil)
106
+ # @return [void]
90
107
  def remove(triple, context = nil)
91
108
  if context
92
109
  if triple.subject == nil && triple.predicate.nil? && triple.object.nil?
@@ -147,7 +164,15 @@ module RdfContext
147
164
  # triple columns: subject,predicate,object,context,termComb,objLanguage,objDatatype
148
165
  # class membership columns: member,klass,context termComb
149
166
  #
150
- # FIXME: These union all selects *may* be further optimized by joins
167
+ # @todo These union all selects *may* be further optimized by joins
168
+ #
169
+ # @param [Triple] triple
170
+ # @param [Graph] context (nil)
171
+ # @return [Array<Triplle>]
172
+ # @raise [StoreException] Not Implemented
173
+ # @yield [triple, context]
174
+ # @yieldparam [Triple] triple
175
+ # @yieldparam [Graph] context
151
176
  def triples(triple, context = nil) # :yields: triple, context
152
177
  parameters = []
153
178
 
@@ -261,6 +286,11 @@ module RdfContext
261
286
  results.uniq
262
287
  end
263
288
 
289
+ # Check to see if this store contains the specified triple
290
+ #
291
+ # @param [Triple] triple
292
+ # @param [Graph] context (nil)
293
+ # @return [Boolean]
264
294
  def contains?(triple, context = nil)
265
295
  #puts "contains? #{triple}"
266
296
  object = triple.object
@@ -276,6 +306,8 @@ module RdfContext
276
306
  end
277
307
 
278
308
  # Number of statements in the store.
309
+ # @param [Graph] context (nil)
310
+ # @return [Integer]
279
311
  def size(context = nil)
280
312
  parameters = []
281
313
  quotedContext = assertedContext = typeContext = literalContext = nil
@@ -364,6 +396,8 @@ module RdfContext
364
396
  end
365
397
 
366
398
  # Contexts containing the triple (no matching), or total number of contexts in store
399
+ # @param [Triple] triple (nil) Containing the triple/pattern if not nil
400
+ # @return [Array<Graph>]
367
401
  def contexts(triple = nil)
368
402
  parameters = []
369
403
 
@@ -505,6 +539,9 @@ module RdfContext
505
539
  # Namespace persistence interface implementation
506
540
  #
507
541
  # Bind namespace to store, returns bound namespace
542
+ #
543
+ # @param [Nameespace] namespace the namespace to bind
544
+ # @return [Namespace] The newly bound or pre-existing namespace.
508
545
  def bind(namespace)
509
546
  # Remove existing bindings for the same URI
510
547
  executeSQL("DELETE FROM #{namespace_binds} WHERE prefix=?", namespace.prefix.to_s)
@@ -521,6 +558,8 @@ module RdfContext
521
558
  end
522
559
 
523
560
  # Namespace for prefix
561
+ # @param [String] prefix
562
+ # @return [Namespace]
524
563
  def namespace(prefix)
525
564
  @namespaceCache ||= {}
526
565
  @namespaceUriCache ||= {}
@@ -535,6 +574,8 @@ module RdfContext
535
574
  end
536
575
 
537
576
  # Prefix for namespace
577
+ # @param [Namespace] namespcae
578
+ # @return [String]
538
579
  def prefix(namespace)
539
580
  uri = namespace.is_a?(Namespace) ? namespace.uri.to_s : namespace
540
581
 
@@ -550,6 +591,7 @@ module RdfContext
550
591
  end
551
592
 
552
593
  # Hash of prefix => Namespace bindings
594
+ # @return [Hash{String => Namespace}]
553
595
  def nsbinding
554
596
  unless @nsbinding.is_a?(Hash)
555
597
  @nsbinding = {}
@@ -568,6 +610,7 @@ module RdfContext
568
610
  end
569
611
 
570
612
  # Hash of uri => Namespace bindings
613
+ # @return [Hash{URIRef => Namespace}]
571
614
  def uri_binding
572
615
  nsbinding
573
616
  @uri_binding
@@ -3,6 +3,10 @@ module RdfContext
3
3
  class AbstractStore
4
4
  attr_reader :nsbinding, :uri_binding, :identifier
5
5
 
6
+ # Create a new AbstractStore Store, should be subclassed
7
+ # @param [Resource] identifier
8
+ # @param[Hash] configuration Specific to type of storage
9
+ # @return [AbstractStore]
6
10
  def initialize(identifier = nil, configuration = {})
7
11
  @nsbinding = {}
8
12
  # Reverse namespace binding
@@ -11,17 +15,54 @@ module RdfContext
11
15
  @identifier = identifier || BNode.new
12
16
  end
13
17
 
18
+ # Is store Context Aware, capable of being used for named graphs?
19
+ # @return [false]
14
20
  def context_aware?; false; end
21
+
22
+ # Is store Formulae Aware, capable of storing variables?
23
+ # @return [false]
15
24
  def formula_aware?; false; end
25
+
26
+ # Is store Transaction Aware, capable of rollback?
27
+ # @return [false]
16
28
  def transaction_aware?; false; end
17
29
 
18
30
  # Interfaces that must be implemented
31
+
32
+ # A generator over all matching triples
33
+ # @param [Triple] triple
34
+ # @param [Graph] context (nil)
35
+ # @return [Array<Triplle>]
36
+ # @raise [StoreException] Not Implemented
37
+ # @yield [triple, context]
38
+ # @yieldparam [Triple] triple
39
+ # @yieldparam [Graph] context
19
40
  def triples(triple, context = nil) # :yields: triple, context
20
41
  raise StoreException, "not implemented"
21
42
  end
43
+
44
+ # Add triple to store
45
+ # @param [Triple] triple
46
+ # @param [Graph] context (nil)
47
+ # @param [Boolean] quoted (false) A quoted triple, for Formulae
48
+ # @raise [StoreException] Not Implemented
49
+ # @return [Triple]
22
50
  def add(triple, context = nil, quoted = false); raise StoreException, "not implemented"; end
51
+
52
+ # Remove a triple from the store
53
+ # @param [Triple] triple
54
+ # @param [Graph] context (nil)
55
+ # @raise [StoreException] Not Implemented
56
+ # @return [void]
23
57
  def remove(triple, context = nil); raise StoreException, "not implemented"; end
24
58
 
59
+ # Check to see if this store contains the specified triple
60
+ # @param [Triple] triple
61
+ # @param [Graph] context (nil) ignored
62
+ # @raise [StoreException] Not Implemented
63
+ # @return [Boolean]
64
+ def contains?(triple, context = nil); raise StoreException, "not implemented"; end
65
+
25
66
  # Default (sub-optimal) implemenations of interfaces
26
67
  def inspect
27
68
  "#{self.class}[identifier=#{identifier.inspect}]"
@@ -33,7 +74,11 @@ module RdfContext
33
74
  def commit; end
34
75
  def rollback; end
35
76
 
36
- # Bind namespace to store, returns bound namespace
77
+ ##
78
+ # Bind a namespace to the store.
79
+ #
80
+ # @param [Nameespace] namespace the namespace to bind
81
+ # @return [Namespace] The newly bound or pre-existing namespace.
37
82
  def bind(namespace)
38
83
  # Over-write an empty prefix
39
84
  uri = namespace.uri.to_s
@@ -45,16 +90,22 @@ module RdfContext
45
90
  end
46
91
 
47
92
  # Namespace for prefix
93
+ # @param [String] prefix
94
+ # @return [Namespace]
48
95
  def namespace(prefix)
49
96
  @nsbinding[prefix.to_s]
50
97
  end
51
98
 
52
99
  # Prefix for namespace
100
+ # @param [Namespace] namespcae
101
+ # @return [String]
53
102
  def prefix(namespace)
54
103
  namespace.is_a?(Namespace) ? @uri_binding[namespace.uri.to_s].prefix : @uri_binding[namespace].prefix
55
104
  end
56
105
 
57
106
  # Get all BNodes with usage count used within graph
107
+ # @param [Graph] context (nil)
108
+ # @return [Array<BNode>]
58
109
  def bnodes(context = nil)
59
110
  bn = {}
60
111
  triples(Triple.new(nil, nil, nil), context) do |t, ctx|
@@ -74,10 +125,31 @@ module RdfContext
74
125
  bn
75
126
  end
76
127
 
128
+
129
+ # Number of Triples in the graph
130
+ # @param [Graph] context (nil)
131
+ # @return [Integer]
77
132
  def size(context = nil); triples(Triple.new(nil, nil, nil), context).size; end
133
+
134
+ # List of distinct subjects in graph
135
+ # @param [Graph] context (nil)
136
+ # @return [Array<Resource>]
78
137
  def subjects(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.subject}.uniq; end
138
+
139
+ # List of distinct predicates in graph
140
+ # @param [Graph] context (nil)
141
+ # @return [Array<Resource>]
79
142
  def predicates(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.predicate}.uniq; end
143
+
144
+ # List of distinct objects in graph
145
+ # @param [Graph] context (nil)
146
+ # @return [Array<Resource>]
80
147
  def objects(context = nil); triples(Triple.new(nil, nil, nil), context).map {|t| t.object}.uniq; end
148
+
149
+ # Return an indexed element from the graph
150
+ # @param [Integer] item Index into the serialized store
151
+ # @param [Graph] context
152
+ # @return [Array<Triple>]
81
153
  def item(item, context = nil) triples(Triple.new(nil, nil, nil), context)[item]; end
82
154
  end
83
155
  end