Module: TWFilter::Sentences
- Defined in:
- lib/twfilter/sentences.rb,
sig/twfilter.rbs
Constant Summary collapse
- TERMINATORS =
A boundary is a run of terminators followed by any closing brackets; 、 is not a boundary.
"。!?…‼⁉"- CLAUSE =
";"- CLOSERS =
"」』)〕】》〉\u{201D}\u{2019}"- PIECES =
{ true => /[^#{TERMINATORS}#{CLAUSE}]*[#{TERMINATORS}#{CLAUSE}]+[#{CLOSERS}]*|[^#{TERMINATORS}#{CLAUSE}]+/, false => /[^#{TERMINATORS}]*[#{TERMINATORS}]+[#{CLOSERS}]*|[^#{TERMINATORS}]+/ }.freeze
Class Method Summary collapse
- .shaped?(text, policy: Policy.corpus) ⇒ Boolean
- .split(text, clause: true) ⇒ ::Array[::String]
- .terminal?(text) ⇒ Boolean
Class Method Details
.shaped?(text, policy: Policy.corpus) ⇒ Boolean
27 28 29 30 |
# File 'lib/twfilter/sentences.rb', line 27 def shaped?(text, policy: Policy.corpus) han = Han.count(text) policy.han_range.cover?(han) && Han.ratio(text) >= policy.min_han_ratio end |
.split(text, clause: true) ⇒ ::Array[::String]
17 18 19 20 21 22 23 |
# File 'lib/twfilter/sentences.rb', line 17 def split(text, clause: true) text .to_s .scan(PIECES.fetch(clause)) .map { |piece| piece.gsub(/\s+/, " ").strip } .reject(&:empty?) end |
.terminal?(text) ⇒ Boolean
25 |
# File 'lib/twfilter/sentences.rb', line 25 def terminal?(text) = TERMINATORS.chars.any? { |mark| text.end_with?(mark) } |