related_word 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -2
- data/lib/related_word.rb +1 -3
- data/lib/related_word/configure.rb +2 -2
- data/lib/related_word/formatter.rb +6 -0
- data/lib/related_word/formatter/base_formatter.rb +11 -0
- data/lib/related_word/formatter/semantic_formatter.rb +13 -0
- data/lib/related_word/service.rb +2 -6
- data/lib/related_word/service/semantic_service.rb +14 -5
- data/lib/related_word/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b36f44911da5f28b4d3af3b2f3fef0b140efc8
|
4
|
+
data.tar.gz: a4f4c959a59b2dc1b2be9326d448768ff5522392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4efcdbdcfcb49a73f50fdb687e31841cfc64d1b89c35eee492011c22248806add2a0cc46c2c229950f2348da3f947ba9a84047a515b02cf65626a6cdd112bd45
|
7
|
+
data.tar.gz: 7a56d9dc4998156d113e4350fb2861b18c29177f878132300714b10540a6c4117ca9cdee2489e8e353cdb2c389b33fe9433312d6f40420dbc2217925efbabadd
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
Get the list of related words of a specific word.
|
4
4
|
|
5
|
+
## Versions
|
6
|
+
|
7
|
+
For installations and instructions of older versions, please follow below links:
|
8
|
+
* [0.2](https://github.com/lmduc/related_word/tree/v0.2)
|
9
|
+
|
5
10
|
## Installation
|
6
11
|
|
7
12
|
Add this line to your application's Gemfile:
|
@@ -18,14 +23,23 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
$ gem install related_word
|
20
25
|
|
26
|
+
## Config
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
RelatedWord.config do |c|
|
30
|
+
c.timeout = 200 # The timeout for each request to the service
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
21
34
|
## Usage
|
22
35
|
|
23
36
|
#### RelatedWord.find
|
24
37
|
```ruby
|
25
38
|
require 'related_word'
|
26
39
|
|
27
|
-
word = '
|
40
|
+
word = 'student'
|
28
41
|
RelatedWord.new.find(word)
|
42
|
+
> #=> [{:word=>"individualized", :score=>"0.258894"}, {:word=>"NUS", :score=>"0.206925"}, {:word=>"extracurricular", :score=>"0.206289"}, {:word=>"Yearbook", :score=>"0.197864"}, ...]
|
29
43
|
```
|
30
44
|
|
31
45
|
## Contributing
|
@@ -36,4 +50,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
36
50
|
## License
|
37
51
|
|
38
52
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
-
|
data/lib/related_word.rb
CHANGED
@@ -4,10 +4,10 @@ class RelatedWord
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Configure
|
7
|
-
# The service used for find related words
|
7
|
+
# The default service used for find related words
|
8
8
|
@service = :semantic
|
9
9
|
|
10
|
-
# The timeout of each request to the service
|
10
|
+
# The default timeout of each request to the service
|
11
11
|
@timeout = 2000
|
12
12
|
|
13
13
|
class << self
|
data/lib/related_word/service.rb
CHANGED
@@ -3,16 +3,12 @@ require 'related_word/service/semantic_service'
|
|
3
3
|
class RelatedWord
|
4
4
|
class Service
|
5
5
|
class << self
|
6
|
-
def instance
|
7
|
-
instance_class.new
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
6
|
def instance_class
|
13
7
|
Object.const_get("RelatedWord::Service::#{class_name}")
|
14
8
|
end
|
15
9
|
|
10
|
+
private
|
11
|
+
|
16
12
|
def class_name
|
17
13
|
"#{service_name}Service"
|
18
14
|
end
|
@@ -3,22 +3,31 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
require 'timeout'
|
5
5
|
|
6
|
+
require 'related_word/formatter'
|
7
|
+
|
6
8
|
class RelatedWord
|
7
9
|
class Service
|
8
10
|
class SemanticService
|
9
11
|
LINK = "http://semantic-link.com/related.php?word="
|
10
12
|
|
11
|
-
|
13
|
+
attr_reader :word
|
14
|
+
|
15
|
+
def initialize(word)
|
16
|
+
@word = word
|
17
|
+
end
|
18
|
+
|
19
|
+
def find
|
12
20
|
Timeout::timeout(Configure.timeout) do
|
13
|
-
resp
|
14
|
-
JSON.parse(resp.body)
|
21
|
+
resp = Net::HTTP.get_response(word_uri)
|
22
|
+
json_resp = JSON.parse(resp.body)
|
23
|
+
Formatter::SemanticFormatter.new(json_resp).format
|
15
24
|
end
|
16
25
|
end
|
17
26
|
|
18
27
|
private
|
19
28
|
|
20
|
-
def
|
21
|
-
URI.parse("#{LINK}#{word}")
|
29
|
+
def word_uri
|
30
|
+
@word_uri ||= URI.parse("#{LINK}#{word}")
|
22
31
|
end
|
23
32
|
end
|
24
33
|
end
|
data/lib/related_word/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: related_word
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- MatBi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,9 @@ files:
|
|
84
84
|
- bin/setup
|
85
85
|
- lib/related_word.rb
|
86
86
|
- lib/related_word/configure.rb
|
87
|
+
- lib/related_word/formatter.rb
|
88
|
+
- lib/related_word/formatter/base_formatter.rb
|
89
|
+
- lib/related_word/formatter/semantic_formatter.rb
|
87
90
|
- lib/related_word/service.rb
|
88
91
|
- lib/related_word/service/semantic_service.rb
|
89
92
|
- lib/related_word/version.rb
|