Class: Iriq::NullEvidenceSource
- Inherits:
-
Object
- Object
- Iriq::NullEvidenceSource
- Defined in:
- lib/iriq/normalizer.rb
Overview
NullEvidenceSource is the default evidence source — purely classifier-driven, no corpus signal. The Normalizer's mechanical behavior is what this produces. Implements the same render_query interface that Corpus implements for the corpus-informed path.
Instance Method Summary collapse
-
#render_param(name, value, classifier) ⇒ Object
One param's mechanical rendering.
- #render_path(iri, classifier, hints) ⇒ Object
- #render_query(iri, classifier) ⇒ Object
Instance Method Details
#render_param(name, value, classifier) ⇒ Object
One param's mechanical rendering. Corpus#render_query delegates here for params it lacks evidence on, so the two paths can't drift.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/iriq/normalizer.rb', line 79 def render_param(name, value, classifier) type = classifier.classify(value.to_s) # Param-name hint can lift a generic literal/opaque_id/slug into # a semantic type — `?phone=unknown` becomes `{phone}`. if (hint = SegmentClassifier.param_name_hint(name, type)) type = hint end if type == :date && (canon = SegmentClassifier.canonical_date(value.to_s)) canon elsif type == :currency && (canon = SegmentClassifier.canonical_currency(value.to_s)) canon elsif classifier.variable?(type) "{#{SegmentClassifier.display_type(type)}}" else value end end |
#render_path(iri, classifier, hints) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/iriq/normalizer.rb', line 64 def render_path(iri, classifier, hints) PathShape.new( classifier: classifier, hints: hints, canonical_dates: true, canonical_currencies: true, ).for(iri.path_segments) end |
#render_query(iri, classifier) ⇒ Object
71 72 73 74 75 |
# File 'lib/iriq/normalizer.rb', line 71 def render_query(iri, classifier) iri.query_params.keys.sort.map do |k| "#{k}=#{render_param(k, iri.query_params[k], classifier)}" end.join("&") end |