sanzang 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e45b8e0b9f093af18eaa9f9cc4b2c670ea0eb044
4
- data.tar.gz: cc4cbc73c335dd6d5e3294c3f6826bdb52877398
3
+ metadata.gz: e46c28d14de2815bbd9dfaf3fa7cb9ed89555385
4
+ data.tar.gz: 5808fe326032855a17222e714daca783808872cc
5
5
  SHA512:
6
- metadata.gz: ec8dbbc4bfeb9b6c1ec02e284e2274eb8941d7195cbb49bedf3080256d5239da5632350adeee111f776127a954c0ff555419895339557c8bcc633d82459da835
7
- data.tar.gz: 3c941b3b382d93e9cc8036aeb6616d572e7f1e6f251e73c622e8212e655b5faf56e507a35d2bb335e92e1b52310263591534665dd14793dcba63c87ba8883386
6
+ metadata.gz: f2c2312ff05514cf05a340c177e57ee271a941a6ec9124b61a04e71dcd38d1d0c1f40cbea21de2f178a03f66cd4ca5107f980e69b7f7a48f3cbddbd186fa37d7
7
+ data.tar.gz: 2592b320420505a7337c404689babfb6dbf909fe76654aa8e51a85f65781b246af74a356fcbc7eb15ba2516ed2bcc5c688a700c27584cc92d4b0564a9b7a7e9d
@@ -38,6 +38,7 @@ module Sanzang::Command
38
38
  @encoding = nil
39
39
  @outdir = nil
40
40
  @jobs = nil
41
+ @verbose = false
41
42
  end
42
43
 
43
44
  # Run the batch command with the given arguments. The parameter _args_
@@ -68,11 +69,13 @@ module Sanzang::Command
68
69
  return 0
69
70
  rescue SystemExit => err
70
71
  return err.status
71
- rescue Errno::EPIPE => err
72
+ rescue Errno::EPIPE
72
73
  return 0
73
74
  rescue Exception => err
74
- $stderr.puts err.backtrace
75
- $stderr.puts "\nERROR: #{err.inspect}\n\n"
75
+ if @verbose
76
+ $stderr.puts err.backtrace
77
+ end
78
+ $stderr.puts err.inspect
76
79
  return 1
77
80
  end
78
81
 
@@ -122,6 +125,9 @@ module Sanzang::Command
122
125
  op.on("-j", "--jobs=N", "allow N concurrent processes") do |v|
123
126
  @jobs = v.to_i
124
127
  end
128
+ op.on("-v", "--verbose", "verbose mode for debugging") do |v|
129
+ @verbose = true
130
+ end
125
131
  end
126
132
  end
127
133
 
@@ -32,15 +32,18 @@ module Sanzang::Command
32
32
  #
33
33
  class Reflow
34
34
 
35
- # Create a new instance of the reflow command
35
+ # Create a new instance of the reflow command.
36
36
  #
37
37
  def initialize
38
38
  @name = "sanzang reflow"
39
39
  @encoding = Encoding.default_external
40
40
  @infile = nil
41
41
  @outfile = nil
42
+ @verbose = false
42
43
  end
43
44
 
45
+ # Get a list of all acceptable text encodings.
46
+ #
44
47
  def valid_encodings
45
48
  all_enc = Encoding.list.collect {|e| e.to_s }.sort do |x,y|
46
49
  x.upcase <=> y.upcase
@@ -88,11 +91,13 @@ module Sanzang::Command
88
91
  return 0
89
92
  rescue SystemExit => err
90
93
  return err.status
91
- rescue Errno::EPIPE => err
94
+ rescue Errno::EPIPE
92
95
  return 0
93
96
  rescue Exception => err
94
- $stderr.puts err.backtrace
95
- $stderr.puts "\nERROR: #{err.inspect}\n\n"
97
+ if @verbose
98
+ $stderr.puts err.backtrace
99
+ end
100
+ $stderr.puts err.inspect
96
101
  return 1
97
102
  end
98
103
 
@@ -140,6 +145,9 @@ module Sanzang::Command
140
145
  op.on("-o", "--outfile=FILE", "write output text to FILE") do |v|
141
146
  @outfile = v
142
147
  end
148
+ op.on("-v", "--verbose", "verbose mode for debugging") do |v|
149
+ @verbose = true
150
+ end
143
151
  end
144
152
  end
145
153
 
@@ -67,9 +67,10 @@ module Sanzang::Command
67
67
  return 1
68
68
  rescue SystemExit => err
69
69
  return err.status
70
+ rescue Errno::EPIPE
71
+ return 0
70
72
  rescue Exception => err
71
- $stderr.puts err.backtrace
72
- $stderr.puts "ERROR: #{err.inspect}"
73
+ $stderr.puts err.inspect
73
74
  return 1
74
75
  end
75
76
 
@@ -37,6 +37,22 @@ module Sanzang::Command
37
37
  @encoding = nil
38
38
  @infile = nil
39
39
  @outfile = nil
