natto2classifier 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +0 -10
- data/Gemfile.lock +1 -1
- data/README.md +11 -0
- data/lib/natto2classifier.rb +1 -0
- data/lib/natto2classifier/bayes.rb +17 -0
- data/lib/natto2classifier/lsi.rb +22 -0
- data/lib/natto2classifier/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8ef6d3851edf130a6a2b7ca3a6ba7c305cf39be
|
4
|
+
data.tar.gz: a73d1ab45544793c3a27a704233b29a8a1898b04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1b3dc2ca4d798aaffbcd1be95bd03d62a822550520b029b734a13265161582ca82c25d1720e6d05ebcab6c1c126e62e98b64ac345403e52c4b544914a0edc4a
|
7
|
+
data.tar.gz: 89fcf93bc0d47633659bfffa12b375d34f25cad5a8a774a7746b3c9e7dcbc99cba8eb6a72009b29d6660c41deb029eea2609c5c79fe8aae224c19b5ab1c0a2f4
|
data/.circleci/config.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,17 @@ lsi.classify '納豆はいつも朝食べている' #=> '朝食'
|
|
39
39
|
lsi.find_related '納豆はいつも朝食べている' #=> ['今日 キョウ の ノ 朝食 チョウショク は ハ 納豆 ナットウ だ ダ', '今日 キョウ の ノ 夕食 ユウショク は ハ 湯豆腐 ユドウフ だ ダ']
|
40
40
|
```
|
41
41
|
|
42
|
+
### validate methods
|
43
|
+
|
44
|
+
```
|
45
|
+
sample_data = CSV.read('./data/train.csv')
|
46
|
+
bayes = Natto2classifier::Bayes.new '朝食', '夕食'
|
47
|
+
cross_validate(bayes, sample_data) #=> report...
|
48
|
+
|
49
|
+
test_data, training_data = sample_data.partition.with_index { |_, i| (i % 2).zero? }
|
50
|
+
validate(bayes, training_data, test_data) #=> {"夕食"=>{"夕食"=>3, "朝食"=>0}, "朝食"=>{"夕食"=>...}}
|
51
|
+
```
|
52
|
+
|
42
53
|
## Development
|
43
54
|
|
44
55
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/natto2classifier.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
module Natto2classifier
|
3
|
+
# It is a library that classifies Japanese language.
|
4
|
+
class Bayes < ClassifierReborn::Bayes
|
5
|
+
alias_method :__train__, :train
|
6
|
+
alias_method :__classify__, :classify
|
7
|
+
private :__train__, :__classify__
|
8
|
+
|
9
|
+
def train(category, word)
|
10
|
+
__train__ category, Natto2classifier::Natto.parse(word).join(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def classify(word)
|
14
|
+
__classify__ Natto2classifier::Natto.parse(word).join(' ')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
module Natto2classifier
|
3
|
+
# It is a library that classifies Japanese language.
|
4
|
+
class LSI < ClassifierReborn::LSI
|
5
|
+
alias_method :__add_item__, :add_item
|
6
|
+
alias_method :__classify__, :classify
|
7
|
+
alias_method :__find_related__, :find_related
|
8
|
+
private :__add_item__, :__classify__, :__find_related__
|
9
|
+
|
10
|
+
def add_item(word, category)
|
11
|
+
__add_item__ Natto2classifier::Natto.parse(word).join(' '), category
|
12
|
+
end
|
13
|
+
|
14
|
+
def classify(word)
|
15
|
+
__classify__ Natto2classifier::Natto.parse(word).join(' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_related(word)
|
19
|
+
__find_related__ Natto2classifier::Natto.parse(word).join(' ')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: natto2classifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kanayannet
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,6 +129,8 @@ files:
|
|
129
129
|
- bin/setup
|
130
130
|
- data/train.csv
|
131
131
|
- lib/natto2classifier.rb
|
132
|
+
- lib/natto2classifier/bayes.rb
|
133
|
+
- lib/natto2classifier/lsi.rb
|
132
134
|
- lib/natto2classifier/natto.rb
|
133
135
|
- lib/natto2classifier/version.rb
|
134
136
|
- natto2classifier.gemspec
|