Module: SpellKit

Defined in:
lib/spellkit_stub.rb

Overview

SpellKit stub for integration example This will be replaced by the actual spellkit gem (version 0.1.1+)

Defined Under Namespace

Classes: Error

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.statsObject (readonly)

Returns the value of attribute stats.



8
9
10
# File 'lib/spellkit_stub.rb', line 8

def stats
  @stats
end

Class Method Details

.correct(term) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spellkit_stub.rb', line 53

def correct(term)
  return term unless @loaded

  # Protected terms never get corrected
  return term if @protected_terms.include?(term)

  # Stub corrections
  corrections = {
    "sequnce" => "sequence",
    "helllo" => "hello",
    "lyssis" => "lysis",
    "protien" => "protein"
  }

  corrections[term.downcase] || term
end

.correct?(term) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
# File 'lib/spellkit_stub.rb', line 42

def correct?(term)
  return false unless @loaded

  # Protected terms are always correct
  return true if @protected_terms.include?(term)

  # Stub: check if term is in "dictionary"
  known_terms = %w[hello world sequence gene the with to need i lysis protein oligo rat buffer western blot]
  known_terms.include?(term.downcase) || @protected_terms.include?(term)
end

.correct_tokens(tokens) ⇒ Object



70
71
72
73
# File 'lib/spellkit_stub.rb', line 70

def correct_tokens(tokens)
  return tokens unless @loaded
  tokens.map { |t| correct(t) }
end

.healthcheckObject

Raises:



75
76
77
78
# File 'lib/spellkit_stub.rb', line 75

def healthcheck
  raise Error, "SpellKit not loaded. Call SpellKit.load! first" unless @loaded
  true
end

.load!(dictionary:, edit_distance: 1, frequency_threshold: 0, protected_terms: nil, skip_patterns: {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/spellkit_stub.rb', line 10

def load!(dictionary:, edit_distance: 1, frequency_threshold: 0, protected_terms: nil, skip_patterns: {})
  @loaded = true
  @edit_distance = edit_distance
  @protected_terms = Set.new(protected_terms || %w[CDK10 IL6 IL-6 BRCA1 BRCA2 TP53 EGFR])
  @stats = {
    version: "spellkit-stub-0.1.1",
    loaded_at: Time.now,
    tokens_corrected: 0,
    p50_us: 20,
    p95_us: 60
  }
  puts "SpellKit loaded (stub implementation)"
end

.suggestions(term, max = 5) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/spellkit_stub.rb', line 24

def suggestions(term, max = 5)
  return [] unless @loaded

  # Stub suggestions
  case term.downcase
  when "sequnce"
    [{"term" => "sequence", "distance" => 1, "freq" => 50000}]
  when "helllo"
    [{"term" => "hello", "distance" => 1, "freq" => 100000}]
  when "lyssis"
    [{"term" => "lysis", "distance" => 1, "freq" => 12345}]
  when "protien"
    [{"term" => "protein", "distance" => 1, "freq" => 54321}]
  else
    []
  end
end