Class: Iriq::NullEvidenceSource

Inherits:
Object
  • Object
show all
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

Instance Method Details

#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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/iriq/normalizer.rb', line 71

def render_query(iri, classifier)
  iri.query_params.keys.sort.map do |k|
    v    = iri.query_params[k]
    type = classifier.classify(v.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(k, type))
      type = hint
    end
    shaped =
      if type == :date && (canon = SegmentClassifier.canonical_date(v.to_s))
        canon
      elsif type == :currency && (canon = SegmentClassifier.canonical_currency(v.to_s))
        canon
      elsif classifier.variable?(type)
        "{#{SegmentClassifier.display_type(type)}}"
      else
        v
      end
    "#{k}=#{shaped}"
  end.join("&")
end