datamuse 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/datamuse.gemspec +27 -0
- data/lib/datamuse.rb +30 -0
- data/lib/datamuse/version.rb +3 -0
- data/lib/word.rb +11 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18df0fdfc4137639d4831f525b43935cfd187dac
|
4
|
+
data.tar.gz: 01828df0605176d3094bf194d11183856b4b6316
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00f006963c330974a0d792ed2c7ede7e79020691eeec53b9478e2d4b8363211ed36fa80788acd37785f0be3a3b299e74010276207c2bc0933761ea101f61c737
|
7
|
+
data.tar.gz: 6195ba319bbf5322205ccdb9d37305974678438b02b83df309303b756e4e3a86c5ca473132dd3255fb934bb123555dfbf138cc5e381adba533452aef3780cad0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Datamuse
|
2
|
+
|
3
|
+
Find rhyming words using the [Datamuse api](http://www.datamuse.com/api/).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'datamuse'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install datamuse
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```
|
25
|
+
client = Datamuse.new(rhymes_with: "dog", max: 10)
|
26
|
+
|
27
|
+
client.get_rhymes
|
28
|
+
=> [ #<Word:0x007ffcd4ad0308 @word="demagogue", @score=1168, @syllable_count=3>,
|
29
|
+
#<Word:0x007ffcd4ad02e0 @word="frog", @score=758, @syllable_count=1>,
|
30
|
+
#<Word:0x007ffcd4ad02b8 @word="dialogue", @score=684, @syllable_count=3>,
|
31
|
+
#<Word:0x007ffcd4ad0268 @word="log", @score=642, @syllable_count=1>,
|
32
|
+
...SNIP
|
33
|
+
]
|
34
|
+
|
35
|
+
client.get_rhymes.map(&:word)
|
36
|
+
=> ["demagogue", "frog", "dialogue", "log", "analog", "hog", "agog", "epilogue", "bog", "blog"]
|
37
|
+
|
38
|
+
client = Datamuse.new(rhymes_with: "dog", related_to: "animals", max: 10)
|
39
|
+
|
40
|
+
client.get_rhymes.map(&:word)
|
41
|
+
=> ["frog", "hedgehog"]
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nodanaonlyzuul/datamuse.
|
53
|
+
|
54
|
+
## But Also
|
55
|
+
|
56
|
+
I heard you rushed and rushed, and attacked
|
57
|
+
|
58
|
+
Then they rebuked then you had to smack
|
59
|
+
|
60
|
+
Causing rambunction throughout the sphere
|
61
|
+
|
62
|
+
Raise the levels of the boom inside the ear
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "datamuse"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/datamuse.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datamuse/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datamuse"
|
8
|
+
spec.version = Datamuse::VERSION
|
9
|
+
spec.authors = ["nodanaonlyzuul"]
|
10
|
+
spec.email = ["beholdthepanda@gmail.com"]
|
11
|
+
spec.licenses = ['MIT']
|
12
|
+
spec.summary = %q{Ruby Library for Datamuse's API}
|
13
|
+
spec.description = %q{Ruby Library for Datamuse's API (http://www.datamuse.com/api/) developed by me, not datamuse.}
|
14
|
+
spec.homepage = "https://github.com/nodanaonlyzuul/datamuse"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'http', '~> 2.0'
|
22
|
+
spec.add_dependency 'addressable', '~> 2.4'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
27
|
+
end
|
data/lib/datamuse.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'datamuse/version'
|
2
|
+
require 'word'
|
3
|
+
require 'http'
|
4
|
+
require 'json'
|
5
|
+
require 'addressable/uri'
|
6
|
+
|
7
|
+
class Datamuse
|
8
|
+
attr_reader :results
|
9
|
+
|
10
|
+
# Options:
|
11
|
+
# :rhymes_with = A string
|
12
|
+
# :max = Maximum results
|
13
|
+
def initialize(options = {})
|
14
|
+
@rhymes_with = options[:rhymes_with]
|
15
|
+
@relates_to = options[:related_to]
|
16
|
+
@max = (options[:max] || "100").to_s
|
17
|
+
@results = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_rhymes
|
21
|
+
params = {"rel_rhy" => @rhymes_with, "ml" => @relates_to, "max" => @max}
|
22
|
+
params.delete_if{|k,v| v.nil? || v.gsub(" ", "").empty? }
|
23
|
+
|
24
|
+
uri = Addressable::URI.new
|
25
|
+
uri.query_values = params
|
26
|
+
|
27
|
+
response = JSON.parse(HTTP.get("https://api.datamuse.com/words?#{uri.query}").to_s)
|
28
|
+
@results = response.map{ |hash| Word.new(hash) }
|
29
|
+
end
|
30
|
+
end
|
data/lib/word.rb
ADDED
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datamuse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nodanaonlyzuul
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
83
|
+
description: Ruby Library for Datamuse's API (http://www.datamuse.com/api/) developed
|
84
|
+
by me, not datamuse.
|
85
|
+
email:
|
86
|
+
- beholdthepanda@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- datamuse.gemspec
|
98
|
+
- lib/datamuse.rb
|
99
|
+
- lib/datamuse/version.rb
|
100
|
+
- lib/word.rb
|
101
|
+
homepage: https://github.com/nodanaonlyzuul/datamuse
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.5.1
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Ruby Library for Datamuse's API
|
125
|
+
test_files: []
|