Class: RdfContext::ConjunctiveGraph
- Defined in:
- lib/rdf_context/conjunctive_graph.rb
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
-
#add_quad(subject, predicate, object, context) ⇒ Graph
Adds a quad from the intended subject, predicate, object, and context.
-
#contexts ⇒ Object
Contexts contained within the store.
-
#default_context ⇒ Object
The default_context is a Graph having an identifier the same as the identifier of the store.
-
#initialize(options = {}) ⇒ ConjunctiveGraph
constructor
Store for ConjunctiveGraph must support contexts.
-
#parse(stream, uri, options = {}, &block) ⇒ Graph
Parse source into a new context.
-
#triples(triple = Triple.new(nil, nil, nil), &block) ⇒ Array
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
#initialize(options = {}) ⇒ ConjunctiveGraph
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
#add_quad(subject, predicate, object, context) ⇒ Graph
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 |
#contexts ⇒ Object
Contexts contained within the store
30 31 32 |
# File 'lib/rdf_context/conjunctive_graph.rb', line 30 def contexts @store.contexts end |
#default_context ⇒ Object
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 |
#parse(stream, uri, options = {}, &block) ⇒ Graph
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 |
#triples(triple = Triple.new(nil, nil, nil), &block) ⇒ Array
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 |