Module: RDF::Enumerable
- Extended by:
- Util::Aliasing::LateBound
- Includes:
- Enumerable, Countable, Isomorphic
- Included in:
- JSON::LD::Resource, Dataset, Enumerator, Graph, List, MergeGraph, N3::Algebra::Builtin, N3::Algebra::Formula, N3::Reasoner, Normalize::Carroll2001, Normalize::URDNA2015, Query, Query::Solution, Queryable::Enumerator, Reader, Transaction, SHACL::ValidationReport, SHACL::ValidationResult
- Defined in:
- vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb,
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-isomorphic-e16080d8315a/lib/rdf/isomorphic.rb,
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-n3-2af20d654efc/lib/rdf/n3/extensions.rb,
vendor/bundler/ruby/3.1.0/bundler/gems/rdf-reasoner-31c78d18a7e1/lib/rdf/reasoner/extensions.rb
Overview
Extend RDF::Enumerables with these functions.
Defined Under Namespace
Classes: Enumerator
Constant Summary collapse
- @@entailments =
{}
Instance Attribute Summary collapse
-
#existentials ⇒ Array<RDF::Query::Variable>
Existential quantifiers defined on this enumerable.
-
#universals ⇒ Array<RDF::Query::Variable>
Universal quantifiers defined on this enumerable.
Class Method Summary collapse
-
.add_entailment(method, proc) ⇒ Object
Add an entailment method.
Instance Method Summary collapse
-
#dump(*args, **options) ⇒ String
Returns a serialized string representation of
self
. -
#each_graph ⇒ Object
Iterates the given block for each RDF graph in
self
. -
#each_object ⇒ Object
Iterates the given block for each unique RDF object term.
-
#each_predicate ⇒ Object
Iterates the given block for each unique RDF predicate term.
-
#each_quad ⇒ Object
Iterates the given block for each RDF quad.
-
#each_statement(&block) ⇒ Object
Iterates the given block for each RDF statement.
-
#each_subject ⇒ Object
Iterates the given block for each unique RDF subject term.
-
#each_term ⇒ Object
Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
-
#each_triple ⇒ Object
Iterates the given block for each RDF triple.
-
#entail(*rules, &block) ⇒ Object
Perform entailments on this enumerable in a single pass, yielding entailed statements.
-
#enum_graph ⇒ Enumerator<RDF::Graph>
(also: #enum_graphs)
Returns an enumerator for #each_graph.
-
#enum_object ⇒ Enumerator<RDF::Term>
(also: #enum_objects)
Returns an enumerator for #each_object.
-
#enum_predicate ⇒ Enumerator<RDF::URI>
(also: #enum_predicates)
Returns an enumerator for #each_predicate.
-
#enum_quad ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>
(also: #enum_quads)
Returns an enumerator for #each_quad.
-
#enum_statement ⇒ Enumerator<RDF::Statement>
(also: #enum_statements)
Returns an enumerator for #each_statement.
-
#enum_subject ⇒ Enumerator<RDF::Resource>
(also: #enum_subjects)
Returns an enumerator for #each_subject.
-
#enum_term ⇒ Enumerator<RDF::Term>
(also: #enum_terms)
Returns an enumerator for #each_term.
-
#enum_triple ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term)>
(also: #enum_triples)
Returns an enumerator for #each_triple.
-
#graph?(graph_name) ⇒ Boolean
(also: #has_graph?)
Returns
true
ifself
contains the given RDF graph_name. -
#graph_names(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF graph names, other than the default graph.
-
#invalid? ⇒ Boolean
Returns
true
if value is not valid. -
# ⇒ String
protected
Implements #to_writer for each available instance of Writer, based on the writer symbol.
-
#object?(value) ⇒ Boolean
(also: #has_object?)
Returns
true
ifself
contains the given RDF object term. -
#objects(unique: true) ⇒ Array<RDF::Term>
Returns all unique RDF object terms.
-
#predicate?(value) ⇒ Boolean
(also: #has_predicate?)
Returns
true
ifself
contains the given RDF predicate term. -
#predicates(unique: true) ⇒ Array<RDF::URI>
Returns all unique RDF predicate terms.
-
#project_graph(graph_name) ⇒ Object
Limits statements to be from a specific graph.
-
#quad?(quad) ⇒ Boolean
(also: #has_quad?)
Returns
true
ifself
contains the given RDF quad. -
#quads(**options) ⇒ Array<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>
Returns all RDF quads.
- #respond_to_missing?(name, include_private = false) ⇒ Boolean protected
- #statement?(*args) ⇒ Object (also: #has_statement?, #include?)
-
#statements(**options) ⇒ Array<RDF::Statement>
Returns all RDF statements.
-
#subject?(value) ⇒ Boolean
(also: #has_subject?)
Returns
true
ifself
contains the given RDF subject term. -
#subjects(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF subject terms.
-
#supports?(feature) ⇒ Boolean
Returns
true
if this enumerable supports the givenfeature
. - #term?(*args) ⇒ Object (also: #has_term?)
-
#terms(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF terms (subjects, predicates, objects, and graph_names).
-
#to_a ⇒ Array
Returns all RDF statements in
self
as an array. -
#to_h ⇒ Hash
Returns all RDF object terms indexed by their subject and predicate terms.
-
#to_set ⇒ Set
Returns all RDF statements in
self
as a set. -
#triple?(triple) ⇒ Boolean
(also: #has_triple?)
Returns
true
ifself
contains the given RDF triple. -
#triples(**options) ⇒ Array<Array(RDF::Resource, RDF::URI, RDF::Term)>
Returns all RDF triples.
-
#valid? ⇒ Boolean
Returns
true
if all statements are valid. -
#validate! ⇒ RDF::Enumerable
(also: #validate)
Default validate! implementation, overridden in concrete classes.
Methods included from Util::Aliasing::LateBound
Methods included from Isomorphic
#bijection_to, #isomorphic_with?
Methods included from Countable
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
# ⇒ String (protected)
796 797 798 799 800 801 802 803 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 796 def method_missing(meth, *args) writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_" if writer writer.buffer(standard_prefixes: true) {|w| w << self} else super end end |
Instance Attribute Details
#existentials ⇒ Array<RDF::Query::Variable>
Existential quantifiers defined on this enumerable
10 11 12 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-n3-2af20d654efc/lib/rdf/n3/extensions.rb', line 10 def existentials @existentials end |
#universals ⇒ Array<RDF::Query::Variable>
Universal quantifiers defined on this enumerable
14 15 16 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-n3-2af20d654efc/lib/rdf/n3/extensions.rb', line 14 def universals @universals end |
Class Method Details
.add_entailment(method, proc) ⇒ Object
Add an entailment method. The method accepts no arguments, and returns or yields an array of values associated with the particular entailment method
148 149 150 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-reasoner-31c78d18a7e1/lib/rdf/reasoner/extensions.rb', line 148 def add_entailment(method, proc) @@entailments[method] = proc end |
Instance Method Details
#dump(*args, **options) ⇒ String
Returns a serialized string representation of self
.
Before calling this method you may need to explicitly require a serialization extension for the specified format.
781 782 783 784 785 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 781 def dump(*args, **) writer = RDF::Writer.for(*args) raise RDF::WriterError, "No writer found using #{args.inspect}" unless writer writer.dump(self, nil, **) end |
#each_graph {|graph| ... } #each_graph ⇒ Enumerator<RDF::Graph>
Iterates the given block for each RDF graph in self
.
If no block was given, returns an enumerator.
The order in which graphs are yielded is undefined.
699 700 701 702 703 704 705 706 707 708 709 710 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 699 def each_graph if block_given? yield RDF::Graph.new(graph_name: nil, data: self) # FIXME: brute force, repositories should override behavior if supports?(:graph_name) enum_statement.map(&:graph_name).uniq.compact.each do |graph_name| yield RDF::Graph.new(graph_name: graph_name, data: self) end end end enum_graph end |
#each_object {|object| ... } #each_object ⇒ Enumerator<RDF::Term>
Iterates the given block for each unique RDF object term.
If no block was given, returns an enumerator.
The order in which values are yielded is undefined.
504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 504 def each_object # FIXME: deduplication if block_given? values = {} each_statement do |statement| value = statement.object unless value.nil? || values.include?(value) values[value] = true yield value end end end enum_object end |
#each_predicate {|predicate| ... } #each_predicate ⇒ Enumerator<RDF::URI>
Iterates the given block for each unique RDF predicate term.
If no block was given, returns an enumerator.
The order in which values are yielded is undefined.
437 438 439 440 441 442 443 444 445 446 447 448 449 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 437 def each_predicate if block_given? values = {} each_statement do |statement| value = statement.predicate unless value.nil? || values.include?(value.to_s) values[value.to_s] = true yield value end end end enum_predicate end |
#each_quad {|subject, predicate, object, graph_name| ... } #each_quad ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>
Iterates the given block for each RDF quad.
If no block was given, returns an enumerator.
The order in which quads are yielded is undefined.
308 309 310 311 312 313 314 315 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 308 def each_quad if block_given? each_statement do |statement| yield(*statement.to_quad) end end enum_quad end |
#each_statement {|statement| ... } #each_statement ⇒ Enumerator<RDF::Statement>
Iterates the given block for each RDF statement.
If no block was given, returns an enumerator.
The order in which statements are yielded is undefined.
180 181 182 183 184 185 186 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 180 def each_statement(&block) if block_given? # Invoke {#each} in the containing class: each(&block) end enum_statement end |
#each_subject {|subject| ... } #each_subject ⇒ Enumerator<RDF::Resource>
Iterates the given block for each unique RDF subject term.
If no block was given, returns an enumerator.
The order in which values are yielded is undefined.
371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 371 def each_subject if block_given? values = {} each_statement do |statement| value = statement.subject unless value.nil? || values.include?(value.to_s) values[value.to_s] = true yield value end end end enum_subject end |
#each_term {|term| ... } #each_term ⇒ Enumerator<RDF::Term>
Iterates the given block for each unique RDF term (subject, predicate, object, or graph_name).
If no block was given, returns an enumerator.
The order in which values are yielded is undefined.
588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 588 def each_term if block_given? values = {} each_statement do |statement| statement.terms.each do |value| unless values.include?(value.hash) values[value.hash] = true yield value end end end end enum_term end |
#each_triple {|subject, predicate, object| ... } #each_triple ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term)>
Iterates the given block for each RDF triple.
If no block was given, returns an enumerator.
The order in which triples are yielded is undefined.
245 246 247 248 249 250 251 252 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 245 def each_triple if block_given? each_statement do |statement| yield(*statement.to_triple) end end enum_triple end |
#entail {|statement| ... } #entail ⇒ Enumerator
Perform entailments on this enumerable in a single pass, yielding entailed statements.
For best results, either run rules separately expanding the enumberated graph, or run repeatedly until no new statements are added to the enumerable containing both original and entailed statements. As :subClassOf
and :subPropertyOf
entailments are implicitly recursive, this may not be necessary except for extreme cases.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-reasoner-31c78d18a7e1/lib/rdf/reasoner/extensions.rb', line 169 def entail(*rules, &block) if block_given? rules = %w(subClassOf subPropertyOf domain range).map(&:to_sym) if rules.empty? self.each do |statement| rules.each {|rule| statement.entail(rule, &block)} end else # Otherwise, return an Enumerator with the entailed statements this = self RDF::Queryable::Enumerator.new do |yielder| this.entail(*rules) {|y| yielder << y} end end end |
#enum_graph ⇒ Enumerator<RDF::Graph> Also known as: enum_graphs
Returns an enumerator for #each_graph.
718 719 720 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 718 def enum_graph enum_for(:each_graph) end |
#enum_object ⇒ Enumerator<RDF::Term> Also known as: enum_objects
Returns an enumerator for #each_object.
523 524 525 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 523 def enum_object enum_for(:each_object) end |
#enum_predicate ⇒ Enumerator<RDF::URI> Also known as: enum_predicates
Returns an enumerator for #each_predicate.
456 457 458 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 456 def enum_predicate enum_for(:each_predicate) end |
#enum_quad ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)> Also known as: enum_quads
Returns an enumerator for #each_quad.
322 323 324 325 326 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 322 def enum_quad Countable::Enumerator.new do |yielder| each_quad {|s, p, o, c| yielder << [s, p, o, c]} end end |
#enum_statement ⇒ Enumerator<RDF::Statement> Also known as: enum_statements
Returns an enumerator for #each_statement. FIXME: enum_for doesn't seem to be working properly in JRuby 1.7, so specs are marked pending
195 196 197 198 199 200 201 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 195 def enum_statement # Ensure that statements are queryable, countable and enumerable this = self Queryable::Enumerator.new do |yielder| this.send(:each_statement) {|y| yielder << y} end end |
#enum_subject ⇒ Enumerator<RDF::Resource> Also known as: enum_subjects
Returns an enumerator for #each_subject.
390 391 392 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 390 def enum_subject enum_for(:each_subject) end |
#enum_term ⇒ Enumerator<RDF::Term> Also known as: enum_terms
Returns an enumerator for #each_term.
609 610 611 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 609 def enum_term enum_for(:each_term) end |
#enum_triple ⇒ Enumerator<Array(RDF::Resource, RDF::URI, RDF::Term)> Also known as: enum_triples
Returns an enumerator for #each_triple.
259 260 261 262 263 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 259 def enum_triple Countable::Enumerator.new do |yielder| each_triple {|s, p, o| yielder << [s, p, o]} end end |
#graph?(graph_name) ⇒ Boolean Also known as: has_graph?
Returns true
if self
contains the given RDF graph_name.
636 637 638 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 636 def graph?(graph_name) enum_statement.any? {|s| s.graph_name == graph_name} end |
#graph_names(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF graph names, other than the default graph.
622 623 624 625 626 627 628 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 622 def graph_names(unique: true) unless unique enum_statement.map(&:graph_name).compact # TODO: optimize else enum_graph.map(&:graph_name).compact end end |
#invalid? ⇒ Boolean
Returns true
if value is not valid
115 116 117 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 115 def invalid? !valid? end |
#object?(value) ⇒ Boolean Also known as: has_object?
Returns true
if self
contains the given RDF object term.
481 482 483 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 481 def object?(value) enum_object.include?(value) end |
#objects(unique: true) ⇒ Array<RDF::Term>
Returns all unique RDF object terms.
468 469 470 471 472 473 474 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 468 def objects(unique: true) unless unique enum_statement.map(&:object) # TODO: optimize else enum_object.to_a end end |
#predicate?(value) ⇒ Boolean Also known as: has_predicate?
Returns true
if self
contains the given RDF predicate term.
415 416 417 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 415 def predicate?(value) enum_predicate.include?(value) end |
#predicates(unique: true) ⇒ Array<RDF::URI>
Returns all unique RDF predicate terms.
402 403 404 405 406 407 408 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 402 def predicates(unique: true) unless unique enum_statement.map(&:predicate) # TODO: optimize else enum_predicate.to_a end end |
#project_graph(graph_name) {|statement| ... } #project_graph(graph_name) ⇒ Enumerable
Limits statements to be from a specific graph.
If no block was given, returns an enumerator.
The order in which statements are yielded is undefined.
666 667 668 669 670 671 672 673 674 675 676 677 678 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 666 def project_graph(graph_name) if block_given? self.each do |statement| yield statement if statement.graph_name == graph_name end else # Ensure that statements are queryable, countable and enumerable this = self Queryable::Enumerator.new do |yielder| this.send(:project_graph, graph_name) {|y| yielder << y} end end end |
#quad?(quad) ⇒ Boolean Also known as: has_quad?
Returns true
if self
contains the given RDF quad.
282 283 284 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 282 def quad?(quad) quads.include?(quad) end |
#quads(**options) ⇒ Array<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>
Returns all RDF quads.
273 274 275 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 273 def quads(**) enum_statement.map(&:to_quad) # TODO: optimize end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean (protected)
this instantiates an writer; it could probably be done more
efficiently by refactoring RDF::Reader
and/or RDF::Format
to expose
a list of valid format symbols.
809 810 811 812 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 809 def respond_to_missing?(name, include_private = false) return RDF::Writer.for(name.to_s[3..-1].to_sym) if name.to_s[0,3] == 'to_' super end |
#statement? ⇒ Boolean #statement?(statement) ⇒ Boolean Also known as: has_statement?, include?
151 152 153 154 155 156 157 158 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 151 def statement?(*args) case args.length when 0 then false when 1 args.first && !enum_statement.find { |s| s.eql?(args.first) }.nil? else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)") end end |
#statements(**options) ⇒ Array<RDF::Statement>
Returns all RDF statements.
137 138 139 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 137 def statements(**) enum_statement.to_a end |
#subject?(value) ⇒ Boolean Also known as: has_subject?
Returns true
if self
contains the given RDF subject term.
349 350 351 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 349 def subject?(value) enum_subject.include?(value) end |
#subjects(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF subject terms.
336 337 338 339 340 341 342 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 336 def subjects(unique: true) unless unique enum_statement.map(&:subject) # TODO: optimize else enum_subject.to_a end end |
#supports?(feature) ⇒ Boolean
Returns true
if this enumerable supports the given feature
.
Supported features include:
:graph_name
supports statements with a graph_name, allowing multiple named graphs:inference
supports RDFS inferrence of queryable contents.:literal_equality' preserves [term-equality](https://www.w3.org/TR/rdf11-concepts/#dfn-literal-term-equality) for literals. Literals are equal only if their lexical values and datatypes are equal, character by character. Literals may be "inlined" to value-space for efficiency only if
:literal_equalityis
false`.:validity
allows a concrete Enumerable implementation to indicate that it does or does not support valididty checking. By default implementations are assumed to support validity checking.:skolemize
supports Skolemization of anEnumerable
. Implementations supporting this feature must implement a#skolemize
method, taking a base URI used for minting URIs for BNodes as stable identifiers and a#deskolemize
method, also taking a base URI used for turning URIs having that prefix back into the same BNodes which were originally skolemized.:rdfstar
supports RDF* where statements may be subjects or objects of other statements.
91 92 93 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 91 def supports?(feature) feature == :validity || feature == :literal_equality end |
#term? ⇒ Boolean #term?(value) ⇒ Boolean Also known as: has_term?
561 562 563 564 565 566 567 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 561 def term?(*args) case args.length when 0 then super when 1 then args.first && enum_term.include?(args.first) else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)") end end |
#terms(unique: true) ⇒ Array<RDF::Resource>
Returns all unique RDF terms (subjects, predicates, objects, and graph_names).
539 540 541 542 543 544 545 546 547 548 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 539 def terms(unique: true) unless unique enum_statement. map(&:terms). flatten. compact else enum_term.to_a end end |
#to_a ⇒ Array
Returns all RDF statements in self
as an array.
Mixes in RDF::Enumerable
into the returned object.
730 731 732 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 730 def to_a super.extend(RDF::Enumerable) end |
#to_h ⇒ Hash
Returns all RDF object terms indexed by their subject and predicate terms.
The return value is a Hash
instance that has the structure:
{subject => {predicate => [*objects]}}
.
754 755 756 757 758 759 760 761 762 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 754 def to_h result = {} each_statement do |statement| result[statement.subject] ||= {} values = (result[statement.subject][statement.predicate] ||= []) values << statement.object unless values.include?(statement.object) end result end |
#to_set ⇒ Set
Returns all RDF statements in self
as a set.
Mixes in RDF::Enumerable
into the returned object.
741 742 743 744 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 741 def to_set require 'set' unless defined?(::Set) super.extend(RDF::Enumerable) end |
#triple?(triple) ⇒ Boolean Also known as: has_triple?
Returns true
if self
contains the given RDF triple.
220 221 222 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 220 def triple?(triple) triples.include?(triple) end |
#triples(**options) ⇒ Array<Array(RDF::Resource, RDF::URI, RDF::Term)>
Returns all RDF triples.
211 212 213 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 211 def triples(**) enum_statement.map(&:to_triple) # TODO: optimize end |
#valid? ⇒ Boolean
Returns true
if all statements are valid
101 102 103 104 105 106 107 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 101 def valid? raise NotImplementedError, "#{self.class} does not support validation" unless supports?(:validity) each_statement do |s| return false if s.invalid? end true end |
#validate! ⇒ RDF::Enumerable Also known as: validate
Default validate! implementation, overridden in concrete classes
124 125 126 127 |
# File 'vendor/bundler/ruby/3.1.0/bundler/gems/rdf-ac80b2f2b82e/lib/rdf/mixin/enumerable.rb', line 124 def validate! raise ArgumentError if supports?(:validity) && invalid? self end |