related_word 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -2
- data/lib/related_word.rb +13 -1
- data/lib/related_word/service.rb +6 -6
- data/lib/related_word/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f866c483493b6048157a084a7293a5335b17ce
|
4
|
+
data.tar.gz: a9607e7fbf9ecf3eddd64cfd868479b525376c60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 805bd9e7b7b5d11c37f7fa51c339899a90574763ca18933109df244e8d12f989d181ae48df7ccc67d773a8ef4c7499ef2a985fe28723b8b53766410ab1803703
|
7
|
+
data.tar.gz: 4a7c34f6ba9d36ec51169228ff0b28d8966531103a47726ea704bda57008caa3a8e4ca4b33e437fa196c506a20a7057f4c9dea537bf086d963aac47786b029ce
|
data/README.md
CHANGED
@@ -25,9 +25,18 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Config
|
27
27
|
|
28
|
+
The code for config below is optional. For Rails, you can put those code in the file `config/initializers/related_word.rb`. For the pure Ruby, you can run those code whenever you want to set the config for the gem.
|
29
|
+
|
28
30
|
```ruby
|
29
31
|
RelatedWord.config do |c|
|
30
|
-
|
32
|
+
# Set the service serving the related word
|
33
|
+
# The services is one of [:onelook, :semantic]
|
34
|
+
# The default service is :semantic
|
35
|
+
c.service = :onelook
|
36
|
+
|
37
|
+
# The timeout for each request to the service
|
38
|
+
# The default timeout is 2000
|
39
|
+
c.timeout = 2000
|
31
40
|
end
|
32
41
|
```
|
33
42
|
|
@@ -38,8 +47,15 @@ end
|
|
38
47
|
require 'related_word'
|
39
48
|
|
40
49
|
word = 'student'
|
41
|
-
|
50
|
+
|
51
|
+
r = RelatedWord.new # The default service is :semantic
|
52
|
+
r.find(word)
|
42
53
|
#=> [{:word=>"individualized", :score=>"0.258894"}, {:word=>"NUS", :score=>"0.206925"}, {:word=>"extracurricular", :score=>"0.206289"}, {:word=>"Yearbook", :score=>"0.197864"}, ...]
|
54
|
+
|
55
|
+
|
56
|
+
r = RelatedWord.new(:onelook) # Use the service :onelook
|
57
|
+
r.find(word)
|
58
|
+
#=> [{:word=>"academy", :score=>0}, {:word=>"grade", :score=>0}, {:word=>"seminary", :score=>0}, {:word=>"college", :score=>0}, {:word=>"graduate", :score=>0}, ...]
|
43
59
|
```
|
44
60
|
|
45
61
|
## Contributing
|
data/lib/related_word.rb
CHANGED
@@ -2,7 +2,19 @@ require 'related_word/service'
|
|
2
2
|
require 'related_word/configure'
|
3
3
|
|
4
4
|
class RelatedWord
|
5
|
+
attr_reader :service
|
6
|
+
|
7
|
+
def initialize(service = nil)
|
8
|
+
@service = service
|
9
|
+
end
|
10
|
+
|
5
11
|
def find(word)
|
6
|
-
|
12
|
+
service_class.new(word).find
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def service_class
|
18
|
+
@service_class ||= Service.instance_class(service)
|
7
19
|
end
|
8
20
|
end
|
data/lib/related_word/service.rb
CHANGED
@@ -4,18 +4,18 @@ require 'related_word/service/onelook_service'
|
|
4
4
|
class RelatedWord
|
5
5
|
class Service
|
6
6
|
class << self
|
7
|
-
def instance_class
|
8
|
-
Object.const_get("RelatedWord::Service::#{class_name}")
|
7
|
+
def instance_class(service)
|
8
|
+
Object.const_get("RelatedWord::Service::#{class_name(service)}")
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def class_name
|
14
|
-
"#{service_name}Service"
|
13
|
+
def class_name(service)
|
14
|
+
"#{service_name(service || Configure.service)}Service"
|
15
15
|
end
|
16
16
|
|
17
|
-
def service_name
|
18
|
-
|
17
|
+
def service_name(service)
|
18
|
+
service.to_s.split('_').map(&:capitalize).join
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/related_word/version.rb
CHANGED