cbeta 4.0.0 → 4.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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/cbeta/gaiji.rb +25 -10
- data/lib/cbeta/p5a_checker.rb +32 -0
- data/lib/cbeta/unicode_service.rb +19 -9
- data.tar.gz.sig +0 -0
- metadata +1 -21
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e86b3e6256a56e239bd95259c3e040ce05563740aa7a53ae387bbdace4bae2e1
|
|
4
|
+
data.tar.gz: d72162f4ea8d9c0650d748b3593c3ddabe259dd295438d7aed7a474b93bfe5bf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e75dbd36ac5ececb236bac18deff9692055188456cc42afe69a99218948013943229e5f3679272491c9ff6baaac0f06654a2f1ff9965df0bb2dbff3b9d048d45
|
|
7
|
+
data.tar.gz: 644492039267b108f6d35fdf97fb937bbff1ce592d2090169171a89d94aa235e59068eb1dc92fb6ca3c10fd1afa4c0c6a8e48c87c29fff9b49fe05431ecdf4e1
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/lib/cbeta/gaiji.rb
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
-
require 'unihan2'
|
|
3
2
|
|
|
4
3
|
# 存取 CBETA 缺字資料庫
|
|
5
4
|
class CBETA::Gaiji
|
|
6
|
-
|
|
5
|
+
# 內建缺字資料所在的資料夾
|
|
6
|
+
DATA_FOLDER = File.expand_path('../data', __dir__)
|
|
7
|
+
|
|
7
8
|
# 載入 CBETA 缺字資料庫
|
|
8
|
-
|
|
9
|
+
#
|
|
10
|
+
# 預設使用 gem 內建的缺字資料。也可以傳入外部檔案路徑,自行決定要使用哪一份資料,
|
|
11
|
+
# 例如 https://github.com/cbeta-org/cbeta_gaiji 某個版本的 cbeta_gaiji.json,
|
|
12
|
+
# 讓缺字資料版本與 gem 版本脫鉤。外部檔案必須與 cbeta_gaiji repo 的 JSON 格式相同。
|
|
13
|
+
#
|
|
14
|
+
# @param gaiji_path [String, nil] CB 缺字資料(cbeta_gaiji.json)路徑,nil 表示使用內建資料
|
|
15
|
+
# @param sanskrit_path [String, nil] 悉曇、蘭札資料(cbeta_sanskrit.json)路徑,nil 表示使用內建資料
|
|
16
|
+
#
|
|
17
|
+
# @example 使用內建資料
|
|
18
|
+
# g = CBETA::Gaiji.new
|
|
19
|
+
#
|
|
20
|
+
# @example 使用外部資料
|
|
21
|
+
# g = CBETA::Gaiji.new(
|
|
22
|
+
# gaiji_path: '/path/to/cbeta_gaiji/cbeta_gaiji.json',
|
|
23
|
+
# sanskrit_path: '/path/to/cbeta_gaiji/cbeta_sanskrit.json'
|
|
24
|
+
# )
|
|
25
|
+
def initialize(gaiji_path: nil, sanskrit_path: nil)
|
|
9
26
|
@us = CBETA::UnicodeService.new
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
h = JSON.parse(File.read(fn))
|
|
16
|
-
@gaijis.merge!(h)
|
|
27
|
+
gaiji_path ||= File.join(DATA_FOLDER, 'cbeta_gaiji.json')
|
|
28
|
+
sanskrit_path ||= File.join(DATA_FOLDER, 'cbeta_sanskrit.json')
|
|
29
|
+
|
|
30
|
+
@gaijis = JSON.parse(File.read(gaiji_path))
|
|
31
|
+
@gaijis.merge!(JSON.parse(File.read(sanskrit_path)))
|
|
17
32
|
|
|
18
33
|
@zzs = {}
|
|
19
34
|
@uni2cb = {}
|
data/lib/cbeta/p5a_checker.rb
CHANGED
|
@@ -21,6 +21,7 @@ require_relative 'cbeta_share'
|
|
|
21
21
|
# * [E14] <anchor type="right"> 不應直接出現在 div 或 body 下
|
|
22
22
|
# * [E15] <note> corresp 無對應的 <note>
|
|
23
23
|
# * [E16] app/@n 與 note/@n 不一致
|
|
24
|
+
# * [E17] list 下沒有任何有內容的 item
|
|
24
25
|
#
|
|
25
26
|
# * 警告類型
|
|
26
27
|
# * [W01] 夾注包夾注
|
|
@@ -29,6 +30,9 @@ require_relative 'cbeta_share'
|
|
|
29
30
|
class CBETA::P5aChecker
|
|
30
31
|
ALLOW_TAB = %w[change]
|
|
31
32
|
|
|
33
|
+
# 判斷 item 是否有內容時,不計入的元素(本身不產生內容,只是標記位置)
|
|
34
|
+
EMPTY_ELEMENTS = %w[lb pb milestone anchor mulu space]
|
|
35
|
+
|
|
32
36
|
# @param xml_root [String] 來源 CBETA XML P5a 路徑
|
|
33
37
|
# @param figures [String] 插圖 路徑 (可由 https://github.com/cbeta-git/CBR2X-figures 取得)
|
|
34
38
|
# @param log [String] Log file path
|
|
@@ -119,6 +123,12 @@ class CBETA::P5aChecker
|
|
|
119
123
|
end
|
|
120
124
|
end
|
|
121
125
|
|
|
126
|
+
# 節點是否有內容(文字,或 EMPTY_ELEMENTS 以外的元素)
|
|
127
|
+
def content?(e)
|
|
128
|
+
return true unless e.text.strip.empty?
|
|
129
|
+
e.xpath('.//*').any? { |d| not EMPTY_ELEMENTS.include?(d.name) }
|
|
130
|
+
end
|
|
131
|
+
|
|
122
132
|
def display_errors
|
|
123
133
|
@g_errors.keys.sort.each do |k|
|
|
124
134
|
s = @g_errors[k].to_a.join(',')
|
|
@@ -230,6 +240,20 @@ class CBETA::P5aChecker
|
|
|
230
240
|
traverse(e)
|
|
231
241
|
end
|
|
232
242
|
|
|
243
|
+
# list 下應該至少有一個 item 是有內容的
|
|
244
|
+
def e_list(e)
|
|
245
|
+
# item 可能包在 app/lem 之類的元素裡,所以用 descendant 找,
|
|
246
|
+
# 但要排除 巢狀 list 底下的 item
|
|
247
|
+
items = e.xpath('.//item').select { |item| nearest_list(item).equal?(e) }
|
|
248
|
+
unless items.any? { |item| content?(item) }
|
|
249
|
+
msg = "[E17] list 下沒有任何有內容的 item"
|
|
250
|
+
head = e.at_xpath('head')
|
|
251
|
+
msg += ", head: #{head.text.gsub(/\s+/, ' ').strip[0, 30]}" unless head.nil?
|
|
252
|
+
error msg
|
|
253
|
+
end
|
|
254
|
+
traverse(e)
|
|
255
|
+
end
|
|
256
|
+
|
|
233
257
|
def e_note(e)
|
|
234
258
|
error "[E11] note 直接出現在 div 下" if e.parent.name == 'div'
|
|
235
259
|
error "[E12] note 直接出現在 lg 下" if e.parent.name == 'lg'
|
|
@@ -342,6 +366,7 @@ class CBETA::P5aChecker
|
|
|
342
366
|
when 'item' then e_item(e)
|
|
343
367
|
when 'lb' then e_lb(e)
|
|
344
368
|
when 'lem' then e_lem(e)
|
|
369
|
+
when 'list' then e_list(e)
|
|
345
370
|
when 'note' then e_note(e)
|
|
346
371
|
when 'p' then e_p(e)
|
|
347
372
|
when 'rdg' then e_rdg(e)
|
|
@@ -360,6 +385,13 @@ class CBETA::P5aChecker
|
|
|
360
385
|
end
|
|
361
386
|
end
|
|
362
387
|
|
|
388
|
+
# 往上找最近的 list 祖先
|
|
389
|
+
def nearest_list(e)
|
|
390
|
+
r = e.parent
|
|
391
|
+
r = r.parent while r.element? and r.name != 'list'
|
|
392
|
+
r
|
|
393
|
+
end
|
|
394
|
+
|
|
363
395
|
def read_notes(doc)
|
|
364
396
|
@notes = Set.new
|
|
365
397
|
doc.xpath('//note').each do |e|
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
+
# 判斷字元收錄於哪一版 Unicode
|
|
2
|
+
#
|
|
3
|
+
# 使用 Ruby 內建 regexp 的 Unicode Age 屬性(\p{Age=...})判斷。
|
|
4
|
+
# Age 屬性一經指定就不會變動,所以結果不受 Ruby 版本影響。
|
|
1
5
|
class CBETA::UnicodeService
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
# Unicode 3.0 以內
|
|
7
|
+
LEVEL1 = /\A\p{Age=3.0}+\z/
|
|
8
|
+
|
|
9
|
+
# Unicode 10.0 以內
|
|
10
|
+
LEVEL2 = /\A\p{Age=10.0}+\z/
|
|
5
11
|
|
|
12
|
+
# Unicode 3.0 以內 在 mobile 可以正確顯示
|
|
13
|
+
#
|
|
14
|
+
# @param code [String] 字元
|
|
15
|
+
# @return [Boolean]
|
|
6
16
|
def level1?(code)
|
|
7
17
|
return false if code.nil?
|
|
8
|
-
|
|
9
|
-
v = @u2.ver(code)
|
|
10
|
-
raise "Unihan2.ver 回傳 nil, code: #{code}" if v.nil?
|
|
11
|
-
v <= 3
|
|
18
|
+
LEVEL1.match?(code)
|
|
12
19
|
end
|
|
13
20
|
|
|
21
|
+
# Unicode 10 以內 在 desktop 有字型可以顯示
|
|
22
|
+
#
|
|
23
|
+
# @param code [String] 字元
|
|
24
|
+
# @return [Boolean]
|
|
14
25
|
def level2?(code)
|
|
15
26
|
return false if code.nil?
|
|
16
|
-
|
|
17
|
-
@u2.ver(code) <= 10
|
|
27
|
+
LEVEL2.match?(code)
|
|
18
28
|
end
|
|
19
29
|
end
|
data.tar.gz.sig
CHANGED
|
Binary file
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cbeta
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 4.
|
|
4
|
+
version: 4.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ray Chou
|
|
@@ -36,26 +36,6 @@ cert_chain:
|
|
|
36
36
|
-----END CERTIFICATE-----
|
|
37
37
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
38
38
|
dependencies:
|
|
39
|
-
- !ruby/object:Gem::Dependency
|
|
40
|
-
name: unihan2
|
|
41
|
-
requirement: !ruby/object:Gem::Requirement
|
|
42
|
-
requirements:
|
|
43
|
-
- - "~>"
|
|
44
|
-
- !ruby/object:Gem::Version
|
|
45
|
-
version: '1.2'
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: 1.2.0
|
|
49
|
-
type: :runtime
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - "~>"
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: '1.2'
|
|
56
|
-
- - ">="
|
|
57
|
-
- !ruby/object:Gem::Version
|
|
58
|
-
version: 1.2.0
|
|
59
39
|
- !ruby/object:Gem::Dependency
|
|
60
40
|
name: nokogiri
|
|
61
41
|
requirement: !ruby/object:Gem::Requirement
|
metadata.gz.sig
CHANGED
|
Binary file
|