tiny-classifier 1.1 → 1.2
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
- data/README.md +2 -0
- data/lib/tiny-classifier/base.rb +9 -7
- data/lib/tiny-classifier/classifier.rb +3 -6
- data/lib/tiny-classifier/trainer.rb +3 -7
- data/tiny-classifier.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4640ed17e08cec0d4c7e06a7acedc0527669506
|
4
|
+
data.tar.gz: 982f06aad8df916300a18b04ca00ac9e0ae2dceb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd7a63f5ff86e02b32a63a852f40d17ffce45ccd9ee5d68ee1fc131f68d770f595fae5c12a039d207ef557e2ee23229c2bea0755d7c36b84444bd0721e27e29e
|
7
|
+
data.tar.gz: 67ad761ba648d8718b1dd6339e83c221856223e180787d14e7761106b7589e588468f6d47d6bc3f3471d2c591868a0d72756532d5e530f944bc7f8f5e10409f4
|
data/README.md
CHANGED
@@ -33,6 +33,8 @@ Training:
|
|
33
33
|
% echo "Oh my god!" | tc-train --labels=positive,negative negative
|
34
34
|
```
|
35
35
|
|
36
|
+
The training data will be saved as `tc.positive-negative.dat` (`tc.` is the fixed prefix, `.dat` is the fixed suffix. The middle part is filled by given labels automatically.) in the current directory. If you hope the file to be saved in any different place, please specify `--base-dir=/path/to/data/directory`.
|
37
|
+
|
36
38
|
Classifying:
|
37
39
|
|
38
40
|
~~~
|
data/lib/tiny-classifier/base.rb
CHANGED
@@ -99,7 +99,16 @@ class TinyClassifierBase
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
def input
|
103
|
+
@input ||= prepare_input
|
104
|
+
end
|
105
|
+
|
102
106
|
def prepare_input
|
107
|
+
unless File.pipe?(STDIN)
|
108
|
+
STDERR.puts("Error: No effective input. You need to give any input via the STDIN.")
|
109
|
+
exit(false)
|
110
|
+
end
|
111
|
+
@input = $stdin.readlines.join("\n")
|
103
112
|
tokenize
|
104
113
|
@input.strip!
|
105
114
|
end
|
@@ -122,11 +131,4 @@ class TinyClassifierBase
|
|
122
131
|
end
|
123
132
|
@input = terms.join(" ").strip
|
124
133
|
end
|
125
|
-
|
126
|
-
def save
|
127
|
-
data = Marshal.dump(classifier)
|
128
|
-
File.open(data_file_path, "w") do |file|
|
129
|
-
file.write(data)
|
130
|
-
end
|
131
|
-
end
|
132
134
|
end
|
@@ -21,20 +21,17 @@ class Classifier < TinyClassifierBase
|
|
21
21
|
argv ||= ARGV.dup
|
22
22
|
classifier = new
|
23
23
|
classifier.parse_command_line_options(argv)
|
24
|
-
|
25
|
-
classifier.run(input: input)
|
24
|
+
classifier.run
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
def run(params)
|
30
29
|
@label = params[:label]
|
31
|
-
|
32
|
-
prepare_input
|
33
|
-
if @input.empty?
|
30
|
+
if input.empty?
|
34
31
|
STDERR.puts("Error: No effective input.")
|
35
32
|
false
|
36
33
|
else
|
37
|
-
label = classifier.classify(
|
34
|
+
label = classifier.classify(input)
|
38
35
|
puts label.downcase
|
39
36
|
true
|
40
37
|
end
|
@@ -21,9 +21,7 @@ class Trainer < TinyClassifierBase
|
|
21
21
|
argv ||= ARGV.dup
|
22
22
|
trainer = new
|
23
23
|
*labels = trainer.parse_command_line_options(argv)
|
24
|
-
|
25
|
-
trainer.run(label: labels.first,
|
26
|
-
input: input)
|
24
|
+
trainer.run(label: labels.first)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
@@ -34,14 +32,12 @@ class Trainer < TinyClassifierBase
|
|
34
32
|
|
35
33
|
def run(params)
|
36
34
|
@label = params[:label]
|
37
|
-
@input = params[:input]
|
38
35
|
prepare_label
|
39
|
-
|
40
|
-
if @input.empty?
|
36
|
+
if input.empty?
|
41
37
|
STDERR.puts("Error: No effective input.")
|
42
38
|
false
|
43
39
|
else
|
44
|
-
classifier.send("train_#{@label}",
|
40
|
+
classifier.send("train_#{@label}", input)
|
45
41
|
save
|
46
42
|
true
|
47
43
|
end
|
data/tiny-classifier.gemspec
CHANGED
@@ -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 = "1.
|
24
|
+
spec.version = "1.2"
|
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"]
|