Module: TWFilter

Defined in:
lib/twfilter.rb,
lib/twfilter/han.rb,
lib/twfilter/block.rb,
lib/twfilter/errors.rb,
lib/twfilter/policy.rb,
lib/twfilter/tables.rb,
lib/twfilter/finding.rb,
lib/twfilter/subject.rb,
lib/twfilter/version.rb,
lib/twfilter/evidence.rb,
lib/twfilter/sentences.rb,
lib/twfilter/punctuation.rb,
lib/twfilter/checks/erhua.rb,
lib/twfilter/checks/shape.rb,
lib/twfilter/checks/script.rb,
lib/twfilter/checks/wenyan.rb,
lib/twfilter/checks/lexicon.rb,
sig/twfilter.rbs

Defined Under Namespace

Modules: Block, Checks, Evidence, Han, Punctuation, Sentences, Tables, _Check Classes: Error, Finding, InvalidTableError, MissingTableError, Policy, Report, Subject

Constant Summary collapse

CHECKS =

Returns:

[Checks::Shape, Checks::Script, Checks::Lexicon, Checks::Erhua, Checks::Wenyan].freeze
TIERS =

教育部 chart indices, ordered by decreasing frequency of use.

Returns:

  • (::Hash[::Symbol, ::Integer])
{common: 0, secondary: 1, rare: 2}.freeze
DETAIL_SAMPLE =

Offending items quoted in a finding detail. The check fires on all of them; this only bounds log width.

Returns:

  • (::Integer)
4
VERSION =

Returns:

  • (String)
"1.0.0"

Class Method Summary collapse

Class Method Details

.examine(text, policy: Policy.corpus, checks: CHECKS) ⇒ Report

Parameters:

  • (Object)
  • policy: (Policy) (defaults to: Policy.corpus)
  • checks: (::Array[_Check]) (defaults to: CHECKS)

Returns:



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/twfilter.rb', line 26

def examine(text, policy: Policy.corpus, checks: CHECKS)
  subject = Subject.new(text, policy: policy)
  findings = checks.flat_map { |check| check.call(subject) }

  Report.new(
    text: subject.text,
    findings: findings.freeze,
    tier: Checks::Script.tier_of(subject.text),
    han: subject.han,
    evidence: Evidence.count(subject.text)
  )
end

.keep?(text, policy: Policy.corpus) ⇒ Boolean

Parameters:

  • (Object)
  • policy: (Policy) (defaults to: Policy.corpus)

Returns:

  • (Boolean)


39
# File 'lib/twfilter.rb', line 39

def keep?(text, policy: Policy.corpus) = examine(text, policy: policy).ok?

.normalize(text, **options) ⇒ ::String

Parameters:

  • (Object)
  • collapse_repeats: (Boolean)

Returns:

  • (::String)


41
# File 'lib/twfilter.rb', line 41

def normalize(text, **options) = Punctuation.normalize(text, **options)

.provenance::Hash[::Symbol, untyped]

Returns:

  • (::Hash[::Symbol, untyped])


47
# File 'lib/twfilter.rb', line 47

def provenance = Tables.provenance

.reset!Object



49
50
51
52
53
54
55
# File 'lib/twfilter.rb', line 49

def reset!
  Tables.reset!
  Evidence.reset!
  Checks::Script.reset!
  Checks::Lexicon.reset!
  self
end

.sentences(text, **options) ⇒ ::Array[::String]

Parameters:

  • (Object)
  • clause: (Boolean)

Returns:

  • (::Array[::String])


43
# File 'lib/twfilter.rb', line 43

def sentences(text, **options) = Sentences.split(text, **options)

.tier(text) ⇒ ::Integer?

Parameters:

  • (::String)

Returns:

  • (::Integer, nil)


45
# File 'lib/twfilter.rb', line 45

def tier(text) = Checks::Script.tier_of(text)