40
+ @verbose = false
41
+ end
42
+
43
+ # Get a list of all acceptable text encodings.
44
+ #
45
+ def valid_encodings
46
+ all_enc = Encoding.list.collect {|e| e.to_s }.sort do |x,y|
47
+ x.upcase <=> y.upcase
48
+ end
49
+ all_enc.find_all do |e|
50
+ begin
51
+ Encoding::Converter.search_convpath(e, Encoding::UTF_8)
52
+ rescue Encoding::ConverterNotFoundError
53
+ e == "UTF-8" ? true : false
54
+ end
55
+ end
40
56
  end
41
57
 
42
58
  # Run the translate command with the given arguments. The parameter _args_
@@ -79,11 +95,13 @@ module Sanzang::Command
79
95
  return 0
80
96
  rescue SystemExit => err
81
97
  return err.status
82
- rescue Errno::EPIPE => err
98
+ rescue Errno::EPIPE
83
99
  return 0
84
100
  rescue Exception => err
85
- $stderr.puts err.backtrace
86
- $stderr.puts "\nERROR: #{err.inspect}\n\n"
101
+ if @verbose
102
+ $stderr.puts err.backtrace
103
+ end
104
+ $stderr.puts err.inspect
87
105
  return 1
88
106
  end
89
107
 
@@ -124,10 +142,7 @@ module Sanzang::Command
124
142
  @encoding = Encoding.find(v)
125
143
  end
126
144
  op.on("-L", "--list-encodings", "list possible encodings") do |v|
127
- encodings = Encoding.list.sort do |x,y|
128
- x.to_s.upcase <=> y.to_s.upcase
129
- end
130
- puts encodings
145
+ puts valid_encodings
131
146
  exit 0
132
147
  end
133
148
  op.on("-i", "--infile=FILE", "read input text from FILE") do |v|
@@ -136,6 +151,9 @@ module Sanzang::Command
136
151
  op.on("-o", "--outfile=FILE", "write output text to FILE") do |v|
137
152
  @outfile = v
138
153
  end
154
+ op.on("-v", "--verbose", "verbose mode for debugging") do |v|
155
+ @verbose = true
156
+ end
139
157
  end
140
158
  end
141
159
 
@@ -42,11 +42,12 @@ module Sanzang
42
42
  #
43
43
  def initialize(rules)
44
44
  contents = rules.kind_of?(String) ? rules : rules.read
45
+ contents.encode!(Encoding::UTF_8)
45
46
  @encoding = contents.encoding
46
47
 
47
- left = "~|".encode(@encoding)
48
- right = "|~".encode(@encoding)
49
- separator = "|".encode(@encoding)
48
+ left = "~|"
49
+ right = "|~"
50
+ separator = "|"
50
51
 
51
52
  @records = contents.gsub("\r", "").split("\n").collect do |rec|
52
53
  rec.strip.gsub(left, "").gsub(right, "").split(separator)
@@ -48,9 +48,9 @@ module Sanzang
48
48
  end
49
49
 
50
50
  # Use the TranslationTable of the Translator to create translations for
51
- # each destination language column of the translation table. These
52
- # result is a simple Array of String objects, with each String object
53
- # corresponding to a destination language column in the TranslationTable.
51
+ # each destination language column of the translation table. The result is
52
+ # a simple Array of String objects, with each String object corresponding
53
+ # to a destination language column in the TranslationTable.
54
54
  #
55
55
  def translate(source_text)
56
56
  text_collection = [source_text]
@@ -70,10 +70,13 @@ module Sanzang
70
70
  # This is the normal text listing output of the Sanzang Translator.
71
71
  #
72
72
  def gen_listing(source_text)
73
+ source_encoding = source_text.encoding
74
+ source_text.encode!(Encoding::UTF_8)
75
+
73
76
  newline = source_text.include?("\r") ? "\r\n" : "\n"
74
77
  texts = translate(source_text).collect {|t| t = t.split(newline) }
75
- listing = "".encode(source_text.encoding)
76
78
 
79
+ listing = ""
77
80
  texts[0].length.times do |line_i|
78
81
  @table.width.times do |col_i|
79
82
  listing << "[#{line_i + 1}.#{col_i + 1}] #{texts[col_i][line_i]}" \
@@ -81,7 +84,7 @@ module Sanzang
81
84
  end
82
85
  listing << newline
83
86
  end
84
- listing
87
+ listing.encode!(source_encoding)
85
88
  end
86
89
 
87
90
  # Read a text from _input_ and write its translation listing to _output_.
@@ -20,6 +20,6 @@ module Sanzang
20
20
 
21
21
  # Current version number of Sanzang
22
22
  #
23
- VERSION = "1.0.1"
23
+ VERSION = "1.0.2"
24
24
 
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanzang
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lapis Lazuli Texts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-10 00:00:00.000000000 Z
11
+ date: 2013-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.0.0
90
+ rubygems_version: 2.0.3
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Simple rule-based machine translation system.