Class: RDF::Query::HashPatternNormalizer
- Inherits:
-
Object
- Object
- RDF::Query::HashPatternNormalizer
- Defined in:
- lib/rdf/query/hash_pattern_normalizer.rb
Overview
An RDF query pattern normalizer.
Defined Under Namespace
Classes: Counter
Instance Attribute Summary collapse
-
#options ⇒ Hash{Symbol => Object}
readonly
The options for this hash pattern normalizer.
Class Method Summary collapse
-
.normalize!(hash_pattern, **options) ⇒ Hash{Symbol => Object}
Returns the normalization of the specified
hash_pattern
.
Instance Method Summary collapse
-
#initialize(**options) ⇒ HashPatternNormalizer
constructor
A new instance of HashPatternNormalizer.
-
#normalize!(hash_pattern) ⇒ Hash{Symbol => Object}
Equivalent to calling
self.class.normalize!(hash_pattern, self.options)
.
Constructor Details
#initialize(**options) ⇒ HashPatternNormalizer
Returns a new instance of HashPatternNormalizer.
178 179 180 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 178 def initialize(**) @options = .dup end |
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
The options for this hash pattern normalizer.
171 172 173 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 171 def @options end |
Class Method Details
.normalize!(hash_pattern, **options) ⇒ Hash{Symbol => Object}
Returns the normalization of the specified hash_pattern
.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 89 def normalize!(*args) hash_pattern = args.shift = args.shift || {} anonymous_subject_format = .fetch(:anonymous_subject_format, '__%s__') raise ArgumentError, "invalid hash pattern: #{hash_pattern.inspect}" unless hash_pattern.is_a?(Hash) counter = RDF::Query::HashPatternNormalizer::Counter.new hash_pattern.inject({}) { |acc, pair| subject, predicate_to_object = pair ensure_absence_of_duplicate_subjects!(acc, subject) normalized_predicate_to_object = normalize_hash!(predicate_to_object, acc, counter, anonymous_subject_format) ensure_absence_of_duplicate_subjects!(acc, subject) acc[subject] = normalized_predicate_to_object acc } end |
Instance Method Details
#normalize!(hash_pattern) ⇒ Hash{Symbol => Object}
Equivalent to calling self.class.normalize!(hash_pattern, self.options)
.
189 190 191 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 189 def normalize!(hash_pattern) self.class.normalize!(hash_pattern, @options) end |