ebook_tools 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,5 @@
1
+ 0.0.1 2013.4.1
2
+ change docbook format
3
+
1
4
  0.0.1 2013.4.1
2
5
  init release
data/README CHANGED
@@ -1,76 +1,6 @@
1
- # encoding: UTF-8
2
- # = ExtractBookStruct
3
- # ExtractBookStruct的目的是从各类电子书内容中提取书的结构信息。目前支持txt,epub,html。
4
- # ExtractBookStruct选择从TXT文档提取书的结构信息。对TXT的文档要有如下要求:
5
- # 1. 文档的编码格式必须是UTF-8或GB2312,推荐使用UTF-8格式
6
- # 2. 文档的内容只包含书内容部分(书名、作者、目录等信息应该不包含在文档内)
7
- # 3. 文档的段落应该完整(有些PDF转换过来的文档会破坏句子,需要进行预处理)
8
- # 4. 文档必须符合正常的文档流(错位的章节段落等情况将影响正常的结构提取)
9
- # 5. 文档需要包含结构信息(例如: 卷、篇、部分、章(回)节或者有连续的序号)
10
- # 6. 每个结构信息都应该独立成行。
11
- #
12
- # 文档结构信息分析
13
- # 一本书在编排的时候会有自己的结构信息,这些结构信息通常通过卷、篇、部分、章(回)节等表述,也会使用序号的方式表述。总体上可以分为以下几种:
14
- # 1. 文本描述(text): 按卷、部分(篇)、章(回)、节等文字表述
15
- # 2. 数字描述(digital): 所有结构信息都是按照数字序号表示,比如 1 xxxxx; 1.1 xxxxx
16
- # 3. 混合描述(hybrid):章按照文字表述,节按照序号表示,比如 1.1 xxxxxx
17
- # 根据不同的类型,对结构信息的提取采用不同的处理手段。
18
- #
19
- # 有效的标题信息应该符合以下规则:
20
- # 1. 标题应该不包含完整的句子(应该不包含句子分隔符,例如“。","!"等)
21
- # 2. 应该包含结构信息表述,具体如下:
22
- # 文本描述:
23
- # 卷: 以"第xxx卷"开始
24
- # 以"卷"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
25
- # 以"volume"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
26
- # 部分(篇): 以"第xxx部"或"第xxx篇"开始
27
- # 以"part"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
28
- # 章(回): 以"第xxx章"或"第xxx回"开始
29
- # 以"chapter"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
30
- # 节: 以"第xxx节"开始
31
- # 前言: 以"前"开始,以"言"结束,中间加入空白字符。例如"前言","前 言"等。
32
- # 以"序"开始,以"言"结束,中间加入空白字符。例如"序言","序 言"等。
33
- # 单个"序"
34
- # 以"序"或"序言"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
35
- # "preface"
36
- # "foreword"
37
- # 以"preface"或"foreword"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
38
- # 索引: 以"索"开始,以"引"结束,中间加入空白字符。例如"索引","索 引"等。
39
- # 以"索引"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
40
- # "index"
41
- # 以"index"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
42
- # 附录: 以"附"开始,以"录"结束,中间加入空白字符。例如"附录","附 录"等。
43
- # 以"附录"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
44
- # "appendix"
45
- # 以"appendix"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
46
- # 术语: 以"术"开始,以"语"结束,中间加入空白字符。例如"术语","术 语"等。
47
- # 以"术语"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
48
- # "glossary"
49
- # 以"glossary"开始,后面跟序号表述方式,例如 “I”,“Ⅱ”,“1”等
50
- #
51
- # 数字描述:
52
- # 以数字序号层级表达,数字序号和标题内容之间有空白字符分隔。例如"1 管理的概念", "1.1 定义", "1.1.1 管理"等。
53
- #
54
- # ==API接口
55
- #
56
- # === ExtractBookStruct.from_txt
57
- # 从文本文件中提取目录结构,使用示例:
58
- # ExtractBookStruct.from_txt('1.txt',{:title=>'title',:author=>'author'})
59
- #
60
- # === ExtractBookStruct.from_epub
61
- # 从EPUB文件中提取目录结构,使用示例:
62
- # ExtractBookStruct.from_epub('1.epub',{:title=>'title',:author=>'author'})
63
- #
64
- # === ExtractBookStruct.from_html
65
- # 从HTML中提取目录结构,使用示例:
66
- # ExtractBookStruct.from_html('1.html',{:title=>'title',:author=>'author'})
67
- #
68
- # == 命令行工具
69
- # extract_book_struct,使用示例:
70
- # extract_book_struct '1.txt', '1.xml'
71
- #
72
- # == 依赖
73
- # ExtractBookStruct依赖以下工具和包:
74
- # ebook-convert: calibre cli tools.
75
- # uuid: ruby gem.
76
- # iconv: ruby gem.
1
+ = ebook_tools
2
+ ebook tools
3
+
4
+ == Installation
5
+
6
+ gem install ebook_tools
data/ebook_tools.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ebook_tools}
5
- s.version = '0.0.1'
5
+ s.version = '0.0.2'
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aaron"]
@@ -30,16 +30,19 @@ module ExtractBookStruct
30
30
  extend HeaderDetect
31
31
 
32
32
  def from_txt(filename,options={})
33
+ options[:title] ||= File.basename(filename,File.extname(filename))
33
34
  content = File.open(filename).read
34
35
  extract_book_struct(content,options)
35
36
  end
36
37
 
37
38
  def from_html(filename,options={})
39
+ options[:title] ||= File.basename(filename,File.extname(filename))
38
40
  content = extract_text_from_file(filename,'.html')
39
41
  extract_book_struct(content,options)
40
42
  end
41
43
 
42
44
  def from_epub(filename,options={})
45
+ options[:title] ||= File.basename(filename,File.extname(filename))
43
46
  content = extract_text_from_file(filename,'.epub')
44
47
  extract_book_struct(content,options)
45
48
  end
@@ -50,7 +53,6 @@ module ExtractBookStruct
50
53
  end
51
54
  content = sanitize_for_epub_text(content)
52
55
  paras = extract_paras(content)
53
-
54
56
  # 检查书类型(text,digital,hybrid)
55
57
  format = options[:format] || detect_struct_type(paras)
56
58
  case format
@@ -112,13 +114,10 @@ module ExtractBookStruct
112
114
  def extract_text_book_struct(content,options={})
113
115
  # 标注结构信息
114
116
  marked_content = mark_struct_info(content)
115
-
116
117
  # 构建书结构
117
118
  struct = build_struct(marked_content)
118
-
119
119
  # 修正结构
120
120
  revised_struct = revise_struct(struct)
121
-
122
121
  # 生成docbook
123
122
  build_doc_book(revised_struct,options)
124
123
  end
@@ -227,9 +226,11 @@ module ExtractBookStruct
227
226
  <book xmlns="http://docbook.org/ns/docbook" version="5.0">
228
227
  <info>
229
228
  <title>#{options[:title]}</title>
230
- <author>#{options[:author]}</author>
229
+ <authorgroup>
230
+ <author><personname>#{options[:author]}</personname></author>
231
+ </authorgroup>
231
232
  <pubdate>#{options[:pubdate]}</pubdate>
232
- <publisher>#{options[:publisher]}</publisher>
233
+ <publisher><publishername>#{options[:publisher]}</publishername></publisher>
233
234
  </info>
234
235
  #{doc_toc}
235
236
  #{doc_content}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebook_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: