tiny-classifier 2.0 → 2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff0e4cd3aafc37e4ba99b782d3b7816c6bbb5f9f
4
- data.tar.gz: d9b99162fe1711f3f7cdaaf3791f1df9d75df14f
3
+ metadata.gz: 7eb179e8a3a17711921f6bd0af6132909ace2f90
4
+ data.tar.gz: 2f029f934ddb3f5277980228800fa24093491bab
5
5
  SHA512:
6
- metadata.gz: 933a1773de70ee773863a643556ec4dfedff6433ee3385b4ce8f3283efa1959e25027fae1712f410c39d70f72b74a06b231299d5041a12276afe8c771f948047
7
- data.tar.gz: 93602fc9af2bda18c52beaefd980b912aa438b95526c549d965fde192c3f3061fbb1ebffaf13de221ec92ae57e7cf25b06adb3c0c83c90f16520aa3208037cab
6
+ metadata.gz: 9ecc0831b783aed6891e09fe73260f0eef63f021e450bf4db89cea267b4797cffade8f74b05530a058646d77ca1265a24ea7287e6754e132ec1e724d0ae21611
7
+ data.tar.gz: aa5e0822ebcbc19b5497f1596be44b3b01e0fe184903d8b111fa9eae635f5bfd8c94ed34bda5a98658514cf10d185806abbd0eb12a124beba92943750bf107a0
data/README.md CHANGED
@@ -67,7 +67,7 @@ positive
67
67
 
68
68
  ### Common
69
69
 
70
- `-l`, `--categories=CATEGORIES` (required)
70
+ `-c`, `--categories=CATEGORIES` (required)
71
71
  : A comman-separated list of categories. You should use only alphabetic characters. (Non-alphabetical characters will cause problems.)
72
72
 
73
73
  `-d`, `--data-dir=PATH` (optional)
@@ -25,6 +25,7 @@ module TinyClassifier
25
25
  def initialize
26
26
  @tokenizer = Tokenizer.new
27
27
  @data_dir = Dir.pwd
28
+ @verbose = false
28
29
  end
29
30
 
30
31
  def parse_command_line_options(command_line_options)
@@ -51,6 +52,7 @@ module TinyClassifier
51
52
  parser.on("-c CATEGORIES", "--categories=CATEGORIES",
52
53
  "List of categories (comma-separated)") do |categories|
53
54
  @categories = normalize_categories(categories)
55
+ log("categories: #{@categories}")
54
56
  end
55
57
 
56
58
  parser.on("-t TOKENIZER", "--tokenizer=TOKENIZER",
@@ -58,6 +60,11 @@ module TinyClassifier
58
60
  @tokenizer.type = tokenizer
59
61
  end
60
62
 
63
+ parser.on("-v", "--verbose",
64
+ "Output internal information (for debugging)") do |verbose|
65
+ @verbose = verbose
66
+ end
67
+
61
68
  parser
62
69
  end
63
70
 
@@ -107,12 +114,23 @@ module TinyClassifier
107
114
 
108
115
  def prepare_input
109
116
  unless File.pipe?(STDIN)
110
- STDERR.puts("Error: No effective input. You need to give any input via the STDIN.")
117
+ error("Error: No effective input. You need to give any input via the STDIN.")
111
118
  exit(false)
112
119
  end
113
120
  @input = $stdin.readlines.join(" ")
114
- @tokenizer.tokenize(@input)
121
+ @input = @tokenizer.tokenize(@input)
122
+ log("tokenizer: #{@tokenizer.type}")
115
123
  @input.strip!
124
+ log("input: #{@input}")
125
+ @input
126
+ end
127
+
128
+ def error(message)
129
+ STDERR.puts(message)
130
+ end
131
+
132
+ def log(message)
133
+ STDERR.puts(message) if @verbose
116
134
  end
117
135
  end
118
136
  end
@@ -30,7 +30,7 @@ module TinyClassifier
30
30
 
31
31
  def run
32
32
  if input.empty?
33
- STDERR.puts("Error: No effective input.")
33
+ error("Error: No effective input.")
34
34
  false
35
35
  else
36
36
  category = classifier.classify(input)
@@ -29,7 +29,7 @@ module TinyClassifier
29
29
 
30
30
  def run(params)
31
31
  if input.empty?
32
- STDERR.puts("Error: No effective input.")
32
+ error("Error: No effective input.")
33
33
  false
34
34
  else
35
35
  @category = params[:wrong]
@@ -27,7 +27,7 @@ module TinyClassifier
27
27
  end
28
28
 
29
29
  def tokenize(input)
30
- case @tokenizer.to_s.downcase.to_sym
30
+ case @type.to_s.downcase.to_sym
31
31
  when :mecab
32
32
  tokenize_by_mecab(input)
33
33
  else
@@ -35,7 +35,7 @@ module TinyClassifier
35
35
  @category = params[:category]
36
36
  prepare_category
37
37
  if input.empty?
38
- STDERR.puts("Error: No effective input.")
38
+ error("Error: No effective input.")
39
39
  false
40
40
  else
41
41
  classifier.send("train_#{@category}", input)
@@ -47,19 +47,19 @@ module TinyClassifier
47
47
  private
48
48
  def prepare_category
49
49
  unless @category
50
- STDERR.puts("Error: You need to specify the category for the input.")
50
+ error("Error: You need to specify the category for the input.")
51
51
  exit(false)
52
52
  end
53
53
 
54
54
  @category = @category.downcase.strip
55
55
 
56
56
  if @category.empty?
57
- STDERR.puts("Error: You need to specify the category for the input.")
57
+ error("Error: You need to specify the category for the input.")
58
58
  exit(false)
59
59
  end
60
60
 
61
61
  unless @categories.include?(@category.capitalize)
62
- STDERR.puts("Error: You need to specify one of valid categories: #{@categories.join(', ')}")
62
+ error("Error: You need to specify one of valid categories: #{@categories.join(', ')}")
63
63
  exit(false)
64
64
  end
65
65
  end
@@ -21,7 +21,7 @@ module TinyClassifier
21
21
  @category = params[:category]
22
22
  prepare_category
23
23
  if input.empty?
24
- STDERR.puts("Error: No effective input.")
24
+ error("Error: No effective input.")
25
25
  false
26
26
  else
27
27
  classifier.send("untrain_#{@category}", input)
@@ -21,7 +21,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
21
21
 
22
22
  Gem::Specification.new do |spec|
23
23
  spec.name = "tiny-classifier"
24
- spec.version = "2.0"
24
+ spec.version = "2.1"
25
25
  spec.homepage = "https://github.com/piroor/tiny-classifier"
26
26
  spec.authors = ["YUKI \"Piro\" Hiroshi"]
27
27
  spec.email = ["piro.outsider.reflex@gmail.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny-classifier
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '2.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - YUKI "Piro" Hiroshi