lateral_recommender 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 651c7824ece60aa76af16f0db48e5a91969debba
4
- data.tar.gz: 50232352c637633cd16e18dc3838b8e649949d25
3
+ metadata.gz: 30f817bfa2c49f5b662223f53679499fef6f4343
4
+ data.tar.gz: 4882d70fdf91115eb50ba45dc766e781853f2dac
5
5
  SHA512:
6
- metadata.gz: d8b5a35a8c26b2fc30ed22173f6361755f23790ad27cd4dbe0cc37d9f5e44ac87b7821f78aafd28173d9449d33b30650b1721bc526cfa7d22d479aaf93b745ad
7
- data.tar.gz: fb5f55f3a930690ee9ca0937c45cc0f27ce1d918d25f01cea3c87c1c0ea5d9c7b6ff443a38bc19d8aae8f13c415a3f392b1b9845f25ad4452234da49d9a0ee4a
6
+ metadata.gz: eaa4b721f15177afae07bd0e651b551f97e55766b25cc5a315ac9082897298d58e83a1d2ff6d952517e18c3a68350670146e37da85035e93d43e808d0e65387b
7
+ data.tar.gz: 2734b5bd4b4e992d2ca9dba15d83e92ee8ce7e8362b71a7ea7730d83ef88eaba5fa7a70aa5848506fbd792eb720476a9ea939be9de59a021d9d22704117b60eb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format d --fail-fast --tty
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - 2.1.1
7
+ - 2.1.2
8
+ - 2.1.3
9
+ - 2.1.4
10
+ - 2.1.5
11
+ - 2.2.0
12
+ - jruby-19mode
13
+ env:
14
+ global:
15
+ - secure: Ri31ozxBLZ9/lzvejfgdtM9LVFdB7kKITRwCSZ9KvSKocy+msPUxND9t8G9cqr6fKU0yzSrYcGdBYP8S3SXOUI+a9Ev5UeQPU8lcZWIg9Bqe4RaIif/anKeCyamoCunReHQ9sxziVSMfg+yn0yoNS8epUA9BbBpqZDeeVMSW9qY=
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # LateralRecommender
2
2
 
