Class: Iriq::SynthesizedRecognizer
- Inherits:
-
Recognizer
- Object
- Recognizer
- Iriq::SynthesizedRecognizer
- Defined in:
- lib/iriq/synthesized_recognizer.rb
Overview
Recognizer built dynamically from a learned-prefix pattern.
Used by Corpus#activate_proposal to promote a RecognizerProposal into a live Recognizer that the classifier ensemble consults. Same shape as the built-in Recognizers — uuid, date, integer — but the pattern + type are supplied at construction instead of compiled-in.
r = SynthesizedRecognizer.new(prefix: "ghp_", type: :ghp)
r.try("ghp_abcdef123") # → {type: :ghp, confidence: 1.0, specificity: 1.0}
Pattern: ‘<prefix><+>` — anchored, alphanumeric suffix only. Matches the same shape PrefixUnderscoreId proposes from, so round-trip (propose → activate → reinfer) reclassifies the same values the proposal was derived from.
Specificity defaults to SEMANTIC. A learned prefix is very specific by construction (a distinctive literal prefix that recurred enough to clear the proposal noise floor) — calling it as confident as a built-in UUID is reasonable.
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#specificity ⇒ Object
readonly
Returns the value of attribute specificity.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(prefix:, type:, specificity: Specificity::SEMANTIC) ⇒ SynthesizedRecognizer
constructor
A new instance of SynthesizedRecognizer.
- #to_dump ⇒ Object
- #try(segment) ⇒ Object
Methods inherited from Recognizer
Constructor Details
#initialize(prefix:, type:, specificity: Specificity::SEMANTIC) ⇒ SynthesizedRecognizer
Returns a new instance of SynthesizedRecognizer.
28 29 30 31 32 33 34 35 36 |
# File 'lib/iriq/synthesized_recognizer.rb', line 28 def initialize(prefix:, type:, specificity: Specificity::SEMANTIC) raise ArgumentError, "prefix must be a non-empty string" if prefix.nil? || prefix.empty? raise ArgumentError, "type must be a symbol" unless type.is_a?(Symbol) @prefix = prefix @type = type @specificity = specificity @pattern = /\A#{Regexp.escape(prefix)}[A-Za-z0-9]+\z/.freeze end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
22 23 24 |
# File 'lib/iriq/synthesized_recognizer.rb', line 22 def prefix @prefix end |
#specificity ⇒ Object (readonly)
Returns the value of attribute specificity.
22 23 24 |
# File 'lib/iriq/synthesized_recognizer.rb', line 22 def specificity @specificity end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/iriq/synthesized_recognizer.rb', line 22 def type @type end |
Class Method Details
.from_dump(h) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/iriq/synthesized_recognizer.rb', line 48 def self.from_dump(h) new( prefix: h["prefix"], type: h["type"].to_sym, specificity: h.fetch("specificity", Specificity::SEMANTIC), ) end |
.from_proposal(proposal) ⇒ Object
24 25 26 |
# File 'lib/iriq/synthesized_recognizer.rb', line 24 def self.from_proposal(proposal) new(prefix: proposal.prefix, type: proposal.suggested_type) end |
Instance Method Details
#to_dump ⇒ Object
44 45 46 |
# File 'lib/iriq/synthesized_recognizer.rb', line 44 def to_dump { "prefix" => @prefix, "type" => @type.to_s, "specificity" => @specificity } end |
#try(segment) ⇒ Object
38 39 40 41 42 |
# File 'lib/iriq/synthesized_recognizer.rb', line 38 def try(segment) return nil unless segment.start_with?(@prefix) && @pattern.match?(segment) { type: @type, confidence: 1.0, specificity: @specificity } end |