lyracyst 0.0.8 → 0.0.9

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.
@@ -0,0 +1,50 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Define
7
+ # Fetches definitions from Wordnik. Parts include:
8
+ # 'noun,adjective,verb,adverb,interjection,pronoun,
9
+ # preposition,abbreviation,affix,article,auxiliary-verb,
10
+ # conjunction,definite-article,family-name,given-name,
11
+ # idiom,imperative,noun-plural,noun-posessive,
12
+ # past-participle,phrasal-prefix,proper-noun,
13
+ # proper-noun-plural,proper-noun-posessive,suffix,
14
+ # verb-intransitive,verb-transitive'
15
+ #
16
+ # @param search [String] The word or phrase to search for.
17
+ # @param part [String] Comma-separated list of parts of speech.
18
+ # @param params [Hash] The search parameters to use.
19
+ def get_def(search, part, params)
20
+ func, label, result = 'definitions', 'Definition', nil
21
+ if part != nil then params[:part] = part; end
22
+ defi = Lyracyst::Wordnik.new
23
+ result = defi.get_word(search, func, params, result)
24
+ result = MultiJson.load(result)
25
+ if result != nil
26
+ x, y = 0, result.length - 1
27
+ while x <= y
28
+ d = result[x]
29
+ text = d['text']
30
+ part = d['partOfSpeech']
31
+ Lyracyst.label(label)
32
+ print Rainbow("#{part}|").bright
33
+ puts "#{text}|"
34
+ if $fmt != nil
35
+ type = { 'type' => 'definition' }
36
+ part = { 'part' => part }
37
+ text = { 'text' => text}
38
+ $tofile.push type
39
+ $tofile.push part
40
+ $tofile.push text
41
+ end
42
+ x += 1
43
+ end
44
+ else
45
+ puts 'Wordnik returned an empty string.'
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Example
7
+ # Fetches examples from Wordnik.
8
+ #
9
+ # @param search [String] The word or phrase to search for.
10
+ # @param params [Hash] The search parameters to use.
11
+ def get_ex(search, params)
12
+ func, label, result = 'examples', 'Example', nil
13
+ exam = Lyracyst::Wordnik.new
14
+ result = exam.get_word(search, func, params, result)
15
+ result = MultiJson.load(result)
16
+ result = result['examples']
17
+ if result != nil
18
+ x, y = 0, result.length - 1
19
+ while x <= y
20
+ ex = result[x]
21
+ title = ex['title']
22
+ text = ex['text']
23
+ url = ex['url']
24
+ Lyracyst.label(label)
25
+ print Rainbow("#{title}➜").bright
26
+ puts "#{text}➜#{url}➜"
27
+ if $fmt != nil
28
+ ty = { 'type' => 'example' }
29
+ ti = { 'title' => title }
30
+ te = { 'text' => text }
31
+ u = { 'url' => url }
32
+ $tofile.push ty
33
+ $tofile.push ti
34
+ $tofile.push te
35
+ $tofile.push u
36
+ end
37
+ x += 1
38
+ end
39
+ else
40
+ puts 'Wordnik failed to fetch word info.'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Hyphen
7
+ # Fetches hyphenations from Wordnik.
8
+ #
9
+ # @param search [String] The word or phrase to search for.
10
+ # @param params [Hash] The search parameters to use.
11
+ def get_hyph(search, params)
12
+ func, label, result = 'hyphenation', 'Hyphenation', nil
13
+ hyph = Lyracyst::Wordnik.new
14
+ result = hyph.get_word(search, func, params, result)
15
+ result = MultiJson.load(result)
16
+ if result != nil
17
+ x, y, hcont = 0, result.length - 1, []
18
+ Lyracyst.label(label)
19
+ while x <= y
20
+ hy = result[x]
21
+ ht = hy['text']
22
+ if $fmt !=nil
23
+ t = { 'type' => 'hyphenation' }
24
+ $tofile.push t
25
+ end
26
+ if hy['type'] == 'stress'
27
+ stress = 'primary'
28
+ sh = { ht => stress }
29
+ h = { 'syllable' => sh}
30
+ if $fmt != nil
31
+ $tofile.push h
32
+ end
33
+ hcont.push Rainbow(ht).red.bright
34
+ elsif hy['type'] == 'secondary stress'
35
+ stress = 'secondary'
36
+ sh = { ht => stress }
37
+ h = { 'syllable' => sh}
38
+ if $fmt != nil
39
+ $tofile.push h
40
+ end
41
+ hcont.push Rainbow(ht).bright
42
+ else
43
+ if $fmt != nil
44
+ h = { 'syllable' => ht}
45
+ $tofile.push h
46
+ end
47
+ hcont.push ht
48
+ end
49
+ x += 1
50
+ end
51
+ puts hcont.join('-')
52
+ else
53
+ puts 'Wordnik failed to fetch word info.'
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,76 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Origin
7
+ # Fetches etymologies from Wordnik.
8
+ #
9
+ # @param search [String] The word or phrase to search for.
10
+ # @param params [Hash] The search parameters to use.
11
+ def get_et(search, params)
12
+ func, label, result = 'etymologies', 'Etymology', nil
13
+ etymology = Lyracyst::Wordnik.new
14
+ extra = Lyracyst::Wordnik::Origin.new
15
+ result = etymology.get_word(search, func, params, result)
16
+ if result != nil && result != '[]'
17
+ result = MultiJson.load(result)
18
+ a, b, cont = 0, result.length - 1, []
19
+ if $fmt != nil
20
+ type = { 'type' => 'etymology'}
21
+ $tofile.push type
22
+ end
23
+ while a <= b
24
+ xml = result[a]
25
+ xml = MultiXml.parse(xml)
26
+ root = xml['ety']
27
+ content, ets, er = root['__content__'], root['ets'], root['er']
28
+ if $fmt != nil
29
+ root = { 'root' => content }
30
+ $tofile.push root
31
+ end
32
+ Lyracyst.label(label)
33
+ print "#{content}|"
34
+ if ets != nil
35
+ extra.origin_extra(ets)
36
+ else
37
+ puts ''
38
+ end
39
+ if er != nil
40
+ print '|'
41
+ extra.origin_extra(er)
42
+ else
43
+ puts ''
44
+ end
45
+ a += 1
46
+ puts ''
47
+ end
48
+ else
49
+ puts 'Wordnik failed to fetch word info.'
50
+ end
51
+ end
52
+ def origin_extra(obj)
53
+ a, b, container = 0, obj.length - 1, []
54
+ while a <= b
55
+ if b == 0
56
+ content = obj['__content__']
57
+ container.push content
58
+ if $fmt != nil
59
+ node = { 'node' => content }
60
+ $tofile.push node
61
+ end
62
+ else
63
+ content = obj[a]
64
+ container.push content['__content__']
65
+ if $fmt != nil
66
+ node = { 'node' => content}
67
+ $tofile.push node
68
+ end
69
+ end
70
+ a += 1
71
+ end
72
+ print "#{container.join('|')}"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Phrase
7
+ # Fetches bi-gram phrases from Wordnik.
8
+ #
9
+ # @param search [String] The word or phrase to search for.
10
+ # @param params [Hash] The search parameters to use.
11
+ def get_phr(search, params)
12
+ func, label, result = 'phrases', 'Bi-gram phrases', nil
13
+ phr = Lyracyst::Wordnik.new
14
+ result = phr.get_word(search, func, params, result)
15
+ result = MultiJson.load(result)
16
+ if result != nil
17
+ x, y, phcont = 0, result.length - 1, []
18
+ Lyracyst.label(label)
19
+ if $fmt != nil
20
+ type = { 'type' => 'phrase' }
21
+ $tofile.push type
22
+ end
23
+ while x <= y
24
+ ph = result[x]
25
+ one = ph['gram1']
26
+ two = ph['gram2']
27
+ if $fmt != nil
28
+ g1 = { 'gram1' => one }
29
+ g2 = { 'gram2' => two }
30
+ $tofile.push g1
31
+ $tofile.push g2
32
+ end
33
+ if one == search
34
+ item = "#{Rainbow(one).bright}➜#{two}"
35
+ else
36
+ item = "#{one}➜#{Rainbow(two).bright}"
37
+ end
38
+ phcont.push item
39
+ x += 1
40
+ end
41
+ puts "#{phcont.join('➜')}"
42
+ else
43
+ puts 'Wordnik failed to fetch word info.'
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Pronounce
7
+ # Fetches pronunciations from Wordnik. Types include ['ahd'
8
+ # 'arpabet', 'gcide-diacritical', 'IPA']
9
+ #
10
+ # @param search [String] The word or phrase to search for.
11
+ # @param params [Hash] The search parameters to use.
12
+ # @param ptype [String] Pronunciation type.
13
+ def get_pro(search, params, ptype)
14
+ func, label, result = 'pronunciations', 'Pronunciation', nil
15
+ if ptype != nil then params[:tformat] = ptype; end
16
+ pron = Lyracyst::Wordnik.new
17
+ result = pron.get_word(search, func, params, result)
18
+ result = MultiJson.load(result)
19
+ if result != nil
20
+ x, y = 0, result.length - 1
21
+ if $fmt != nil
22
+ type = { 'type' => 'pronunciation' }
23
+ $tofile.push type
24
+ end
25
+ while x <= y
26
+ pro = result[x]
27
+ rawtype = pro['rawType']
28
+ raw = pro['raw']
29
+ Lyracyst.label(label)
30
+ puts "#{raw}|#{rawtype}|"
31
+ if $fmt != nil
32
+ pronunciation = { 'pronunciation' => raw }
33
+ ptype = { 'type' => rawType }
34
+ $tofile.push pronunciation
35
+ $tofile.push ptype
36
+ end
37
+ x += 1
38
+ end
39
+ else
40
+ puts 'Wordnik failed to fetch word info.'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ class Wordnik
6
+ class Relate
7
+ # Fetches related words from Wordnik. Types include ['synonym',
8
+ # 'antonym', 'variant', 'equivalent', 'cross-reference',
9
+ # 'related-word', 'rhyme', 'form', 'etymologically-related-term',
10
+ # 'hypernym', 'hyponym', 'inflected-form', 'primary', 'same-context',
11
+ # 'verb-form', 'verb-stem']
12
+ #
13
+ # @param search [String] The word or phrase to search for.
14
+ # @param params [Hash] The search parameters to use.
15
+ # @param reltypes [String] Relationship type.
16
+ def get_rel(search, params, reltypes)
17
+ func, label, result = 'relatedWords', 'Related words', nil
18
+ if reltypes != nil then params[:reltypes] = reltypes; end
19
+ rel = Lyracyst::Wordnik.new
20
+ result = rel.get_word(search, func, params, result)
21
+ result = MultiJson.load(result)
22
+ if result != nil
23
+ x, y = 0, result.length - 1
24
+ if $fmt != nil
25
+ type = { 'type' => 'related words' }
26
+ $tofile.push type
27
+ end
28
+ while x <= y
29
+ re = result[x]
30
+ words, type = re['words'], re['relationshipType']
31
+ Lyracyst.label(label)
32
+ print Rainbow("#{type}|").bright
33
+ puts "#{words.join('|')}"
34
+ if $fmt != nil
35
+ words = { 'words' => words }
36
+ rtype = { 'relationship type' => type }
37
+ $tofile.push words
38
+ $tofile.push rtype
39
+ end
40
+ x += 1
41
+ end
42
+ else
43
+ puts 'Wordnik failed to fetch word info.'
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ %w{httpi multi_json multi_xml rainbow}.map {|lib| require lib}
3
+
4
+ module Lyracyst
5
+ # Wordnik.com's service provides definitions, examples,
6
+ # related words, pronunciations, hyphenation, phrases,
7
+ # and etymologies.
8
+ class Wordnik
9
+ # Fetches dynamically generated URL. Functions are definitions,
10
+ # examples, relatedWords, pronunciations, hyphenation, phrases,
11
+ # and etymologies.
12
+ #
13
+ # @param search [String] The word or phrase to search for.
14
+ # @param func [String] The search function to use.
15
+ # @param params [Hash] The search parameters to use.
16
+ # @param result [String] The search response.
17
+ def get_word(search, func, params, result)
18
+ prefix = 'http://api.wordnik.com:80/v4/word.json/'
19
+ word, pcont = "#{prefix}#{search}/#{func}?", []
20
+ params.map { |k,v|
21
+ if k == :canon then pcont.push "useCanonical=#{v}&"; end
22
+ if k == :incdups then pcont.push "includeDuplicates=#{v}&"; end
23
+ if k == :increl then pcont.push "includeRelated=#{v}&"; end
24
+ if k == :inctags then pcont.push "includeTags=#{v}&"; end
25
+ if k == :limit then pcont.push "limit=#{v}&"; end
26
+ if k == :part then pcont.push "partOfSpeech=#{v}&"; end
27
+ if k == :rellimit then pcont.push "limitPerRelationshipType=#{v}&"; end
28
+ if k == :reltypes then pcont.push "relationshipTypes=#{v}&"; end
29
+ if k == :skip then pcont.push "skip=#{v}&"; end
30
+ if k == :source then pcont.push "sourceDictionary=#{v}&"; end
31
+ if k == :defdict then pcont.push "sourceDictionaries=#{v}&"; end
32
+ if k == :tformat then pcont.push "typeFormat=#{v}&"; end
33
+ if k == :wlmi then pcont.push "wlmi=#{v}&"; end
34
+ }
35
+ apikey = ENV['WORDNIK']
36
+ pcont.push "api_key=#{apikey}"
37
+ url = "#{word}#{pcont.join}"
38
+ request = HTTPI::Request.new(url)
39
+ getter = HTTPI.get(request)
40
+ result = getter.body
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyracyst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Prentice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.6'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: gli
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,20 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: xml-fu
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: aruba
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -109,33 +109,33 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.5'
111
111
  - !ruby/object:Gem::Dependency
