wordfor 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,24 +1,72 @@
1
1
  # Wordfor
2
2
 
3
- TODO: Write a gem description
3
+ A simple command line thesaurus based on the
4
+ [WordNet](http://wordnet.princeton.edu/) database. It can help you get other
5
+ **word**s **for** things, which can be particularly useful if your dayjob
6
+ requires frequent naming of things.
7
+
8
+ To "bulk up" the results, I'm using a traversal of the input word's [hyponyms
9
+ and hypernyms](http://en.wikipedia.org/wiki/Hyponymy). Sometimes these look a
10
+ lot like synonyms, sometimes they get a little weird.
4
11
 
5
12
  ## Installation
6
13
 
7
- Add this line to your application's Gemfile:
14
+ Install the gem by running:
15
+
16
+ $ gem install wordfor
8
17
 
9
- gem 'wordfor'
18
+ This gem requires Ruby 1.9.2 or higher.
10
19
 
11
- And then execute:
20
+ ## Usage
12
21
 
13
- $ bundle
22
+ the command:
14
23
 
15
- Or install it yourself as:
24
+ $ wordfor list
16
25
 
17
- $ gem install wordfor
26
+ prints:
18
27
 
19
- ## Usage
28
+ noun:
29
+ synonyms:
30
+ inclination, lean, leaning, tilt, listing
31
+ hyponyms:
32
+ agenda, agendum, order of business, order of the day, order book, order paper,
33
+ a-list, bibliography, bill, bill of entry, bill of goods, bill of fare,
34
+ card, carte, carte du jour, menu, a la carte, prix fixe, table d'hote,
35
+ playbill, black book, blacklist, shitlist, calendar, docket, calorie chart,
36
+ canon, catalog, catalogue, discography, library catalog, library catalogue,
37
+ card catalog, card catalogue, parts catalog, parts catalogue, seed catalog,
38
+ seed catalogue, character set, alphabet, armenian, armenian alphabet, latin
39
+ alphabet, roman alphabet, hebraic alphabet, hebrew alphabet, hebrew script,
40
+ greek alphabet, cyrillic, cyrillic alphabet, arabic alphabet, phonetic
41
+ alphabet, sound alphabet, visible speech, finger alphabet, manual alphabet,
42
+ alphanumeric characters, alphanumerics, checklist, class list, honours list,
43
+ codex, contents, table of contents, corrigenda, credits, criminal record,
44
+ record, directory, subdirectory, distribution list, enumeration, numbering, faq,
45
+ free list, grocery list, shopping list, hit list, hit parade, index,
46
+ concordance, key, key word, key, inventory, stock list, parts inventory,
47
+ mailing list, flag, masthead, computer menu, menu, drop-down menu, cascading
48
+ menu, hierarchical menu, submenu, necrology, play list, playlist, portfolio,
49
+ posting, price list, push-down list, push-down stack, stack, queue, push-down
50
+ queue, roll, roster, batting order, card, lineup, death-roll, muster roll,
51
+ church roll, rota, waiting list, schedule, network programming, timetable,
52
+ timetable, shopping list, grocery list, short list, shortlist, sick list,
53
+ slate, ticket, standing, wish list
54
+ hypernyms:
55
+ position, spatial relation, relation, abstract entity, abstraction, entity,
56
+ database, info, information, content, message, subject matter, substance,
57
+ communication
58
+ verb:
59
+ synonyms:
60
+ name, number, heel, lean
61
+ hyponyms:
62
+ itemise, itemize, inventory, stock-take, take stock, empanel, impanel, index,
63
+ cross-index, blacklist, post
64
+ hypernyms:
65
+ enumerate, itemise, itemize, recite, identify, name, denote, refer, intend, mean,
66
+ signify, stand for, angle, lean, slant, tilt, tip, bend, flex, change form,
67
+ change shape, deform, change, move, register, enter, put down, record,
68
+ preserve, save, hold on, keep, have, have got, hold
20
69
 
21
- TODO: Write usage instructions here
22
70
 
23
71
  ## Contributing
24
72
 
@@ -19,8 +19,8 @@ use this program.
19
19
 
20
20
  EOS
21
21
 
22
- opts.on('-v', '--verbose', 'more noisy') do |v|
23
- options[:verbose] = v
22
+ opts.on('-v', '--version', 'show version and quit') do |v|
23
+ options[:version] = v
24
24
  end
25
25
 
26
26
  opts.on('-d', '--debug', 'debugging output') do |d|
@@ -28,6 +28,11 @@ EOS
28
28
  end
29
29
  end.parse!
30
30
 
31
+ if options[:version]
32
+ puts "wordfor #{ Wordfor::VERSION } #{ Wordfor::VERSION_DATE }"
33
+ exit 0
34
+ end
35
+
31
36
  word = ARGV[0]
32
37
 
33
38
  if word.nil?
@@ -37,33 +42,28 @@ else
37
42
  word = word.strip
38
43
  end
39
44
 
40
- if Wordfor::Setup.run_setup?
41
- Wordfor::Setup.new($stdin, $stdout).run
42
- end
43
-
44
- result = Wordfor::Lookup.new( Wordfor::Configuration.api_key ).lookup(word)
45
+ result = Wordfor::Lookup.new.lookup(word)
45
46
 
46
47
  if options[:debug]
47
48
  puts result.inspect
48
49
  puts result.keys.inspect
49
50
  end
50
51
 
52
+ def display_word_relationship(words, relationship)
53
+ if words[relationship]
54
+ word_list = words[relationship].join(", ")
55
+ puts " #{ relationship }:"
56
+ puts ' ' + Wordfor::Plaintext.wrapped_text(word_list, :indent => ' ')
57
+ end
58
+ end
59
+
51
60
  result.each_pair do |(part_of_speech, words)|
52
61
  if words
53
62
  puts "#{ part_of_speech }:"
54
63
 
55
- if words['syn']
56
- word_list = words['syn'].join(", ")
57
-
58
- puts " synonyms:"
59
- puts ' ' + Wordfor::Plaintext.wrapped_text(word_list, :indent => ' ')
60
- end
61
-
62
- if words['ant']
63
- word_list = words['ant'].join(", ")
64
-
65
- puts " antonyms:"
66
- puts ' ' + Wordfor::Plaintext.wrapped_text(word_list, :indent => ' ')
67
- end
64
+ display_word_relationship words, :synonyms
65
+ display_word_relationship words, :hyponyms
66
+ display_word_relationship words, :hypernyms
67
+ display_word_relationship words, :antonyms
68
68
  end
69
69
  end
@@ -1,11 +1,8 @@
1
- require 'httparty'
2
-
3
1
  require 'wordfor/core_ext/array'
4
2
  require 'wordfor/core_ext/dir'
5
3
 
6
4
  require 'wordfor/version'
7
5
  require 'wordfor/configuration'
8
- require 'wordfor/setup'
9
6
  require 'wordfor/plaintext'
10
7
  require 'wordfor/lookup'
11
8
 
@@ -1,17 +1,73 @@
1
- require 'httparty'
1
+ require 'wordnet'
2
2
 
3
- # http://words.bighugelabs.com/api/2/API_KEY/word/json
3
+ # WordNet!
4
4
  module Wordfor
5
5
  class Lookup
6
- include HTTParty
7
- base_uri 'words.bighugelabs.com'
6
+ def initialize
7
+ @lexicon = WordNet::Lexicon.new
8
8
 
9
- def initialize(api_key)
10
- @api_key = api_key
11
9
  end
12
10
 
11
+ # Based on example code:
12
+ #
13
+ # lex = WordNet::Lexicon.new
14
+ # lex.lookup_synsets('time').map {|o|
15
+ # o.traverse(:hyponyms).with_index.map {|ss, i|
16
+ # [ss.part_of_speech.to_sym, ss.words.map(&:lemma)]
17
+ # }
18
+ # }.reject {|l| l.size == 0}
19
+
13
20
  def lookup(word)
14
- self.class.get("/api/2/#{ @api_key }/#{ word }/json")
21
+ @input_word = word
22
+ @visited = {}
23
+ @pos_map = {}
24
+
25
+ origins = @lexicon.lookup_synsets word
26
+
27
+ origins.each {|o|
28
+ break if visited?(o)
29
+ add_synset_to_map o, :synonyms
30
+
31
+ o.traverse(:hyponyms).with_index.each {|ss|
32
+ break if visited?(ss)
33
+ add_synset_to_map ss, :hyponyms
34
+ }
35
+
36
+ o.traverse(:hypernyms).with_index.each {|ss|
37
+ break if visited?(ss)
38
+ add_synset_to_map ss, :hypernyms
39
+ }
40
+
41
+ o.traverse(:antonyms).with_index.each {|ss|
42
+ break if visited?(ss)
43
+ add_synset_to_map ss, :antonyms
44
+ }
45
+ }
46
+
47
+ @pos_map
48
+ end
49
+
50
+ private
51
+
52
+ def visited? ss
53
+ if @visited[ss.synsetid]
54
+ true
55
+ else
56
+ @visited[ss.synsetid] = ss
57
+ false
58
+ end
59
+ end
60
+
61
+ def filter list, word
62
+ list.reject {|w| w == word}
63
+ end
64
+
65
+ def add_synset_to_map synset, relation
66
+ pos = synset.part_of_speech.to_sym
67
+
68
+ @pos_map[pos] ||= {}
69
+ @pos_map[pos][relation] ||= []
70
+ @pos_map[pos][relation].concat filter(synset.words.map(&:lemma), @input_word)
15
71
  end
16
72
  end
17
73
  end
@@ -1,3 +1,4 @@
1
1
  module Wordfor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
+ VERSION_DATE = "2013-01-23"
3
4
  end
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
19
 
20
- gem.add_dependency('httparty', '~> 0.9.0')
21
- gem.add_dependency('json', '~> 1.7.5')
20
+ gem.add_dependency 'wordnet'
21
+ gem.add_dependency 'wordnet-defaultdb'
22
+
23
+ gem.required_ruby_version = '>= 1.9.2'
22
24
  end
metadata CHANGED
@@ -1,65 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wordfor
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Adam Bachman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-01-10 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: httparty
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: wordnet
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 59
30
- segments:
31
- - 0
32
- - 9
33
- - 0
34
- version: 0.9.0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: json
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: wordnet-defaultdb
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 1
46
- segments:
47
- - 1
48
- - 7
49
- - 5
50
- version: 1.7.5
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
51
38
  type: :runtime
52
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
53
46
  description: Find synonyms and antonyms from the command line.
54
- email:
47
+ email:
55
48
  - adam.bachman@gmail.com
56
- executables:
49
+ executables:
57
50
  - wordfor
58
51
  extensions: []
59
-
60
52
  extra_rdoc_files: []
61
-
62
- files:
53
+ files:
63
54
  - .gitignore
64
55
  - Gemfile
65
56
  - LICENSE.txt
@@ -72,42 +63,30 @@ files:
72
63
  - lib/wordfor/core_ext/dir.rb
73
64
  - lib/wordfor/lookup.rb
74
65
  - lib/wordfor/plaintext.rb
75
- - lib/wordfor/setup.rb
76
66
  - lib/wordfor/version.rb
77
67
  - wordfor.gemspec
78
- has_rdoc: true
79
68
  homepage: http://github.com/abachman/wordfor
80
69
  licenses: []
81
-
82
70
  post_install_message:
83
71
  rdoc_options: []
84
-
85
- require_paths:
72
+ require_paths:
86
73
  - lib
87
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
88
75
  none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: 1.9.2
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
81
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
105
86
  requirements: []
106
-
107
87
  rubyforge_project:
108
- rubygems_version: 1.6.2
88
+ rubygems_version: 1.8.24
109
89
  signing_key:
110
90
  specification_version: 3
111
91
  summary: A thesaurus for your command line.
112
92
  test_files: []
113
-
@@ -1,23 +0,0 @@
1
- module Wordfor
2
- class Setup
3
- def self.run_setup?
4
- !File.exists?(Wordfor::Configuration.config_file)
5
- end
6
-
7
- def initialize(stdin, stdout)
8
- @stdin = stdin
9
- @stdout = stdout
10
- @settings = {}
11
- end
12
-
13
- def run
14
- File.open(Wordfor::Configuration.config_file, "w") do |file|
15
- @stdout.puts "~/.wordfor.yml not found. Running setup"
16
- @stdout.puts "http://words.bighugelabs.com/ API key?"
17
- @settings["api_key"] = @stdin.gets.chomp
18
- file.write @settings.to_yaml
19
- end
20
- end
21
- end
22
- end
23
-