Class: RdfContext::ConjunctiveGraph
Overview
ConjunctiveGraph - The top level container for all named Graphs sharing a Store
A ConjuctiveGraph is a graph that can contain other graphs. Graphs are kept distinct by a context, which is the identifier of the sub-graph. It is the union of all graphs in a Store.
For the sake of persistence, Conjunctive Graphs must be distinguished by identifiers (that may not necessarily be RDF identifiers or may be an RDF identifier normalized - SHA1/MD5 perhaps - for database naming purposes ) which could be referenced to indicate conjunctive queries (queries made across the entire conjunctive graph) or appear as nodes in asserted statements. In this latter case, such statements could be interpreted as being made about the entire 'known' universe.
Instance Attribute Summary
Attributes inherited from Graph
#allow_n3, #identifier, #store
Instance Method Summary (collapse)
-
- (Graph) add_quad(subject, predicate, object, context)
Adds a quad from the intended subject, predicate, object, and context.
-
- (Object) contexts
Contexts contained within the store.
-
- (Object) default_context
The default_context is a Graph having an identifier the same as the identifier of the store.
-
- (ConjunctiveGraph) initialize(options = {})
constructor
Store for ConjunctiveGraph must support contexts.
-
- (Graph) parse(stream, uri, options = {}, &block)
Parse source into a new context.
-
- (Array) triples(triple = Triple.new(nil, nil, nil), &block)
Triples across all contexts in store, optionally matching subject, predicate, or object.
Methods inherited from Graph
#<<, #==, #[], #add, #add_seq, #add_triple, #bind, #bnodes, #close, #commit, #contains?, #context_aware?, #destroy, #get_by_type, #graph?, #has_bnode_identifier?, #hash, #inspect, #isomorphic?, #merge!, #n3, #namespace, #nsbinding, #objects, #open, #predicates, #prefix, #properties, #qname, #remove, #rollback, #seq, #serialize, #size, #subjects, #sync_properties, #to_ntriples, #to_rdfxml, #to_s, #type_of, #uri_binding
Methods inherited from Resource
#bnode?, #graph?, #literal?, parse, #resource?, #uri?
Constructor Details
- (ConjunctiveGraph) initialize(options = {})
Store for ConjunctiveGraph must support contexts.
14 15 16 17 18 19 20 21 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 14 def initialize( = {}) unless [:store] && [:store].context_aware? raise GraphException.new("ConjunctiveGraph requires store supporting contexts") end super(:identifier => [:store].identifier, :store => [:store]) @context_aware = true end |
Instance Method Details
- (Graph) add_quad(subject, predicate, object, context)
Adds a quad from the intended subject, predicate, object, and context.
57 58 59 60 61 62 63 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 57 def add_quad(subject, predicate, object, context) graph = context if context.is_a?(Graph) graph ||= contexts.detect {|g| g.identifier == context} graph ||= Graph.new(:identifier => context, :store => @store) graph.add_triple(subject, predicate, object) graph end |
- (Object) contexts
Contexts contained within the store
30 31 32 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 30 def contexts @store.contexts end |
- (Object) default_context
The default_context is a Graph having an identifier the same as the identifier of the store.
25 26 27 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 25 def default_context @@default_context = Graph.new(:identifier => @store.identifier, :store => @store) end |
- (Graph) parse(stream, uri, options = {}, &block)
Parse source into a new context.
Create a new context (Graph) and parse into that.
76 77 78 79 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 76 def parse(stream, uri, = {}, &block) # :yields: triple graph = Graph.new(:identifier => uri, :store => self.store) Parser.parse(stream, uri, .merge(:graph => graph), &block) end |
- (Array) triples(triple = Triple.new(nil, nil, nil), &block)
Triples across all contexts in store, optionally matching subject, predicate, or object. Delegates to Store#triples.
39 40 41 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 39 def triples(triple = Triple.new(nil, nil, nil), &block) # :yields: triple, context @store.triples(triple, nil, &block) || [] end |