twfilter 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ module TWFilter
4
4
  module Checks
5
5
  module Erhua
6
6
  NAME = :erhua
7
- # 兒 is a root morpheme inside a headed or tailed window, and an erhua suffix elsewhere.
8
7
  MARK = "兒"
9
8
 
10
9
  class << self
@@ -12,28 +11,31 @@ module TWFilter
12
11
  offender = offender(subject.text)
13
12
  return [] if offender.nil?
14
13
 
15
- [Finding.new(check: NAME, code: :erhua, detail: offender)]
14
+ [Finding.new(check: NAME, code: :erhua, detail: subject.original(offender))]
16
15
  end
17
16
 
17
+ # A listed form is erhua unless its 兒 opens a word in which 兒 is the root, as in 玩兒藝節.
18
18
  def offender(text)
19
- return nil if text == MARK
19
+ return nil unless text.include?(MARK)
20
20
 
21
- position = 0
22
- while (position = text.index(MARK, position))
23
- after = text[position, 2]
24
- before = position.positive? ? text[position - 1, 2] : nil
25
-
26
- return before || MARK unless headed.include?(after) || tailed.include?(before)
27
-
28
- position += 1
21
+ text.to_enum(:scan, pattern).each do
22
+ match = Regexp.last_match
23
+ root = text[match.end(0) - 1, 2]
24
+ return match[0] unless headed.include?(root)
29
25
  end
30
26
 
31
27
  nil
32
28
  end
33
29
 
30
+ def forms = Tables.rows("erhua.txt")
31
+
34
32
  def headed = Tables.set("erhua_headed.txt")
35
33
 
36
- def tailed = Tables.set("erhua_tailed.txt")
34
+ def reset! = @pattern = nil
35
+
36
+ private
37
+
38
+ def pattern = @pattern ||= Regexp.union(forms.sort_by { |form| -form.length })
37
39
  end
38
40
  end
39
41
  end
@@ -10,22 +10,22 @@ module TWFilter
10
10
  findings = []
11
11
 
12
12
  hard = hits(subject, :hard, hard_terms)
13
- findings << finding(:mainland, hard.first(DETAIL_SAMPLE).join(" "), :reject) if hard.any?
13
+ findings << finding(:mainland, subject.quote(hard, " "), :reject) if hard.any?
14
14
 
15
15
  severity = subject.policy.soft_lexicon_rejects ? :reject : :mark
16
16
  soft = hits(subject, :soft, soft_terms)
17
- findings << finding(:mainland_soft, soft.first(DETAIL_SAMPLE).join(" "), severity) if soft.any?
17
+ findings << finding(:mainland_soft, subject.quote(soft, " "), severity) if soft.any?
18
18
 
19
19
  cantonese = subject.text.scan(union(:cantonese, cantonese_chars)).uniq
20
- findings << finding(:cantonese, cantonese.first(DETAIL_SAMPLE).join, :reject) if cantonese.any?
20
+ findings << finding(:cantonese, subject.quote(cantonese), :reject) if cantonese.any?
21
21
 
22
22
  regional = hits(subject, :regional, regional_terms)
23
- findings << finding(:regional, regional.first(DETAIL_SAMPLE).join(" "), :reject) if regional.any?
23
+ findings << finding(:regional, subject.quote(regional, " "), :reject) if regional.any?
24
24
 
25
25
  topics = subject.text.scan(union(:topics, foreign_topics)).uniq.select { |term| topic?(subject.text, term) }
26
26
  if topics.any?
27
27
  severity = subject.policy.foreign_topics_reject ? :reject : :mark
28
- findings << finding(:foreign_topic, topics.first(DETAIL_SAMPLE).join(" "), severity)
28
+ findings << finding(:foreign_topic, subject.quote(topics, " "), severity)
29
29
  end
30
30
 
31
31
  findings
@@ -55,7 +55,7 @@ module TWFilter
55
55
  def topic?(text, term)
56
56
  return false unless text.include?(term)
57
57
 
