nlpcloud 1.0.6 → 1.0.10

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nlpcloud.rb +80 -17
  3. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1bc3ef2c6d093286a398df29a536c6cd7b385c98529ca06504c2acf9d9b1d73
4
- data.tar.gz: fde382a7b8d2f2492f674fd9f9b8e915d0703bfc5f3c732d26123cf69120bdb8
3
+ metadata.gz: 33a4b97770d4b1a6f6daf5c3365f5dbe266e82113ab54b4219cf414458aa7907
4
+ data.tar.gz: ec629fbc99105b49cb4f90b90b42b2ad812d509c808d28b77859b61dc7c2b4e1
5
5
  SHA512:
6
- metadata.gz: 4fc09a303f8bccc9100054b42c0b77201c05cb685ffe5f29a06e89066ad92dbdbb1a67fabdb9993f59b4f433c5ebdc2f7e1faaf885f0d446fc0ed97dceb9d465
7
- data.tar.gz: b03c237ee994bdc84344379285bf51994640ab618a03b74cfe4e967e4dfac6bc95d6daeb7142e01a35963c0ab72f5a42fa22e9c08c1eea10dba775c90ea26d60
6
+ metadata.gz: a618257dc0d197126b16698d51957209989b533bbcaf731c6ac4a7987c25ad83b712688d14ea5b3bccdf61c5c8a7675bd0786f30ca5ddb8dca6a6a69f1307f7c
7
+ data.tar.gz: db964aa4c66127a60c64e19b21c8377969f83eec024b1dab3dd3d85ed47d31ece8458ee7cebca7c664b3bb993eae69d028bdfe04c3f5fa2afc965f92c827e49a
data/lib/nlpcloud.rb CHANGED
@@ -9,41 +9,104 @@ module NLPCloud
9
9
 
10
10
  # Client requests the API.
11
11
  class Client
12
- def initialize(model, token)
12
+ def initialize(model, token, gpu: false)
13
13
  @headers = {
14
- 'Authorization' => "Token #{token}"
14
+ 'Authorization' => "Token #{token}",
15
+ "User-Agent": 'nlploud-ruby-client'
15
16
  }
16
- @root_url = "#{BASE_URL}/#{API_VERSION}/#{model}"
17
+
18
+ @root_url = if gpu
19
+ "#{BASE_URL}/#{API_VERSION}/gpu/#{model}"
20
+ else
21
+ "#{BASE_URL}/#{API_VERSION}/#{model}"
22
+ end
17
23
  end
18
24
 
19
- def entities(user_input)
20
- api_post('entities', user_input)
25
+ def entities(text)
26
+ payload = {
27
+ 'text' => text
28
+ }
29
+ response = RestClient.post("#{@root_url}/entities", payload.to_json, @headers)
30
+ JSON.parse(response.body)
21
31
  end
22
32
 
23
- def dependencies(user_input)
24
- api_post('dependencies', user_input)
33
+ def classification(text, labels, multi_class)
34
+ payload = {
35
+ 'text' => text,
36
+ 'labels' => labels,
37
+ 'multi_class' => multi_class
38
+ }
39
+ response = RestClient.post("#{@root_url}/classification", payload.to_json, @headers)
40
+ JSON.parse(response.body)
25
41
  end
26
42
 
27
- def sentence_dependencies(user_input)
28
- api_post('sentence-dependencies', user_input)
43
+ def sentiment(text)
44
+ payload = {
45
+ 'text' => text
46
+ }
47
+ response = RestClient.post("#{@root_url}/sentiment", payload.to_json, @headers)
48
+ JSON.parse(response.body)
29
49
  end
30
50
 
31
- def lib_versions
32
- api_get('version')
51
+ def question(context, question)
52
+ payload = {
53
+ 'context' => context,
54
+ 'question' => question
55
+ }
56
+ response = RestClient.post("#{@root_url}/question", payload.to_json, @headers)
57
+ JSON.parse(response.body)
33
58
  end
34
59
 
35
- private
60
+ def summarization(text)
61
+ payload = {
62
+ 'text' => text
63
+ }
64
+ response = RestClient.post("#{@root_url}/summarization", payload.to_json, @headers)
65
+ JSON.parse(response.body)
66
+ end
36
67
 
37
- def api_post(endpoint, user_input)
68
+ def translation(text)
38
69
  payload = {
39
- 'text' => user_input
70
+ 'text' => text
40
71
  }
41
- response = RestClient.post("#{@root_url}/#{endpoint}", payload.to_json, @headers)
72
+ response = RestClient.post("#{@root_url}/translation", payload.to_json, @headers)
42
73
  JSON.parse(response.body)
43
74
  end
44
75
 
45
- def api_get(endpoint)
46
- response = RestClient.get("#{@root_url}/#{endpoint}", @headers)
76
+ def langdetection(text)
77
+ payload = {
78
+ 'text' => text
79
+ }
80
+ response = RestClient.post("#{@root_url}/langdetection", payload.to_json, @headers)
81
+ JSON.parse(response.body)
82
+ end
83
+
84
+ def tokens(text)
85
+ payload = {
86
+ 'text' => text
87
+ }
88
+ response = RestClient.post("#{@root_url}/tokens", payload.to_json, @headers)
89
+ JSON.parse(response.body)
90
+ end
91
+
92
+ def dependencies(text)
93
+ payload = {
94
+ 'text' => text
95
+ }
96
+ response = RestClient.post("#{@root_url}/dependencies", payload.to_json, @headers)
97
+ JSON.parse(response.body)
98
+ end
99
+
100
+ def sentence_dependencies(text)
101
+ payload = {
102
+ 'text' => text
103
+ }
104
+ response = RestClient.post("#{@root_url}/sentence-dependencies", payload.to_json, @headers)
105
+ JSON.parse(response.body)
106
+ end
107
+
108
+ def lib_versions
109
+ response = RestClient.get("#{@root_url}/versions", @headers)
47
110
  JSON.parse(response.body)
48
111
  end
49
112
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nlpcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Salinas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'Ruby client for the NLP Cloud API. NLP Cloud serves all the spaCy pre-trained
14
- models, and your own custom models, through a RESTful API ready for production.
15
- More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io.'
13
+ description: 'NLP Cloud serves high performance pre-trained or custom models for NER,
14
+ sentiment-analysis, classification, summarization, text generation, question answering,
15
+ machine translation, language detection, tokenization, POS tagging, and dependency
16
+ parsing. It is ready for production, served through a REST API. This is the Ruby
17
+ client for the API. More details here: https://nlpcloud.io. Documentation: https://docs.nlpcloud.io.'
16
18
  email: all@juliensalinas.com
17
19
  executables: []
18
20
  extensions: []