3
+ [![Build Status](https://travis-ci.org/lateral/recommender-gem.svg?branch=master)](https://travis-ci.org/lateral/recommender-gem)
4
+
3
5
  This is a Ruby wrapper around the [Lateral API](https://lateral.io/api). It currently supports `add` and `near_text` from the [Recommender API](https://developers.lateral.io/docs/services/546b2cc23705a70f4cd2766d/operations/546b2e053705a70f4cd2766e) and the complete (experimental) [Personalisation API](https://developers.lateral.io/docs/services/54b7f0923705a712c0f43836/operations/54b7f3753705a712c0f4383f). Over time the missing API methods will be added and this will become a fully featured wrapper around the Lateral API.
4
6
 
5
7
  *For the full API specification please see the [documentation here](https://developers.lateral.io/docs/services/).*
6
8
 
7
9
  ## Installation
8
10
 
9
- Add this line to your application's Gemfile:
11
+ Until the gem is more complete, it will not be available on rubygems.org. So to add it, add this line to your application's Gemfile:
10
12
 
11
- gem 'lateral_recommender'
13
+ gem 'lateral_recommender', github: 'lateral/recommender-gem'
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
16
-
17
- Or install it yourself as:
17
+ $ bundle install
18
18
 
19
- $ gem install lateral_recommender
19
+ Or you can [install it manually](https://stackoverflow.com/questions/2577346/how-to-install-gem-from-github-source).
20
20
 
21
21
  ## Usage
22
22
 
@@ -37,16 +37,22 @@ To add a document to the API call:
37
37
  ```ruby
38
38
  api.add document_id: 'document_id', text: 'document text'
39
39
  ```
40
-
40
+
41
41
  Please be aware that if you don't send enough meaningful text the API will return an error. So please ensure there is at least 100 or so words in the document you're adding.
42
42
 
43
- To get recommendations for a document, use `near_text`:
43
+ To get recommendations for some text, use `near_text`:
44
+
45
+ ```ruby
46
+ api.near_text 'document text'
47
+ ```
48
+
49
+ To get recommendations for a document that's in the API, use `near_id`:
44
50
 
45
51
  ```ruby
46
- api.near_text text: 'document text'
52
+ api.near_id 'document_id'
47
53
  ```
48
-
49
- This returns an array of Hashes containing a `document_id` and `distance`.
54
+
55
+ This returns an array of Hashes containing a `document_id` and `distance`.
50
56
 
51
57
  #### Querying our pre-populated data
52
58
 
@@ -63,15 +69,15 @@ To use these, simply initialize `LateralRecommender` with a second argument cont
63
69
  ```ruby
64
70
  api = LateralRecommender::API.new YOUR_API_KEY, 'news'
65
71
  ```
66
-
72
+
67
73
  The available values are `movies`, `news`, `arxiv`, `pubmed` or `wikipedia`. We plan to add more in the near future.
68
74
 
69
75
  Now you can query the API using `near_text` or `near_user` without the need for populating the API with your own content:
70
76
 
71
77
  ```ruby
72
- api.near_text text: 'document text'
78
+ api.near_text 'document text'
73
79
  ```
74
-
80
+
75
81
  #### Managing users
76
82
 
77
83
  A feature of the API is to be able to add a representation of a user. The user is able to have many documents and when querying the API for recommendations you can specify the user and each of these documents will be used to get recommendations for that user.
@@ -83,13 +89,13 @@ To add a user:
83
89
  ```ruby
84
90
  api.add_user 'user_id'
85
91
  ```
86
-
92
+
87
93
  To add a document to that user:
88
-
94
+
89
95
  ```ruby
90
96
  api.add_user_document 'user_id', 'document_id', 'document text'
91
97
  ```
92
-
98
+
93
99
  You can do this as many times as you want to build a more complete picture of the user. Then, to query for recommendations for that user:
94
100
 
95
101
  ```ruby
@@ -106,3 +112,7 @@ The response will be the same format as a `near_text`.
106
112
  4. Commit your changes (`git commit -am 'Add some feature'`)
107
113
  5. Push to the branch (`git push origin my-new-feature`)
108
114
  6. Create a new Pull Request
115
+
116
+ ### Testing
117
+
118
+ To test the gem, run `bundle exec rspec`. Note: your API key must be un-used.
@@ -12,9 +12,6 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/lateral/recommender-gem'
13
13
  spec.license = 'MIT'
14
14
 
15
- # spec.files = `git ls-files -z`.split("')
16
- # spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
- # spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
15
  spec.files = `git ls-files`.split("\n")
19
16
  spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
17
  spec.require_paths = ['lib']
@@ -28,5 +25,6 @@ Gem::Specification.new do |spec|
28
25
  spec.add_development_dependency 'yard'
29
26
 
30
27
  spec.add_runtime_dependency 'httpclient'
28
+ spec.add_runtime_dependency 'json'
31
29
  spec.add_runtime_dependency 'activesupport'
32
30
  end
@@ -1,3 +1,3 @@
1
1
  module LateralRecommender
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,5 +1,7 @@
1
1
  require 'lateral_recommender/version'
2
+ require 'httpclient'
2
3
  require 'active_support/core_ext/hash'
4
+ require 'json'
3
5
 
4
6
  module LateralRecommender
5
7
  class API
@@ -34,6 +36,17 @@ module LateralRecommender
34
36
  post "#{@corpora}/recommend", { text: text }.merge(opts)
35
37
  end
36
38
 
39
+ # Get recommendations for the provided id
40
+ #
41
+ # @param [String] text The ID of the document to get recommendations for.
42
+ # @param [Hash] opts Additional options for the request.
43
+ # @option opts [Integer] :results (20) How many results to return
44
+ # @option opts [Array] :select_from An array of IDs to return results from
45
+ # @return [Array] An array of Hashes containing the recommendations
46
+ def near_id(id, opts = {})
47
+ post "#{@corpora}/recommend", { document_id: id }.merge(opts)
48
+ end
49
+
37
50
  # Get recommendations for the provided text
38
51
  #
39
52
  # @param [String] id The ID of the user to return recommendations for
@@ -12,7 +12,7 @@ http_interactions:
12
12
  Accept:
13
13
  - '*/*'
14
14
  Date:
15
- - Thu, 22 Jan 2015 12:10:15 GMT
15
+ - Thu, 05 Feb 2015 15:36:52 GMT
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  response:
@@ -27,7 +27,7 @@ http_interactions:
27
27
  Server:
28
28
  - Microsoft-HTTPAPI/2.0
29
29
  Date:
30
- - Thu, 22 Jan 2015 12:10:14 GMT
30
+ - Thu, 05 Feb 2015 15:37:01 GMT
31
31
  body:
32
32
  encoding: UTF-8
33
33
  string: '{"text": "Space exploration\nJump to: navigation , search\nSaturn V
@@ -508,8 +508,8 @@ http_interactions:
508
508
  with strong arguments both for and against. In particular, the making of national
509
509
  territorial claims in outer space and on celestial bodies has been specifically
510
510
  proscribed by the Outer Space Treaty , which had been, as of 2012 [update]
511
- , ratified by all spacefaring nations . [46]", "created_at": "2015-01-22 12:08:28.488731",
511
+ , ratified by all spacefaring nations . [46]", "created_at": "2015-02-05 15:34:54.829682",
512
512
  "meta": "{}", "document_id": "doc_id"}'
513
513
  http_version:
514
- recorded_at: Thu, 22 Jan 2015 12:10:15 GMT
514
+ recorded_at: Thu, 05 Feb 2015 15:37:01 GMT
515
515
  recorded_with: VCR 2.9.3
@@ -12,7 +12,7 @@ http_interactions:
12
12
  Accept:
13
13
  - '*/*'
14
14
  Date:
15
- - Thu, 22 Jan 2015 12:13:03 GMT
15
+ - Thu, 05 Feb 2015 15:40:04 GMT
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  response:
@@ -27,7 +27,7 @@ http_interactions:
27
27
  Content-Type:
28
28
  - application/json
29
29
  Etag:
30
- - '"daea56294f0589e4a280ebcc12be18b2"'
30
+ - '"56d7ecacdee0e66f4ae2f2067dda5eab"'
31
31
  Vary:
32
32
  - Accept-Encoding
33
33
  Server:
@@ -41,16 +41,16 @@ http_interactions:
41
41
  Strict-Transport-Security:
42
42
  - max-age=31536000
43
43
  X-Request-Id:
44
- - 9d65956e-3ca2-43ef-88cd-b61bdd86c7a2
44
+ - 9c7a3ee4-4c84-4655-ad1d-a8d4dc4fed0b
45
45
  X-Runtime:
46
- - '0.020783'
46
+ - '0.035732'
47
47
  X-Powered-By:
48
48
  - Phusion Passenger 4.0.37
49
49
  Date:
50
- - Thu, 22 Jan 2015 12:13:03 GMT
50
+ - Thu, 05 Feb 2015 15:40:04 GMT
51
51
  body:
52
52
  encoding: UTF-8
53
- string: '{"id":"user_id","created_at":"2015-01-22T12:13:04.002Z","updated_at":"2015-01-22T12:13:04.002Z"}'
53
+ string: '{"id":"user_id","created_at":"2015-02-05T15:40:04.608Z","updated_at":"2015-02-05T15:40:04.608Z"}'
54
54
  http_version:
55
- recorded_at: Thu, 22 Jan 2015 12:13:04 GMT
55
+ recorded_at: Thu, 05 Feb 2015 15:40:04 GMT
56
56
  recorded_with: VCR 2.9.3
@@ -12,7 +12,7 @@ http_interactions:
12
12
  Accept:
13
13
  - '*/*'
14
14
  Date:
15
- - Thu, 22 Jan 2015 12:14:05 GMT
15
+ - Thu, 05 Feb 2015 15:40:05 GMT
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  response:
@@ -27,7 +27,7 @@ http_interactions:
27
27
  Content-Type:
28
28
  - application/json
29
29
  Etag:
30
- - '"821bf1908831fbb56e28280c8567bb43"'
30
+ - '"d522edd6b0412c73293c1e57b1a3cc10"'
31
31
  Vary:
32
32
  - Accept-Encoding
33
33
  Server:
@@ -41,13 +41,13 @@ http_interactions:
41
41
  Strict-Transport-Security:
42
42
  - max-age=31536000
43
43
  X-Request-Id:
44
- - 2e731b72-640e-417a-9b33-febd72986af9
44
+ - 14df8fdc-4b6e-48f1-9c86-797e08d0e6f6
45
45
  X-Runtime:
46
- - '0.486240'
46
+ - '0.791947'
47
47
  X-Powered-By:
48
48
  - Phusion Passenger 4.0.37
49
49
  Date:
50
- - Thu, 22 Jan 2015 12:14:05 GMT
50
+ - Thu, 05 Feb 2015 15:40:06 GMT
51
51
  body:
52
52
  encoding: ASCII-8BIT
53
53
  string: !binary |-
@@ -873,7 +873,7 @@ http_interactions:
873
873
  bHkgcHJvc2NyaWJlZCBieSB0aGUgT3V0ZXIgU3BhY2UgVHJlYXR5ICwgd2hp
874
874
  Y2ggaGFkIGJlZW4sIGFzIG9mIDIwMTIgW3VwZGF0ZV0gLCByYXRpZmllZCBi
875
875
  eSBhbGwgc3BhY2VmYXJpbmcgbmF0aW9ucyAuIFs0Nl1cbiIsInRpbWUiOiIy
876
- MDE1LTAxLTIyVDEyOjE0OjA2LjQ1MVoifQ==
876
+ MDE1LTAyLTA1VDE1OjQwOjA2LjI2NloifQ==
877
877
  http_version:
878
- recorded_at: Thu, 22 Jan 2015 12:14:06 GMT
878
+ recorded_at: Thu, 05 Feb 2015 15:40:07 GMT
879
879
  recorded_with: VCR 2.9.3
@@ -5,14 +5,14 @@ http_interactions:
5
5
  uri: https://api.lateral.io/recommender/recommend/?subscription-key=no
6
6
  body:
7
7
  encoding: UTF-8
8
- string: text=%7B%3Atext%3D%3E%22test%22%7D
8
+ string: text=test
9
9
  headers:
10
10
  User-Agent:
11
11
  - HTTPClient/1.0 (2.6.0.1, ruby 2.0.0 (2014-02-24))
12
12
  Accept:
13
13
  - '*/*'
14
14
  Date:
15
- - Thu, 22 Jan 2015 12:08:48 GMT
15
+ - Thu, 05 Feb 2015 10:19:06 GMT
16
16
  Content-Type:
17
17
  - application/x-www-form-urlencoded
18
18
  response:
@@ -27,12 +27,12 @@ http_interactions:
27
27
  Server:
28
28
  - Microsoft-HTTPAPI/2.0
29
29
  Date:
30
- - Thu, 22 Jan 2015 12:08:48 GMT
30
+ - Thu, 05 Feb 2015 10:19:06 GMT
31
31
  body:
32
32
  encoding: UTF-8
33
33
  string: '{ "statusCode": 401, "message": "Access denied due to invalid subscription
34
34
  key. Make sure you are subscribed to an API you are trying to call and provide
35
35
  the right key." }'
36
36
  http_version:
37
- recorded_at: Thu, 22 Jan 2015 12:08:49 GMT
37
+ recorded_at: Thu, 05 Feb 2015 10:19:06 GMT
38
38
  recorded_with: VCR 2.9.3
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.lateral.io/recommender/recommend/?subscription-key=<API_KEY>
6
+ body:
7
+ encoding: UTF-8
8
+ string: document_id=doc_id
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.6.0.1, ruby 2.0.0 (2014-02-24))
12
+ Accept:
13
+ - '*/*'
14
+ Date:
15
+ - Thu, 05 Feb 2015 15:39:26 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '952'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-HTTPAPI/2.0
29
+ Date:
30
+ - Thu, 05 Feb 2015 15:39:27 GMT
31
+ body:
32
+ encoding: UTF-8
33
+ string: '[{"distance": 0.000248, "document_id": "doc_id"}, {"distance": 0.03849,
34
+ "document_id": "16400"}, {"distance": 0.043243, "document_id": "21299"}, {"distance":
35
+ 0.043754, "document_id": "6824"}, {"distance": 0.043945, "document_id": "11689"},
36
+ {"distance": 0.045342, "document_id": "433"}, {"distance": 0.045867, "document_id":
37
+ "8403"}, {"distance": 0.046243, "document_id": "13882"}, {"distance": 0.046285,
38
+ "document_id": "1391"}, {"distance": 0.046396, "document_id": "15333"}, {"distance":
39
+ 0.046684, "document_id": "4236"}, {"distance": 0.046794, "document_id": "8443"},
40
+ {"distance": 0.047875, "document_id": "2422"}, {"distance": 0.048303, "document_id":
41
+ "22543"}, {"distance": 0.048475, "document_id": "11235"}, {"distance": 0.048584,
42
+ "document_id": "17475"}, {"distance": 0.049252, "document_id": "17266"}, {"distance":
43
+ 0.049315, "document_id": "26815"}, {"distance": 0.049454, "document_id": "30270"},
44
+ {"distance": 0.049636, "document_id": "17836"}]'
45
+ http_version:
46
+ recorded_at: Thu, 05 Feb 2015 15:39:27 GMT
47
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,68 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.lateral.io/collections/arxiv/recommend/?subscription-key=<API_KEY>
6
+ body:
7
+ encoding: UTF-8
8
+ string: document_id=arxiv-http%3A%2F%2Farxiv.org%2Fabs%2F1403.2165
9
+ headers:
10
+ User-Agent:
11
+ - HTTPClient/1.0 (2.6.0.1, ruby 2.0.0 (2014-02-24))
12
+ Accept:
13
+ - '*/*'
14
+ Date:
15
+ - Thu, 05 Feb 2015 15:55:22 GMT
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Length:
24
+ - '2823'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Server:
28
+ - Microsoft-HTTPAPI/2.0
29
+ Date:
30
+ - Thu, 05 Feb 2015 15:55:23 GMT
31
+ body:
32
+ encoding: UTF-8
33
+ string: '[{"distance": 0.0, "title": "Set-valued sorting index and joint equidistributions",
34
+ "url": "http://arxiv.org/abs/1403.2165", "authors": ["Eu, Sen-Pen", "Lo, Yuan-Hsun",
35
+ "Wong, Tsai-Lien"], "date": "2015-02-05", "document_id": "arxiv-http://arxiv.org/abs/1403.2165"},
36
+ {"distance": 0.143046, "title": "The sorting index and set-valued joint equidistributions
37
+ of $\\mathcal{B}_n$ and $\\mathcal{D}_n$", "url": "http://arxiv.org/abs/1403.2169",
38
+ "authors": ["Eu, Sen-Peng", "Lo, Yuan-Hsun", "Wong, Tsai-Lien"], "date": "2015-02-05",
39
+ "document_id": "arxiv-http://arxiv.org/abs/1403.2169"}, {"distance": 0.387619,
40
+ "title": "Creature forcing and five cardinal characteristics in Cicho\\''{n}''s diagram",
41
+ "url": "http://arxiv.org/abs/1402.0367", "authors": ["Fischer, Arthur", "Goldstern,
42
+ Martin", "Kellner, Jakob", "Shelah, Saharon"], "date": "2015-02-05", "document_id":
43
+ "arxiv-http://arxiv.org/abs/1402.0367"}, {"distance": 0.47352, "title": "Corpus-based
44
+ Web Document Summarization using Statistical and Linguistic Approach", "url":
45
+ "http://arxiv.org/abs/1304.2476", "authors": ["Hashem, M. M. A.", "Gope, Monika",
46
+ "Akter, Suraiya Rumana", "Shams, Rushdi", "Hossain, Afrina"], "date": "2015-02-05",
47
+ "document_id": "arxiv-http://arxiv.org/abs/1304.2476"}, {"distance": 0.485755,
48
+ "title": "Text as Statistical Mechanics Object", "url": "http://arxiv.org/abs/0810.3416",
49
+ "authors": ["Korutcheva, E.", "Koroutchev, K."], "date": "2015-02-05", "document_id":
50
+ "arxiv-http://arxiv.org/abs/0810.3416"}, {"distance": 0.491576, "title": "Text
51
+ Classification using Artificial Intelligence", "url": "http://arxiv.org/abs/1009.4964",
52
+ "authors": ["Kamruzzaman, S. M."], "date": "2015-02-05", "document_id": "arxiv-http://arxiv.org/abs/1009.4964"},
53
+ {"distance": 0.497958, "title": "Text Classification using Data Mining", "url":
54
+ "http://arxiv.org/abs/1009.4987", "authors": ["Hasan, Ahmed Ryadh", "Haider,
55
+ Farhana", "Kamruzzaman, S. M."], "date": "2015-02-05", "document_id": "arxiv-http://arxiv.org/abs/1009.4987"},
56
+ {"distance": 0.504628, "title": "Artex is AnotheR TEXt summarizer", "url":
57
+ "http://arxiv.org/abs/1210.3312", "authors": ["Torres-Moreno, Juan-Manuel"],
58
+ "date": "2015-02-05", "document_id": "arxiv-http://arxiv.org/abs/1210.3312"},
59
+ {"distance": 0.508608, "title": "Text Classification using Association Rule
60
+ with a Hybrid Concept of Naive Bayes Classifier and Genetic Algorithm",
61
+ "url": "http://arxiv.org/abs/1009.4976", "authors": ["Hasan, Ahmed Ryadh",
62
+ "Haider, Farhana", "Kamruzzaman, S. M."], "date": "2015-02-05", "document_id":
63
+ "arxiv-http://arxiv.org/abs/1009.4976"}, {"distance": 0.516115, "title": "Comparative
64
+ Discourse Analysis of Parallel Texts", "url": "http://arxiv.org/abs/cmp-lg/9407022",
65
+ "authors": ["van der Eijk, Pim"], "date": "2015-02-05", "document_id": "arxiv-http://arxiv.org/abs/cmp-lg/9407022"}]'
66
+ http_version:
67
+ recorded_at: Thu, 05 Feb 2015 15:55:23 GMT
68
+ recorded_with: VCR 2.9.3