58
- text.scan(term).length > text.scan(/#{Regexp.escape(term)}#{ADDRESS}/).length
58
+ text.scan(term).length > text.scan(unions[[:address, term]] ||= /#{Regexp.escape(term)}#{ADDRESS}/).length
59
59
  end
60
60
 
61
61
  # One union scan per table beats 200-odd substring searches; the exception mask then
@@ -15,20 +15,20 @@ module TWFilter
15
15
  findings = []
16
16
 
17
17
  simplified = subject.han_chars.select { |char| simplified_only.include?(char) }.uniq
18
- findings << finding(:simplified, simplified.first(DETAIL_SAMPLE).join) if simplified.any?
18
+ findings << finding(:simplified, subject.quote(simplified)) if simplified.any?
19
19
 
20
20
  converted = subject.han_chars.select { |char| converted_orthography.include?(char) }.uniq
21
21
  if converted.any?
22
22
  severity = subject.policy.orthography_rejects ? :reject : :mark
23
- findings << finding(:converted_orthography, converted.first(DETAIL_SAMPLE).join, severity)
23
+ findings << finding(:converted_orthography, subject.quote(converted), severity)
24
24
  end
25
25
 
26
26
  unlisted = subject.han_chars.reject { |char| tiers.key?(char) }.uniq
27
- findings << finding(:unlisted, unlisted.first(DETAIL_SAMPLE).join) if unlisted.any?
27
+ findings << finding(:unlisted, subject.quote(unlisted)) if unlisted.any?
28
28
 
29
29
  limit = subject.policy.tier_limit
30
30
  above = subject.han_chars.select { |char| (tiers[char] || 0) > limit }.uniq
31
- findings << finding(:above_tier, above.first(DETAIL_SAMPLE).join) if above.any?
31
+ findings << finding(:above_tier, subject.quote(above)) if above.any?
32
32
 
33
33
  findings
34
34
  end
@@ -48,6 +48,7 @@ module TWFilter
48
48
  .reverse
49
49
  .to_h
50
50
  .merge(Tables.rows("moe_exception.txt").to_h { |char| [char, TIERS.fetch(:common)] })
51
+ .merge(Tables.rows("admitted_uncharted.txt").to_h { |char| [char, TIERS.fetch(:common)] })
51
52
  .freeze
52
53
  end
53
54
 
@@ -24,11 +24,11 @@ module TWFilter
24
24
  end
25
25
 
26
26
  offenders = Punctuation.offenders(subject.text, punctuation: subject.policy.punctuation)
27
- findings << finding(:junk_characters, offenders.first(DETAIL_SAMPLE).join) if offenders.any?
27
+ findings << finding(:junk_characters, subject.quote(offenders)) if offenders.any?
28
28
 
29
29
  unless subject.policy.allow_latin
30
30
  latin = subject.text.scan(/[A-Za-z]+/).uniq
31
- findings << finding(:latin, latin.first(DETAIL_SAMPLE).join(" ")) if latin.any?
31
+ findings << finding(:latin, subject.quote(latin, " ")) if latin.any?
32
32
  end
33
33
 
34
34
  findings
@@ -1,6 +1,10 @@
1
1
  {
2
- "version": "0.1.0",
2
+ "version": "0.2.0",
3
3
  "tables": {
4
+ "admitted_uncharted.txt": {
5
+ "rows": 1,
6
+ "sha256": "e470587c3fee4b41766c06e2dbfd77ca6174f4e39795ac5ea305efd2ba7ddcf9"
7
+ },
4
8
  "cantonese.txt": {
5
9
  "rows": 17,
6
10
  "sha256": "3f37b31e98f167cf860ab4068cdf0eaebb7702afccb8b3701dec72cf7223dc2f"
@@ -9,29 +13,29 @@
9
13
  "rows": 14,
10
14
  "sha256": "073f87fffb5922f45a2b1af40deca536dddafc502cc73a87b05846d29b0ecc6d"
11
15
  },
12
- "erhua_headed.txt": {
13
- "rows": 14,
14
- "sha256": "0163fdff14363f3479a072c54a411f37ff3533b7835e3aa6133cc9b56fdf7364"
16
+ "erhua.txt": {
17
+ "rows": 3,
18
+ "sha256": "298b8ce4946a65b5dbc136cc333c79a2d39d6ecd67636f9780ab904694d758b9"
15
19
  },
16
- "erhua_tailed.txt": {
17
- "rows": 36,
18
- "sha256": "ef0bede84353fa8f555a9ca74ba7bad0b9647622f33b9694bd6ad61d51fb8e14"
20
+ "erhua_headed.txt": {
21
+ "rows": 15,
22
+ "sha256": "d2a9f39ddb15e09ef18972befa12347d0c7d92fabaf28c5bbe7f21fbf288aa2d"
19
23
  },
20
24
  "foreign_topics.txt": {
21
25
  "rows": 80,
22
26
  "sha256": "d1685884afd1aafb5c7be07e222fedbd3a4ca1ccf3d96754dae90fdcb32a472f"
23
27
  },
24
28
  "mainland_exceptions.tsv": {
25
- "rows": 6,
26
- "sha256": "647077330116c176dd0aaa983254fbee2129d68da7fe5dffdc5d72c4e5f26bcc"
29
+ "rows": 20,
30
+ "sha256": "a7f1e37d0461ecf33f7c148daa5ae377e0da1915fa238cfdbddfbb3dc3d9fb77"
27
31
  },
28
32
  "mainland_hard.tsv": {
29
- "rows": 149,
30
- "sha256": "11c8c4219b1f5c578b33183eeb93992f932d9ba47ce8ab6d7aea15089468cc69"
33
+ "rows": 144,
34
+ "sha256": "7be27dbf1356161db9957b645f0e45dcc31d75c35e72aeab6e5943ed984452ac"
31
35
  },
32
36
  "mainland_soft.tsv": {
33
- "rows": 38,
34
- "sha256": "1435fc2814454e2675fc4f76528abfa448a18e7e223254bad66ac73b409a2a18"
37
+ "rows": 43,
38
+ "sha256": "63bde1e1c7e901c20979a55c278344b24ff4890a41ba4c717bdc4e0eedbe96d1"
35
39
  },
36
40
  "moe_common.txt": {
37
41
  "rows": 4808,
@@ -0,0 +1 @@
1
+ 〇
@@ -0,0 +1,3 @@
1
+ 事兒
2
+ 玩兒
3
+ 點兒
@@ -11,4 +11,5 @@
11
11
  兒童
12
12
  兒臂
13
13
  兒茶
14
+ 兒藝
14
15
  兒麻
@@ -1,6 +1,20 @@
1
+ 互聯網 互聯網大學
2
+ 交互 社交互 交互計算
1
3
  信息 可信息 通信息
4
+ 內存 內存入 內存放 內存款
5
+ 內核 內核定
6
+ 初中 初中央 初中高
7
+ 博客 博客來
8
+ 字段 數字段
9
+ 實時 事實時
10
+ 帶寬 綠帶寬
2
11
  打車 打車票 卡打車
3
- 水平 水平面 水平線 水平儀 水平位移 水平方向 水平能見度
4
- 視頻 電視頻道 電視頻率 影視頻道
12
+ 文檔 公文檔
13
+ 水平 水平面 水平線 水平儀 水平位移 水平方向 水平能見度 水平原 治水平
14
+ 脫機 解脫機
15
+ 視圖 透視圖
16
+ 視頻 電視頻道 電視頻率 影視頻道 視頻率
17
+ 身份證 身份證明
5
18
  運行 營運行為 運行李
6
- 集成 集成大典
19
+ 鏈接 區塊鏈接
20
+ 集成 集成大典 召集成
@@ -1,23 +1,19 @@
1
1
  信息 資訊 0 2612
2
2
  文檔 文件 0 1649
3
- 初中 國中 0 490
4
3
  公交車 公車 0 435
5
4
  軟件 軟體 0 412
6
5
  芯片 晶片 0 392
7
6
  首席執行官 執行長 0 368
8
- 身份證 身分證 0 348
9
7
  幾率 機率 0 292
10
8
  屏幕 螢幕 0 248
11
9
  硬件 硬體 0 228
12
10
  數據庫 資料庫 0 216
13
- 錄像 錄影 0 199
14
11
  出租車 計程車 0 174
15
12
  演示文稿 簡報 0 163
16
13
  意大利 義大利 0 148
17
14
  短信 簡訊 0 134
18
15
  互聯網 網際網路 0 119
19
16
  互聯網絡 網際網路 0 119
20
- 裏頭 裡頭 0 116
21
17
  信道 通道 0 103
22
18
  納米 奈米 0 94
23
19
  方便麪 泡麵/速食麵 0 88
@@ -30,7 +26,6 @@
30
26
  新西蘭 紐西蘭 0 61
31
27
  模塊 模組 0 59
32
28
  知識產權 智慧財產權 0 59
33
- 複印 影印 0 55
34
29
  激光 雷射 0 54
35
30
  帕勞 帛琉 0 45
36
31
  缺省 預設 0 45
@@ -8,7 +8,9 @@
8
8
  內核 核心 14 528
9
9
  鏈接 連結 3 499
10
10
  實時 即時 12 497
11
+ 初中 國中 0 490
11
12
  查找 查詢 7 470
13
+ 身份證 身分證 0 348
12
14
  水平 水準 64 336
13
15
  指針 指標 12 324
14
16
  視圖 檢視 5 308
@@ -18,14 +20,17 @@
18
20
  人工智能 人工智慧 8 239
19
21
  澳大利亞 澳洲 8 230
20
22
  空調 冷氣 0 229
23
+ 錄像 錄影 0 199
21
24
  激活 啟用 4 195
22
25
  仿真 模擬 4 180
23
26
  拷貝 複製 5 170
24
27
  塑料 塑膠 4 159
25
28
  硅 矽 2 157
26
29
  朝鮮 北韓 26 122
30
+ 裏頭 裡頭 0 116
27
31
  傳感 感測 3 69
28
32
  內置 內建 3 63
33
+ 複印 影印 0 55
29
34
  早上好 早安 2 50
30
35
  普京 普丁 2 49
31
36
  癡呆症 失智症 2 45
@@ -5,6 +5,8 @@ module TWFilter
5
5
  # 沒有 V and 有沒有 V are pan-Mandarin negation and A-not-A, not the Southern Min substrate
6
6
  # perfective. One lookbehind covers both: in 有沒有看 the 有看 match is also preceded by 沒.
7
7
  NEGATED = "沒"
8
+ # 蛤 is also the clam in 文蛤 and 蛤蜊; as a particle it stands apart from any Han neighbour.
9
+ ISOLATED = %w[蛤].freeze
8
10
 
9
11
  class << self
10
12
  def count(text) = scanners.sum { |scanner| text.scan(scanner).length }
@@ -29,11 +31,19 @@ module TWFilter
29
31
  .freeze
30
32
  end
31
33
 
32
- # A plain string scans faster than an equivalent regexp; only 有-initial terms need one.
34
+ # A plain string scans faster than an equivalent regexp; only 有-initial and isolated terms need one.
33
35
  def scanners
34
- @scanners ||= terms.map { |term|
35
- term.start_with?("有") ? /(?<!#{NEGATED})#{Regexp.escape(term)}/ : term
36
- }.freeze
36
+ @scanners ||= terms
37
+ .map { |term|
38
+ if term.start_with?("有")
39
+ /(?<!#{NEGATED})#{Regexp.escape(term)}/
40
+ elsif ISOLATED.include?(term)
41
+ /(?<!\p{Han})#{Regexp.escape(term)}(?!\p{Han})/
42
+ else
43
+ term
44
+ end
45
+ }
46
+ .freeze
37
47
  end
38
48
 
39
49
  private
@@ -1,12 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TWFilter
4
+ # The examined span. Checks run on the NFC form of the caller's text, so a CJK
5
+ # compatibility ideograph is judged as the unified character it stands for. Findings quote
6
+ # the caller's own spelling: each NFC character remembers the grapheme cluster it came from.
4
7
  class Subject
5
- attr_reader :text, :policy
8
+ attr_reader :source, :text, :policy
6
9
 
7
10
  def initialize(text, policy: Policy.corpus)
8
- @text = text.to_s
11
+ @source = text.to_s
9
12
  @policy = policy
13
+ @text, @origins = Subject.normalize(@source)
14
+ end
15
+
16
+ def self.normalize(source)
17
+ return [source, nil] unless source.encoding == Encoding::UTF_8 && source.valid_encoding?
18
+ return [source, nil] if source.unicode_normalized?(:nfc)
19
+
20
+ text = +""
21
+ origins = []
22
+ offset = 0
23
+ source.each_grapheme_cluster do |cluster|
24
+ normalized = cluster.unicode_normalize(:nfc)
25
+ normalized.each_char { origins << (offset...(offset + cluster.length)) }
26
+ text << normalized
27
+ offset += cluster.length
28
+ end
29
+
30
+ return [source.unicode_normalize(:nfc), nil] unless text == source.unicode_normalize(:nfc)
31
+
32
+ [text.freeze, origins.freeze]
10
33
  end
11
34
 
12
35
  def chars = @chars ||= text.chars
@@ -24,5 +47,20 @@ module TWFilter
24
47
  def masked(exceptions)
25
48
  exceptions.reduce(text) { |memo, allowed| memo.gsub(allowed, "") }
26
49
  end
50
+
51
+ def original(fragment)
52
+ return fragment if @origins.nil?
53
+
54
+ start = text.index(fragment)
55
+ return fragment if start.nil? || fragment.empty?
56
+
57
+ first = @origins[start]
58
+ last = @origins[start + fragment.length - 1]
59
+ source[first.begin...last.end]
60
+ end
61
+
62
+ def quote(fragments, separator = "")
63
+ fragments.first(DETAIL_SAMPLE).map { |fragment| original(fragment) }.join(separator)
64
+ end
27
65
  end
28
66
  end
@@ -8,12 +8,14 @@ require "set"
8
8
  module TWFilter
9
9
  # Reference tables. The bundled copy is the source of truth for behavior and is versioned
10
10
  # with the gem; .dir replaces it wholesale and .overlay supplements it. Any deviation from
11
- # the bundled copy changes what "Taiwan Mandarin" means, so both are reported by .provenance.
11
+ # the bundled copy changes what "Taiwanese Mandarin" means, so both are reported by .provenance.
12
12
  module Tables
13
13
  BUNDLED = Pathname(__dir__).join("data").freeze
14
14
  MANIFEST = "MANIFEST.json"
15
15
  ADD = ".add"
16
16
  REMOVE = ".remove"
17
+ EXTENSIONS = %w[.txt .tsv].freeze
18
+ OPERATION = /(?:#{Regexp.escape(ADD)}|#{Regexp.escape(REMOVE)})(?=\.[^.]+\z)/
17
19
 
18
20
  # Row shape per table; unknown names default to :terms so user tables are accepted.
19
21
  SCHEMA = {
@@ -21,6 +23,7 @@ module TWFilter
21
23
  "moe_secondary.txt" => :chars,
22
24
  "moe_rare.txt" => :chars,
23
25
  "moe_exception.txt" => :chars,
26
+ "admitted_uncharted.txt" => :chars,
24
27
  "simplified_only.txt" => :chars,
25
28
  "variants_used_in_taiwan.txt" => :chars,
26
29
  "converted_orthography.txt" => :chars,
@@ -33,10 +36,10 @@ module TWFilter
33
36
  }.freeze
34
37
 
35
38
  class << self
36
- attr_reader :overlay
37
-
38
39
  def dir = @dir ||= Pathname(ENV.fetch("TWFILTER_DATA_DIR", BUNDLED.to_s))
39
40
 
41
+ def overlay = @overlay ||= ENV["TWFILTER_OVERLAY_DIR"]&.then { |path| Pathname(path) }
42
+
40
43
  def dir=(path)
41
44
  @dir = path.nil? ? nil : Pathname(path)
42
45
  TWFilter.reset!
@@ -60,11 +63,9 @@ module TWFilter
60
63
  .freeze
61
64
 
62
65
  def names
63
- base = dir.children.map { |path| path.basename.to_s }
64
- extra = overlay ? overlay.children.map { |path|
65
- path.basename.to_s.sub(/#{Regexp.escape(ADD)}|#{Regexp.escape(REMOVE)}(?=\.)/, "")
66
- } : []
67
- (base + extra).uniq.reject { |name| name == MANIFEST }.sort
66
+ base = files(dir)
67
+ extra = overlay ? files(overlay).map { |name| name.sub(OPERATION, "") } : []
68
+ (base + extra).uniq.sort
68
69
  end
69
70
 
70
71
  def manifest
@@ -87,15 +88,18 @@ module TWFilter
87
88
  }.freeze
88
89
  end
89
90
 
90
- def reset!
91
- @cache = nil
92
- ENV["TWFILTER_OVERLAY_DIR"]&.then { |path| @overlay ||= Pathname(path) }
93
- end
91
+ def reset! = @cache = nil
94
92
 
95
93
  private
96
94
 
97
95
  def cache = @cache ||= {}
98
96
 
97
+ def files(directory)
98
+ directory.children.select { |path| path.file? && EXTENSIONS.include?(path.extname) }.map { |path|
99
+ path.basename.to_s
100
+ }
101
+ end
102
+
99
103
  def resolve(name)
100
104
  base = overlay&.join(name)&.exist? ? read(overlay.join(name), name) : read(dir.join(name), name)
101
105
  return base.freeze if overlay.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TWFilter
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/twfilter.rb CHANGED
@@ -28,7 +28,7 @@ module TWFilter
28
28
  findings = checks.flat_map { |check| check.call(subject) }
29
29
 
30
30
  Report.new(
31
- text: subject.text,
31
+ text: subject.source,
32
32
  findings: findings.freeze,
33
33
  tier: Checks::Script.tier_of(subject.text),
34
34
  han: subject.han,
@@ -42,7 +42,7 @@ module TWFilter
42
42
 
43
43
  def sentences(text, **options) = Sentences.split(text, **options)
44
44
 
45
- def tier(text) = Checks::Script.tier_of(text)
45
+ def tier(text) = Checks::Script.tier_of(Subject.normalize(text.to_s).first)
46
46
 
47
47
  def provenance = Tables.provenance
48
48
 
@@ -51,6 +51,7 @@ module TWFilter
51
51
  Evidence.reset!
52
52
  Checks::Script.reset!
53
53
  Checks::Lexicon.reset!
54
+ Checks::Erhua.reset!
54
55
  self
55
56
  end
56
57
  end
data/sig/twfilter.rbs CHANGED
@@ -27,6 +27,7 @@ module TWFilter
27
27
  def self.sentences: (untyped, ?clause: bool) -> ::Array[::String]
28
28
  def self.tier: (::String) -> ::Integer?
29
29
  def self.provenance: () -> ::Hash[::Symbol, untyped]
30
+ def self.reset!: () -> singleton(TWFilter)
30
31
 
31
32
  class Finding
32
33
  attr_reader check: ::Symbol
@@ -78,10 +79,12 @@ module TWFilter
78
79
  end
79
80
 
80
81
  class Subject
82
+ attr_reader source: ::String
81
83
  attr_reader text: ::String
82
84
  attr_reader policy: Policy
83
85
 
84
86
  def initialize: (untyped, ?policy: Policy) -> void
87
+ def self.normalize: (::String) -> [::String, ::Array[::Range[::Integer]]?]
85
88
  def chars: () -> ::Array[::String]
86
89
  def han_chars: () -> ::Array[::String]
87
90
  def han: () -> ::Integer
@@ -89,11 +92,15 @@ module TWFilter
89
92
  def empty?: () -> bool
90
93
  def include?: (::String) -> bool
91
94
  def masked: (::Array[::String]) -> ::String
95
+ def original: (::String) -> ::String
96
+ def quote: (::Array[::String], ?::String) -> ::String
92
97
  end
93
98
 
94
99
  module Han
95
100
  CHAR: ::Regexp
96
101
  RUN: ::Regexp
102
+ BMP: ::Range[::Integer]
103
+ EXTENSION_A: ::Range[::Integer]
97
104
 
98
105
  def self.char?: (::String) -> bool
99
106
  def self.count: (::String) -> ::Integer
@@ -127,6 +134,7 @@ module TWFilter
127
134
 
128
135
  module Evidence
129
136
  NEGATED: ::String
137
+ ISOLATED: ::Array[::String]
130
138
 
131
139
  def self.count: (::String) -> ::Integer
132
140
  def self.per_100: (::String) -> ::Float
@@ -149,6 +157,8 @@ module TWFilter
149
157
  MANIFEST: ::String
150
158
  ADD: ::String
151
159
  REMOVE: ::String
160
+ EXTENSIONS: ::Array[::String]
161
+ OPERATION: ::Regexp
152
162
  SCHEMA: ::Hash[::String, ::Symbol]
153
163
 
154
164
  def self.dir: () -> ::Pathname
@@ -180,6 +190,7 @@ module TWFilter
180
190
  def self.tiers: () -> ::Hash[::String, ::Integer]
181
191
  def self.simplified_only: () -> ::Set[::String]
182
192
  def self.converted_orthography: () -> ::Set[::String]
193
+ def self.reset!: () -> void
183
194
  end
184
195
 
185
196
  module Lexicon
@@ -194,6 +205,8 @@ module TWFilter
194
205
  def self.cantonese_chars: () -> ::Array[::String]
195
206
  def self.foreign_topics: () -> ::Array[::String]
196
207
  def self.topic?: (::String, ::String) -> bool
208
+ def self.union: (::Symbol, ::Array[::String]) -> ::Regexp
209
+ def self.reset!: () -> void
197
210
  end
198
211
 
199
212
  module Erhua
@@ -201,8 +214,9 @@ module TWFilter
201
214
  MARK: ::String
202
215
  def self.call: (Subject) -> ::Array[Finding]
203
216
  def self.offender: (::String) -> ::String?
217
+ def self.forms: () -> ::Array[::String]
204
218
  def self.headed: () -> ::Set[::String]
205
- def self.tailed: () -> ::Set[::String]
219
+ def self.reset!: () -> void
206
220
  end
207
221
 
208
222
  module Wenyan
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Den Patin
7
+ - Den Patin 丁丹旭
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -53,11 +53,12 @@ dependencies:
53
53
  version: '3.13'
54
54
  description: 'Provenance analysis of Chinese text in pure Ruby: MOE character-chart
55
55
  tiering, OpenCC-derived simplified round-trip detection, mainland traditional orthography,
56
- corpus-verified lexical origin markers graded by attestation ratio, Cantonese particles,
57
- erhua windowing, literary Chinese density, and positive Taiwan evidence over lexicon,
56
+ lexical origin markers with collision masks, written-Cantonese characters, an erhua
57
+ form list, literary Chinese density, and positive Taiwan evidence over lexicon,
58
58
  particles, institutions and the 有 + V perfective. Punctuation normalization to 教育部《重訂標點符號手冊》
59
59
  and sentence segmentation over terminator-closer classes. Every rejection is reported
60
- as a typed finding. No dependencies, no native extensions, deterministic output.'
60
+ as a typed finding. No runtime dependencies, no native extensions, deterministic
61
+ output.'
61
62
  email: hi@dpat.in
62
63
  executables: []
63
64
  extensions: []
@@ -75,10 +76,11 @@ files:
75
76
  - lib/twfilter/checks/shape.rb
76
77
  - lib/twfilter/checks/wenyan.rb
77
78
  - lib/twfilter/data/MANIFEST.json
79
+ - lib/twfilter/data/admitted_uncharted.txt
78
80
  - lib/twfilter/data/cantonese.txt
79
81
  - lib/twfilter/data/converted_orthography.txt
82
+ - lib/twfilter/data/erhua.txt
80
83
  - lib/twfilter/data/erhua_headed.txt
81
- - lib/twfilter/data/erhua_tailed.txt
82
84
  - lib/twfilter/data/foreign_topics.txt
83
85
  - lib/twfilter/data/mainland_exceptions.tsv
84
86
  - lib/twfilter/data/mainland_hard.tsv
@@ -110,6 +112,8 @@ files:
110
112
  homepage: https://github.com/taiwan-corpora/twfilter
111
113
  licenses:
112
114
  - MIT
115
+ - Apache-2.0
116
+ - OGDL-Taiwan-1.0
113
117
  metadata:
114
118
  source_code_uri: https://github.com/taiwan-corpora/twfilter
115
119
  changelog_uri: https://github.com/taiwan-corpora/twfilter/blob/main/CHANGELOG.md
@@ -123,15 +127,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
127
  requirements:
124
128
  - - ">="
125
129
  - !ruby/object:Gem::Version
126
- version: '3.2'
130
+ version: '3.4'
127
131
  required_rubygems_version: !ruby/object:Gem::Requirement
128
132
  requirements:
129
133
  - - ">="
130
134
  - !ruby/object:Gem::Version
131
135
  version: '0'
132
136
  requirements: []
133
- rubygems_version: 4.0.16
137
+ rubygems_version: 4.0.20
134
138
  specification_version: 4
135
- summary: 'Taiwan Mandarin text filter: script inventory, orthography, lexical origin,
139
+ summary: 'Taiwanese Mandarin text filter: script inventory, orthography, lexical origin,
136
140
  punctuation'
137
141
  test_files: []