Class: Vangrail::Rails::Language

Inherits:
Vangrail::Rail show all
Defined in:
lib/vangrail/rails/language.rb

Overview

Reports that a page or a question is in a language nothing here can read.

Every other deterministic rail in this gem is a rule about English or Dutch words. Handed a page in German, all of them return passed, and an application reading that result cannot tell "checked and clean" from "the checks do not apply to this text". That is precisely the distinction this gem promises to keep, so the promise has to hold across languages too, and on the question as well as on the retrieved page.

So this rail never blocks. A page in an unsupported language is not an attack, and refusing it would break a site that has one; what it is, is unchecked, and certain? == false is the word for that. An application reporting a safety posture can then route the page to a model rail, to a human, or to nothing, knowing which it is doing.

Below the floor it says nothing at all. A six-word question is not evidence of a language, and marking every short turn uncertain would turn the posture into noise, which is a different way of making it useless.

Constant Summary

Constants inherited from Vangrail::Rail

Vangrail::Rail::DEFAULT_SIDES, Vangrail::Rail::SIDES

Instance Attribute Summary collapse

Attributes inherited from Vangrail::Rail

#name, #sides

Instance Method Summary collapse

Methods inherited from Vangrail::Rail

#applies_to?, #call, #language_agnostic?, #offline?, #placeholder?, #quantifies?, #to_s, usable

Constructor Details

#initialize(supported: NLP::LANGUAGES, floor: NLP::LANGUAGE_FLOOR, name: 'language', sides: %i[input context])) ⇒ Language

Returns a new instance of Language.



27
28
29
30
31
32
# File 'lib/vangrail/rails/language.rb', line 27

def initialize(supported: NLP::LANGUAGES, floor: NLP::LANGUAGE_FLOOR,
               name: 'language', sides: %i[input context])
  super(name: name, sides: sides)
  @supported = Array(supported).map(&:to_sym)
  @floor = floor
end

Instance Attribute Details

#floorObject (readonly)

Returns the value of attribute floor.



34
35
36
# File 'lib/vangrail/rails/language.rb', line 34

def floor
  @floor
end

#supportedObject (readonly)

Returns the value of attribute supported.



34
35
36
# File 'lib/vangrail/rails/language.rb', line 34

def supported
  @supported
end

Instance Method Details

#cache_key(text, _context) ⇒ Object



40
41
42
# File 'lib/vangrail/rails/language.rb', line 40

def cache_key(text, _context)
  "#{supported.join('+')}\n#{text}"
end

#decide(text, _context) ⇒ Object



44
45
46
47
48
49
# File 'lib/vangrail/rails/language.rb', line 44

def decide(text, _context)
  reason = unread_reason(text)
  return unchecked(reason) if reason

  pass
end

#posture?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/vangrail/rails/language.rb', line 36

def posture?
  true
end