bronto-gem 0.0.2 → 0.1.0
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/.travis.yml +3 -0
- data/README.md +8 -7
- data/{bronto-gem.gemspec → bronto.gemspec} +2 -3
- data/lib/{bronto-gem.rb → bronto.rb} +2 -2
- data/lib/bronto/thesaurus.rb +55 -0
- data/lib/bronto/version.rb +3 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/thesaurus_spec.rb +33 -0
- metadata +9 -8
- data/lib/bronto-gem/lookup.rb +0 -36
- data/lib/bronto-gem/version.rb +0 -3
- data/spec/lookup_spec.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aba4131be2d46e7c94146e2514fb0faec50a7aa3
|
4
|
+
data.tar.gz: ba91b9f62b56a7849c0816571eb8bedbcfd2ab81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e895246561af2e585572c2a1e6ce23324197f0b0d3861abb02b1efc84eb82c99449f4257a33462eca65f3ae300b88d06a96aefd58df7bf8005d6f3c6fdd059a
|
7
|
+
data.tar.gz: 6487718b300416b84c99ea1e416f8409b47093f52f80bdd43d2c433f2a75f5d1d8a8e4a02d883fbac29762190fe63aa534298bbee3e27c692ff5af4ddc437dbc
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A thesaurus gem.
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'bronto-gem'
|
10
|
+
gem 'bronto-gem', '0.1.0'
|
11
11
|
````
|
12
12
|
|
13
13
|
And then execute:
|
@@ -26,9 +26,9 @@ $ gem install bronto-gem
|
|
26
26
|
## Usage
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
require 'bronto
|
29
|
+
require 'bronto'
|
30
30
|
|
31
|
-
synonyms =
|
31
|
+
synonyms = Bronto::Thesaurus.new.lookup("fish") #=>
|
32
32
|
|
33
33
|
{
|
34
34
|
verb: {
|
@@ -36,7 +36,7 @@ synonyms = BrontoGem.lookup("fish") #=>
|
|
36
36
|
},
|
37
37
|
noun: {
|
38
38
|
syn: [
|
39
|
-
|
39
|
+
"aquatic vertebrate",
|
40
40
|
"food",
|
41
41
|
"individual",
|
42
42
|
"mortal",
|
@@ -46,14 +46,15 @@ synonyms = BrontoGem.lookup("fish") #=>
|
|
46
46
|
"solid food",
|
47
47
|
"somebody",
|
48
48
|
"someone",
|
49
|
-
"soul"
|
49
|
+
"soul"
|
50
|
+
]
|
50
51
|
}
|
51
52
|
}
|
52
53
|
```
|
53
54
|
|
54
55
|
## Contributing
|
55
56
|
|
56
|
-
1. Fork it ( https://github.com/
|
57
|
+
1. Fork it ( https://github.com/18F/bronto/fork )
|
57
58
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
59
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
60
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -61,4 +62,4 @@ synonyms = BrontoGem.lookup("fish") #=>
|
|
61
62
|
|
62
63
|
## License
|
63
64
|
|
64
|
-
See `LICENSE.txt`
|
65
|
+
Public Domain. See `LICENSE.txt`
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'bronto
|
5
|
-
#require 'bronto/bronto-gem/lookup'
|
4
|
+
require 'bronto/version'
|
6
5
|
|
7
6
|
Gem::Specification.new do |spec|
|
8
7
|
spec.name = "bronto-gem"
|
9
|
-
spec.version =
|
8
|
+
spec.version = Bronto::VERSION
|
10
9
|
spec.authors = ["Alan deLevie"]
|
11
10
|
spec.email = ["alan.delevie@gsa.gov"]
|
12
11
|
spec.summary = %q{Thesaurus gem}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'wordnet'
|
2
|
+
require 'wordnet-defaultdb'
|
3
|
+
|
4
|
+
$lex = WordNet::Lexicon.new
|
5
|
+
|
6
|
+
module Bronto
|
7
|
+
class Thesaurus
|
8
|
+
def lookup(word)
|
9
|
+
query = word.downcase
|
10
|
+
synonyms = get_synonyms query
|
11
|
+
return nil if synonyms.nil? # check out early if nothing is found
|
12
|
+
|
13
|
+
hash = {}
|
14
|
+
|
15
|
+
if synonyms
|
16
|
+
synonyms.each do |synonym|
|
17
|
+
hash[synonym.last] = {syn: [] } unless hash.member?(synonym.last)
|
18
|
+
hash[synonym.last][:syn] << synonym.first
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
hash.keys.each do |key1|
|
23
|
+
val1 = hash[key1]
|
24
|
+
val1.sort! if val1.respond_to? :sort!
|
25
|
+
|
26
|
+
val1.keys.each do |key2|
|
27
|
+
val2 = hash[key1][key2]
|
28
|
+
val2.sort! if val2.respond_to? :sort!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
hash
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def get_synonyms(query)
|
38
|
+
synsets = $lex.lookup_synsets(query)
|
39
|
+
|
40
|
+
words = []
|
41
|
+
|
42
|
+
synsets.each do |synset|
|
43
|
+
synset.words.map {|word| words << [word.lemma, synset.part_of_speech.to_sym] unless word.lemma == query}
|
44
|
+
|
45
|
+
synset.hypernyms.each do |hypernym|
|
46
|
+
hypernym.words.map {|word| words << [word.lemma, synset.part_of_speech.to_sym] unless word.lemma == query}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
synonyms = words.sort_by {|word| word.first }.uniq!
|
51
|
+
synonyms
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bronto::Thesaurus do
|
4
|
+
|
5
|
+
context "when a word is entered" do
|
6
|
+
before do
|
7
|
+
@thesaurus = Bronto::Thesaurus.new
|
8
|
+
@response = @thesaurus.lookup("fish")
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when it returns a hash of synonym strings grouped by part of speech" do
|
12
|
+
it "has verb and noun keys" do
|
13
|
+
expect(@response).to have_key :verb
|
14
|
+
expect(@response).to have_key :noun
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has hashes whose keys are :syn" do
|
18
|
+
expect(@response[:verb]).to have_key :syn
|
19
|
+
expect(@response[:noun]).to have_key :syn
|
20
|
+
end
|
21
|
+
|
22
|
+
it "contains arrays of strings" do
|
23
|
+
expect(
|
24
|
+
@response[:verb][:syn].map {|s| s.class}.uniq.first
|
25
|
+
).to(eq(String))
|
26
|
+
expect(
|
27
|
+
@response[:noun][:syn].map {|s| s.class}.uniq.first
|
28
|
+
).to(eq(String))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bronto-gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan deLevie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05
|
11
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wordnet
|
@@ -117,16 +117,17 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
119
|
- ".ruby-version"
|
120
|
+
- ".travis.yml"
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
122
123
|
- README.md
|
123
124
|
- Rakefile
|
124
|
-
- bronto
|
125
|
-
- lib/bronto
|
126
|
-
- lib/bronto
|
127
|
-
- lib/bronto
|
128
|
-
- spec/lookup_spec.rb
|
125
|
+
- bronto.gemspec
|
126
|
+
- lib/bronto.rb
|
127
|
+
- lib/bronto/thesaurus.rb
|
128
|
+
- lib/bronto/version.rb
|
129
129
|
- spec/spec_helper.rb
|
130
|
+
- spec/thesaurus_spec.rb
|
130
131
|
homepage: ''
|
131
132
|
licenses:
|
132
133
|
- Public Domain. See LICENSE.txt
|
@@ -152,5 +153,5 @@ signing_key:
|
|
152
153
|
specification_version: 4
|
153
154
|
summary: Thesaurus gem
|
154
155
|
test_files:
|
155
|
-
- spec/lookup_spec.rb
|
156
156
|
- spec/spec_helper.rb
|
157
|
+
- spec/thesaurus_spec.rb
|
data/lib/bronto-gem/lookup.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'wordnet'
|
2
|
-
require 'wordnet-defaultdb'
|
3
|
-
|
4
|
-
$lex = WordNet::Lexicon.new
|
5
|
-
|
6
|
-
module BrontoGem
|
7
|
-
def self.lookup(word)
|
8
|
-
query = word.downcase
|
9
|
-
synsets = $lex.lookup_synsets(query)
|
10
|
-
|
11
|
-
words = []
|
12
|
-
|
13
|
-
synsets.each do |synset|
|
14
|
-
synset.words.map {|word| words << [word.lemma, synset.part_of_speech.to_sym] unless word.lemma == query}
|
15
|
-
|
16
|
-
synset.hypernyms.each do |hypernym|
|
17
|
-
hypernym.words.map {|word| words << [word.lemma, synset.part_of_speech.to_sym] unless word.lemma == query}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
synonyms = words.sort_by {|word| word.first }.uniq!
|
22
|
-
|
23
|
-
return nil if synonyms.nil? # check out early if nothing is found
|
24
|
-
|
25
|
-
hash = {}
|
26
|
-
|
27
|
-
if synonyms
|
28
|
-
synonyms.each do |synonym|
|
29
|
-
hash[synonym.last] = {syn: [] } unless hash.member?(synonym.last)
|
30
|
-
hash[synonym.last][:syn] << synonym.first
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
hash
|
35
|
-
end
|
36
|
-
end
|
data/lib/bronto-gem/version.rb
DELETED
data/spec/lookup_spec.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe BrontoGem do
|
4
|
-
|
5
|
-
context 'when a word is entered' do
|
6
|
-
before do
|
7
|
-
@response = BrontoGem.lookup("fish")
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns a hash of synoyms grouped by part of speech' do
|
11
|
-
fish_response = {
|
12
|
-
verb: {
|
13
|
-
syn: ["angle", "catch", "grab", "look for", "search", "seek", "take hold of"]
|
14
|
-
},
|
15
|
-
noun: {
|
16
|
-
syn: [
|
17
|
-
"aquatic vertebrate",
|
18
|
-
"food",
|
19
|
-
"individual",
|
20
|
-
"mortal",
|
21
|
-
"person",
|
22
|
-
"pisces",
|
23
|
-
"pisces the fishes",
|
24
|
-
"solid food",
|
25
|
-
"somebody",
|
26
|
-
"someone",
|
27
|
-
"soul"]
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
expect(@response).to eq fish_response
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|