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.
176 177 178 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 176 def initialize( = {}) = .dup end |
Instance Attribute Details
#options ⇒ Hash{Symbol => Object} (readonly)
The options for this hash pattern normalizer.
169 170 171 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 169 def end |
Class Method Details
.normalize!(hash_pattern = {}, options = {}) ⇒ Hash{Symbol => Object}
Returns the normalization of the specified ‘hash_pattern`.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 88 def normalize!(hash_pattern = {}, = {}) raise ArgumentError, "invalid hash pattern: #{hash_pattern.inspect}" unless hash_pattern.is_a?(Hash) counter = RDF::Query::HashPatternNormalizer::Counter.new anonymous_subject_format = ([:anonymous_subject_format] || '__%s__').to_s 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)`.
187 188 189 |
# File 'lib/rdf/query/hash_pattern_normalizer.rb', line 187 def normalize!(hash_pattern = {}) self.class.normalize!(hash_pattern, ) end |