bow_tfidf 0.1.0 → 0.1.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 +4 -4
- data/Gemfile.lock +34 -0
- data/README.md +27 -1
- data/bow_tfidf-0.1.0.gem +0 -0
- data/lib/bow_tfidf/classifier.rb +2 -1
- data/lib/bow_tfidf/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40d14aa0f73576f5e41347a94beb38c6a5656841dc6e6d6c0d9226684372e2ab
|
|
4
|
+
data.tar.gz: 3f98488216254e1d318a2aef7b00bee20f5922a6844c18d05f15921cd2ee2296
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b3b166ff76a9b2513eac62b918ee386d7b8c5cd8e0683f60d3c8663f7c09d217b3ad56275eda26f6e5b6506f071ec69bdbfbd725daf8686ec4549b925090ea3
|
|
7
|
+
data.tar.gz: d6a2afb56d90fa0edeb2c8f10bde35ccca4892da735056205ee2d8d1e38a3433c9f45a5cd206b75fa8c4ddf013fdc18f37c7ca125616e4adc404cdd8c09e1973
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
bow_tfidf (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
diff-lcs (1.2.5)
|
|
10
|
+
rake (10.1.0)
|
|
11
|
+
rspec (3.1.0)
|
|
12
|
+
rspec-core (~> 3.1.0)
|
|
13
|
+
rspec-expectations (~> 3.1.0)
|
|
14
|
+
rspec-mocks (~> 3.1.0)
|
|
15
|
+
rspec-core (3.1.7)
|
|
16
|
+
rspec-support (~> 3.1.0)
|
|
17
|
+
rspec-expectations (3.1.2)
|
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
+
rspec-support (~> 3.1.0)
|
|
20
|
+
rspec-mocks (3.1.3)
|
|
21
|
+
rspec-support (~> 3.1.0)
|
|
22
|
+
rspec-support (3.1.2)
|
|
23
|
+
|
|
24
|
+
PLATFORMS
|
|
25
|
+
ruby
|
|
26
|
+
|
|
27
|
+
DEPENDENCIES
|
|
28
|
+
bow_tfidf!
|
|
29
|
+
bundler (~> 1.13)
|
|
30
|
+
rake (~> 10.0)
|
|
31
|
+
rspec
|
|
32
|
+
|
|
33
|
+
BUNDLED WITH
|
|
34
|
+
1.16.0
|
data/README.md
CHANGED
|
@@ -36,13 +36,39 @@ Or install it yourself as:
|
|
|
36
36
|
First of all bag of words with computed tfidf for each word should be created. For this add labeled words as a hash to bag of words:
|
|
37
37
|
|
|
38
38
|
```ruby
|
|
39
|
-
bow =
|
|
39
|
+
bow = BowTfidf::BagOfWords.new
|
|
40
40
|
bow.add_labeled_data!({
|
|
41
41
|
category1: ['word', 'word1'],
|
|
42
42
|
category2: ['word', 'word2']
|
|
43
43
|
category3: ['word', 'word2', 'word3']
|
|
44
44
|
})
|
|
45
45
|
```
|
|
46
|
+
Instance of `BowTfidf::BagOfWords` responds to `words` and `categories` methods:
|
|
47
|
+
```ruby
|
|
48
|
+
bow.words
|
|
49
|
+
#{
|
|
50
|
+
# 'word1' => {
|
|
51
|
+
# categories: {
|
|
52
|
+
# 1 => {
|
|
53
|
+
# tf: 0.3010299956639812,
|
|
54
|
+
# tfidf: 0.14362780923945326
|
|
55
|
+
# }
|
|
56
|
+
# },
|
|
57
|
+
# idf: 0.47712125471966244
|
|
58
|
+
# },
|
|
59
|
+
# ...
|
|
60
|
+
#}
|
|
61
|
+
|
|
62
|
+
bow.categories
|
|
63
|
+
#{
|
|
64
|
+
# category1: {
|
|
65
|
+
# id: 1,
|
|
66
|
+
# key: :category1,
|
|
67
|
+
# words: Set['word', 'word1']
|
|
68
|
+
# },
|
|
69
|
+
# ...
|
|
70
|
+
#}
|
|
71
|
+
```
|
|
46
72
|
|
|
47
73
|
To identify category of text pass array of words as argument to category classifier:
|
|
48
74
|
```ruby
|
data/bow_tfidf-0.1.0.gem
ADDED
|
Binary file
|
data/lib/bow_tfidf/classifier.rb
CHANGED
|
@@ -6,12 +6,13 @@ module BowTfidf
|
|
|
6
6
|
raise(ArgumentError, 'BowTfidf::BagOfWords instance expected') unless bow.is_a?(BowTfidf::BagOfWords)
|
|
7
7
|
|
|
8
8
|
@bow = bow
|
|
9
|
-
@score = {}
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def call(tokens)
|
|
13
12
|
raise(ArgumentError, 'Array of strings expected') unless tokens.is_a?(Array)
|
|
14
13
|
|
|
14
|
+
@score = {}
|
|
15
|
+
|
|
15
16
|
tokens.each do |word|
|
|
16
17
|
process_word(word)
|
|
17
18
|
end
|
data/lib/bow_tfidf/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bow_tfidf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- isidzukuri
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-04-
|
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -67,10 +67,12 @@ extensions: []
|
|
|
67
67
|
extra_rdoc_files: []
|
|
68
68
|
files:
|
|
69
69
|
- Gemfile
|
|
70
|
+
- Gemfile.lock
|
|
70
71
|
- README.md
|
|
71
72
|
- Rakefile
|
|
72
73
|
- bin/console
|
|
73
74
|
- bin/setup
|
|
75
|
+
- bow_tfidf-0.1.0.gem
|
|
74
76
|
- bow_tfidf.gemspec
|
|
75
77
|
- lib/bow_tfidf.rb
|
|
76
78
|
- lib/bow_tfidf/bag_of_words.rb
|