112
- name: coveralls
112
+ name: bundler
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0.7'
117
+ version: '1.6'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0.7'
124
+ version: '1.6'
125
125
  - !ruby/object:Gem::Dependency
126
- name: cucumber
126
+ name: coveralls
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.3'
131
+ version: '0.7'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.3'
138
+ version: '0.7'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '10.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: spinach
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.8'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.8'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: yard
155
169
  requirement: !ruby/object:Gem::Requirement
@@ -164,8 +178,7 @@ dependencies:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '0.8'
167
- description: Search Wordnik, thesaurus.altervista.org, and Rhymebrain from the command
168
- line.
181
+ description: Search Wordnik and Rhymebrain from the command line.
169
182
  email: weirdpercent@gmail.com
170
183
  executables:
171
184
  - lyracyst
@@ -173,12 +186,24 @@ extensions: []
173
186
  extra_rdoc_files: []
174
187
  files:
175
188
  - CHANGELOG.md
176
- - LICENSE.md
177
189
  - bin/lyracyst
178
190
  - lib/lyracyst.rb
179
191
  - lib/lyracyst/rhymebrain.rb
192
+ - lib/lyracyst/rhymebrain/combine.rb
193
+ - lib/lyracyst/rhymebrain/info.rb
194
+ - lib/lyracyst/rhymebrain/rhyme.rb
195
+ - lib/lyracyst/rhymebrain/word.rb
196
+ - lib/lyracyst/urban.rb
180
197
  - lib/lyracyst/version.rb
181
198
  - lib/lyracyst/wordnik.rb
199
+ - lib/lyracyst/wordnik/define.rb
200
+ - lib/lyracyst/wordnik/example.rb
201
+ - lib/lyracyst/wordnik/hyphen.rb
202
+ - lib/lyracyst/wordnik/origin.rb
203
+ - lib/lyracyst/wordnik/phrase.rb
204
+ - lib/lyracyst/wordnik/pronounce.rb
205
+ - lib/lyracyst/wordnik/relate.rb
206
+ - lib/lyracyst/wordnik/word.rb
182
207
  homepage: http://github.com/weirdpercent/lyracyst
183
208
  licenses:
184
209
  - MIT