cbeta 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cbeta/bm_to_text.rb +1 -1
- data/lib/cbeta/gaiji.rb +8 -3
- data/lib/cbeta/html_to_text.rb +5 -5
- data/lib/cbeta/p5a_to_html.rb +18 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9f3c314b6f04464ac94f76c00b5193e7a3bea70
|
4
|
+
data.tar.gz: 0eab9e6c2faa06dae62e3d2ea3e0abc9dc0a4bb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b46179de8ad84ca2a3258c86af91c7d2054953b42b4c037596f3f367e23a68a81a4c3d4293e1c63d4496cd5f2b6143047bfdbbeaf70c69c86a14efe51a20d51
|
7
|
+
data.tar.gz: d6fea9409f2f5b9f801b8aa1447fd530949c5cecc6caeb3f95bf80532f5727733f6ff90a0d9381e563654f8b9284400f39894146a742ee4f66dc06f649e95d3a
|
data/lib/cbeta/bm_to_text.rb
CHANGED
data/lib/cbeta/gaiji.rb
CHANGED
@@ -8,10 +8,13 @@ class CBETA::Gaiji
|
|
8
8
|
@gaijis = JSON.parse(File.read(fn))
|
9
9
|
end
|
10
10
|
|
11
|
-
#
|
11
|
+
# 傳入,傳回 hash 缺字資訊
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# @param cb [String] 缺字 CB 碼
|
14
|
+
# @return [Hash{String => Strin, Array<String>}] 缺字資訊
|
15
|
+
# @return [nil] 如果該 CB 碼在 CBETA 缺字庫中不存在
|
14
16
|
#
|
17
|
+
# @example
|
15
18
|
# g = Cbeta::Gaiji.new
|
16
19
|
# g["CB01002"]
|
17
20
|
#
|
@@ -28,8 +31,10 @@ class CBETA::Gaiji
|
|
28
31
|
|
29
32
|
# 傳入缺字 CB 碼,傳回注音 array
|
30
33
|
#
|
31
|
-
#
|
34
|
+
# @param cb [String] 缺字 CB 碼
|
35
|
+
# @return [Array<String>]
|
32
36
|
#
|
37
|
+
# @example
|
33
38
|
# g = Cbeta::Gaiji.new
|
34
39
|
# g.zhuyin("CB00023") # return [ "ㄍㄢˇ", "ㄍㄢ", "ㄧㄤˊ", "ㄇㄧˇ", "ㄇㄧㄝ", "ㄒㄧㄤˊ" ]
|
35
40
|
def zhuyin(cb)
|
data/lib/cbeta/html_to_text.rb
CHANGED
@@ -8,16 +8,16 @@ require 'nokogiri'
|
|
8
8
|
# h2t = CBETA::HTMLToText.new('/temp/cbeta-html', '/temp/cbeta-text')
|
9
9
|
# h2t.convert("T01") # 轉換大正藏第一冊
|
10
10
|
class CBETA::HTMLToText
|
11
|
-
# html_root
|
12
|
-
# out_root
|
11
|
+
# @param html_root [String] 來源 HTML 路徑
|
12
|
+
# @param out_root [String] 輸出路徑
|
13
13
|
def initialize(html_root, out_root)
|
14
14
|
@html_root = html_root
|
15
15
|
@out_root = out_root
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
18
|
+
# @param arg [String] 要執行轉換的冊數
|
19
|
+
# @example
|
20
|
+
# convert("T01")
|
21
21
|
def convert(arg)
|
22
22
|
@dirty = false
|
23
23
|
@vol = arg.upcase
|
data/lib/cbeta/p5a_to_html.rb
CHANGED
@@ -18,8 +18,8 @@ MISSING = '-'
|
|
18
18
|
# 轉檔規則請參考: http://wiki.ddbc.edu.tw/pages/CBETA_XML_P5a_轉_HTML
|
19
19
|
class CBETA::P5aToHTML
|
20
20
|
|
21
|
-
# xml_root
|
22
|
-
# out_root
|
21
|
+
# @param xml_root [String] 來源 CBETA XML P5a 路徑
|
22
|
+
# @param out_root [String] 輸出 HTML 路徑
|
23
23
|
def initialize(xml_root, out_root)
|
24
24
|
@xml_root = xml_root
|
25
25
|
@out_root = out_root
|
@@ -33,16 +33,21 @@ class CBETA::P5aToHTML
|
|
33
33
|
|
34
34
|
# 將 CBETA XML P5a 轉為 HTML
|
35
35
|
#
|
36
|
-
#
|
36
|
+
# @example for convert 大正藏第一冊:
|
37
37
|
#
|
38
38
|
# x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
|
39
39
|
# x2h.convert('T01')
|
40
40
|
#
|
41
|
-
#
|
41
|
+
# @example for convert 大正藏全部:
|
42
42
|
#
|
43
43
|
# x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
|
44
44
|
# x2h.convert('T')
|
45
45
|
#
|
46
|
+
# @example for convert 大正藏第五冊至第七冊:
|
47
|
+
#
|
48
|
+
# x2h = CBETA::P5aToHTML.new('/PATH/TO/CBETA/XML/P5a', '/OUTPUT/FOLDER')
|
49
|
+
# x2h.convert('T05..T07')
|
50
|
+
#
|
46
51
|
# T 是大正藏的 ID, CBETA 的藏經 ID 系統請參考: http://www.cbeta.org/format/id.php
|
47
52
|
def convert(arg=nil)
|
48
53
|
return convert_all if arg.nil?
|
@@ -489,7 +494,11 @@ class CBETA::P5aToHTML
|
|
489
494
|
juans.each { |j|
|
490
495
|
if j =~ /<juan (\d+)>$/
|
491
496
|
juan_no = $1.to_i
|
492
|
-
|
497
|
+
if @sutra_no.match(/^(T05|T06|T07)n0220/)
|
498
|
+
fn = "#{$1}n0220_%03d.htm" % juan_no
|
499
|
+
else
|
500
|
+
fn = "#{@sutra_no}_%03d.htm" % juan_no
|
501
|
+
end
|
493
502
|
output_path = File.join(@out_folder, fn)
|
494
503
|
fo = File.open(output_path, 'w')
|
495
504
|
open = true
|
@@ -503,7 +512,7 @@ class CBETA::P5aToHTML
|
|
503
512
|
<body>
|
504
513
|
<!--
|
505
514
|
來源 XML CBETA P5a: https://github.com/cbeta-org/xml-p5a.git
|
506
|
-
轉檔程式:
|
515
|
+
轉檔程式: https://rubygems.org/gems/cbeta #{Date.today}
|
507
516
|
說明文件: http://wiki.ddbc.edu.tw/pages/CBETA_XML_P5a_%E8%BD%89_HTML
|
508
517
|
-->
|
509
518
|
<div id='body'>
|
@@ -549,7 +558,7 @@ eos
|
|
549
558
|
end
|
550
559
|
|
551
560
|
def handle_vol(vol)
|
552
|
-
puts
|
561
|
+
puts "handle volumn: #{vol}"
|
553
562
|
if vol.start_with? 'T'
|
554
563
|
@orig = "【大】"
|
555
564
|
else
|
@@ -568,8 +577,9 @@ eos
|
|
568
577
|
end
|
569
578
|
|
570
579
|
def handle_vols(v1, v2)
|
580
|
+
puts "handle volumns: #{v1}..#{v2}"
|
571
581
|
@series = v1[0]
|
572
|
-
folder = File.join(
|
582
|
+
folder = File.join(@xml_root, @series)
|
573
583
|
Dir.foreach(folder) { |vol|
|
574
584
|
next if vol < v1
|
575
585
|
next if vol > v2
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbeta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ray Chou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby gem for use Chinese Buddhist Text resources made by CBETA (http://www.cbeta.org).
|
14
14
|
email: zhoubx@gmail.com
|