ibm_watson 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -39
- data/lib/ibm_watson/assistant_v1.rb +5 -4
- data/lib/ibm_watson/assistant_v2.rb +3 -3
- data/lib/ibm_watson/discovery_v1.rb +7 -14
- data/lib/ibm_watson/discovery_v2.rb +109 -108
- data/lib/ibm_watson/language_translator_v3.rb +2 -2
- data/lib/ibm_watson/natural_language_understanding_v1.rb +12 -14
- data/lib/ibm_watson/speech_to_text_v1.rb +581 -402
- data/lib/ibm_watson/text_to_speech_v1.rb +87 -166
- data/lib/ibm_watson/version.rb +1 -1
- data/lib/ibm_watson.rb +0 -6
- metadata +2 -20
- data/lib/ibm_watson/compare_comply_v1.rb +0 -683
- data/lib/ibm_watson/natural_language_classifier_v1.rb +0 -258
- data/lib/ibm_watson/personality_insights_v3.rb +0 -223
- data/lib/ibm_watson/tone_analyzer_v3.rb +0 -230
- data/lib/ibm_watson/visual_recognition_v3.rb +0 -517
- data/lib/ibm_watson/visual_recognition_v4.rb +0 -930
- data/test/integration/test_compare_comply_v1.rb +0 -105
- data/test/integration/test_natural_language_classifier_v1.rb +0 -80
- data/test/integration/test_personality_insights_v3.rb +0 -81
- data/test/integration/test_tone_analyzer_v3.rb +0 -66
- data/test/integration/test_visual_recognition_v3.rb +0 -68
- data/test/integration/test_visual_recognition_v4.rb +0 -87
- data/test/unit/test_compare_comply_v1.rb +0 -232
- data/test/unit/test_natural_language_classifier_v1.rb +0 -191
- data/test/unit/test_personality_insights_v3.rb +0 -192
- data/test/unit/test_tone_analyzer_v3.rb +0 -217
- data/test/unit/test_visual_recognition_v3.rb +0 -300
- data/test/unit/test_visual_recognition_v4.rb +0 -422
@@ -1,258 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# (C) Copyright IBM Corp. 2018, 2020.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
# IBM OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
|
18
|
-
#
|
19
|
-
# IBM Watson™ Natural Language Classifier uses machine learning algorithms to
|
20
|
-
# return the top matching predefined classes for short text input. You create and train a
|
21
|
-
# classifier to connect predefined classes to example texts so that the service can apply
|
22
|
-
# those classes to new inputs.
|
23
|
-
|
24
|
-
require "concurrent"
|
25
|
-
require "erb"
|
26
|
-
require "json"
|
27
|
-
require "ibm_cloud_sdk_core"
|
28
|
-
require_relative "./common.rb"
|
29
|
-
|
30
|
-
module IBMWatson
|
31
|
-
##
|
32
|
-
# The Natural Language Classifier V1 service.
|
33
|
-
class NaturalLanguageClassifierV1 < IBMCloudSdkCore::BaseService
|
34
|
-
include Concurrent::Async
|
35
|
-
DEFAULT_SERVICE_NAME = "natural_language_classifier"
|
36
|
-
DEFAULT_SERVICE_URL = "https://api.us-south.natural-language-classifier.watson.cloud.ibm.com"
|
37
|
-
##
|
38
|
-
# @!method initialize(args)
|
39
|
-
# Construct a new client for the Natural Language Classifier service.
|
40
|
-
#
|
41
|
-
# @param args [Hash] The args to initialize with
|
42
|
-
# @option args service_url [String] The base service URL to use when contacting the service.
|
43
|
-
# The base service_url may differ between IBM Cloud regions.
|
44
|
-
# @option args authenticator [Object] The Authenticator instance to be configured for this service.
|
45
|
-
# @option args service_name [String] The name of the service to configure. Will be used as the key to load
|
46
|
-
# any external configuration, if applicable.
|
47
|
-
def initialize(args = {})
|
48
|
-
@__async_initialized__ = false
|
49
|
-
defaults = {}
|
50
|
-
defaults[:service_url] = DEFAULT_SERVICE_URL
|
51
|
-
defaults[:service_name] = DEFAULT_SERVICE_NAME
|
52
|
-
defaults[:authenticator] = nil
|
53
|
-
user_service_url = args[:service_url] unless args[:service_url].nil?
|
54
|
-
args = defaults.merge(args)
|
55
|
-
args[:authenticator] = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: args[:service_name]) if args[:authenticator].nil?
|
56
|
-
super
|
57
|
-
@service_url = user_service_url unless user_service_url.nil?
|
58
|
-
end
|
59
|
-
|
60
|
-
#########################
|
61
|
-
# Classify text
|
62
|
-
#########################
|
63
|
-
|
64
|
-
##
|
65
|
-
# @!method classify(classifier_id:, text:)
|
66
|
-
# Classify a phrase.
|
67
|
-
# Returns label information for the input. The status must be `Available` before you
|
68
|
-
# can use the classifier to classify text.
|
69
|
-
# @param classifier_id [String] Classifier ID to use.
|
70
|
-
# @param text [String] The submitted phrase. The maximum length is 2048 characters.
|
71
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
72
|
-
def classify(classifier_id:, text:)
|
73
|
-
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
74
|
-
|
75
|
-
raise ArgumentError.new("text must be provided") if text.nil?
|
76
|
-
|
77
|
-
headers = {
|
78
|
-
}
|
79
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "classify")
|
80
|
-
headers.merge!(sdk_headers)
|
81
|
-
|
82
|
-
data = {
|
83
|
-
"text" => text
|
84
|
-
}
|
85
|
-
|
86
|
-
method_url = "/v1/classifiers/%s/classify" % [ERB::Util.url_encode(classifier_id)]
|
87
|
-
|
88
|
-
response = request(
|
89
|
-
method: "POST",
|
90
|
-
url: method_url,
|
91
|
-
headers: headers,
|
92
|
-
json: data,
|
93
|
-
accept_json: true
|
94
|
-
)
|
95
|
-
response
|
96
|
-
end
|
97
|
-
|
98
|
-
##
|
99
|
-
# @!method classify_collection(classifier_id:, collection:)
|
100
|
-
# Classify multiple phrases.
|
101
|
-
# Returns label information for multiple phrases. The status must be `Available`
|
102
|
-
# before you can use the classifier to classify text.
|
103
|
-
#
|
104
|
-
# Note that classifying Japanese texts is a beta feature.
|
105
|
-
# @param classifier_id [String] Classifier ID to use.
|
106
|
-
# @param collection [Array[ClassifyInput]] The submitted phrases.
|
107
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
108
|
-
def classify_collection(classifier_id:, collection:)
|
109
|
-
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
110
|
-
|
111
|
-
raise ArgumentError.new("collection must be provided") if collection.nil?
|
112
|
-
|
113
|
-
headers = {
|
114
|
-
}
|
115
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "classify_collection")
|
116
|
-
headers.merge!(sdk_headers)
|
117
|
-
|
118
|
-
data = {
|
119
|
-
"collection" => collection
|
120
|
-
}
|
121
|
-
|
122
|
-
method_url = "/v1/classifiers/%s/classify_collection" % [ERB::Util.url_encode(classifier_id)]
|
123
|
-
|
124
|
-
response = request(
|
125
|
-
method: "POST",
|
126
|
-
url: method_url,
|
127
|
-
headers: headers,
|
128
|
-
json: data,
|
129
|
-
accept_json: true
|
130
|
-
)
|
131
|
-
response
|
132
|
-
end
|
133
|
-
#########################
|
134
|
-
# Manage classifiers
|
135
|
-
#########################
|
136
|
-
|
137
|
-
##
|
138
|
-
# @!method create_classifier(training_metadata:, training_data:)
|
139
|
-
# Create classifier.
|
140
|
-
# Sends data to create and train a classifier and returns information about the new
|
141
|
-
# classifier.
|
142
|
-
# @param training_metadata [File] Metadata in JSON format. The metadata identifies the language of the data, and an
|
143
|
-
# optional name to identify the classifier. Specify the language with the 2-letter
|
144
|
-
# primary language code as assigned in ISO standard 639.
|
145
|
-
#
|
146
|
-
# Supported languages are English (`en`), Arabic (`ar`), French (`fr`), German,
|
147
|
-
# (`de`), Italian (`it`), Japanese (`ja`), Korean (`ko`), Brazilian Portuguese
|
148
|
-
# (`pt`), and Spanish (`es`).
|
149
|
-
# @param training_data [File] Training data in CSV format. Each text value must have at least one class. The
|
150
|
-
# data can include up to 3,000 classes and 20,000 records. For details, see [Data
|
151
|
-
# preparation](https://cloud.ibm.com/docs/natural-language-classifier?topic=natural-language-classifier-using-your-data).
|
152
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
153
|
-
def create_classifier(training_metadata:, training_data:)
|
154
|
-
raise ArgumentError.new("training_metadata must be provided") if training_metadata.nil?
|
155
|
-
|
156
|
-
raise ArgumentError.new("training_data must be provided") if training_data.nil?
|
157
|
-
|
158
|
-
headers = {
|
159
|
-
}
|
160
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "create_classifier")
|
161
|
-
headers.merge!(sdk_headers)
|
162
|
-
|
163
|
-
form_data = {}
|
164
|
-
|
165
|
-
unless training_metadata.instance_of?(StringIO) || training_metadata.instance_of?(File)
|
166
|
-
training_metadata = training_metadata.respond_to?(:to_json) ? StringIO.new(training_metadata.to_json) : StringIO.new(training_metadata)
|
167
|
-
end
|
168
|
-
form_data[:training_metadata] = HTTP::FormData::File.new(training_metadata, content_type: "application/json", filename: training_metadata.respond_to?(:path) ? training_metadata.path : nil)
|
169
|
-
|
170
|
-
unless training_data.instance_of?(StringIO) || training_data.instance_of?(File)
|
171
|
-
training_data = training_data.respond_to?(:to_json) ? StringIO.new(training_data.to_json) : StringIO.new(training_data)
|
172
|
-
end
|
173
|
-
form_data[:training_data] = HTTP::FormData::File.new(training_data, content_type: "text/csv", filename: training_data.respond_to?(:path) ? training_data.path : nil)
|
174
|
-
|
175
|
-
method_url = "/v1/classifiers"
|
176
|
-
|
177
|
-
response = request(
|
178
|
-
method: "POST",
|
179
|
-
url: method_url,
|
180
|
-
headers: headers,
|
181
|
-
form: form_data,
|
182
|
-
accept_json: true
|
183
|
-
)
|
184
|
-
response
|
185
|
-
end
|
186
|
-
|
187
|
-
##
|
188
|
-
# @!method list_classifiers
|
189
|
-
# List classifiers.
|
190
|
-
# Returns an empty array if no classifiers are available.
|
191
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
192
|
-
def list_classifiers
|
193
|
-
headers = {
|
194
|
-
}
|
195
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "list_classifiers")
|
196
|
-
headers.merge!(sdk_headers)
|
197
|
-
|
198
|
-
method_url = "/v1/classifiers"
|
199
|
-
|
200
|
-
response = request(
|
201
|
-
method: "GET",
|
202
|
-
url: method_url,
|
203
|
-
headers: headers,
|
204
|
-
accept_json: true
|
205
|
-
)
|
206
|
-
response
|
207
|
-
end
|
208
|
-
|
209
|
-
##
|
210
|
-
# @!method get_classifier(classifier_id:)
|
211
|
-
# Get information about a classifier.
|
212
|
-
# Returns status and other information about a classifier.
|
213
|
-
# @param classifier_id [String] Classifier ID to query.
|
214
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
215
|
-
def get_classifier(classifier_id:)
|
216
|
-
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
217
|
-
|
218
|
-
headers = {
|
219
|
-
}
|
220
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "get_classifier")
|
221
|
-
headers.merge!(sdk_headers)
|
222
|
-
|
223
|
-
method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
|
224
|
-
|
225
|
-
response = request(
|
226
|
-
method: "GET",
|
227
|
-
url: method_url,
|
228
|
-
headers: headers,
|
229
|
-
accept_json: true
|
230
|
-
)
|
231
|
-
response
|
232
|
-
end
|
233
|
-
|
234
|
-
##
|
235
|
-
# @!method delete_classifier(classifier_id:)
|
236
|
-
# Delete classifier.
|
237
|
-
# @param classifier_id [String] Classifier ID to delete.
|
238
|
-
# @return [nil]
|
239
|
-
def delete_classifier(classifier_id:)
|
240
|
-
raise ArgumentError.new("classifier_id must be provided") if classifier_id.nil?
|
241
|
-
|
242
|
-
headers = {
|
243
|
-
}
|
244
|
-
sdk_headers = Common.new.get_sdk_headers("natural_language_classifier", "V1", "delete_classifier")
|
245
|
-
headers.merge!(sdk_headers)
|
246
|
-
|
247
|
-
method_url = "/v1/classifiers/%s" % [ERB::Util.url_encode(classifier_id)]
|
248
|
-
|
249
|
-
request(
|
250
|
-
method: "DELETE",
|
251
|
-
url: method_url,
|
252
|
-
headers: headers,
|
253
|
-
accept_json: true
|
254
|
-
)
|
255
|
-
nil
|
256
|
-
end
|
257
|
-
end
|
258
|
-
end
|
@@ -1,223 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# (C) Copyright IBM Corp. 2018, 2020.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
# IBM OpenAPI SDK Code Generator Version: 3.31.0-902c9336-20210504-161156
|
18
|
-
#
|
19
|
-
# IBM Watson™ Personality Insights is discontinued. Existing instances are
|
20
|
-
# supported until 1 December 2021, but as of 1 December 2020, you cannot create new
|
21
|
-
# instances. Any instance that exists on 1 December 2021 will be deleted.<br/><br/>No
|
22
|
-
# direct replacement exists for Personality Insights. However, you can consider using [IBM
|
23
|
-
# Watson™ Natural Language
|
24
|
-
# Understanding](https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-about)
|
25
|
-
# on IBM Cloud® as part of a replacement analytic workflow for your Personality
|
26
|
-
# Insights use cases. You can use Natural Language Understanding to extract data and
|
27
|
-
# insights from text, such as keywords, categories, sentiment, emotion, and syntax. For
|
28
|
-
# more information about the personality models in Personality Insights, see [The science
|
29
|
-
# behind the
|
30
|
-
# service](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-science).
|
31
|
-
# {: deprecated}
|
32
|
-
#
|
33
|
-
# The IBM Watson Personality Insights service enables applications to derive insights from
|
34
|
-
# social media, enterprise data, or other digital communications. The service uses
|
35
|
-
# linguistic analytics to infer individuals' intrinsic personality characteristics,
|
36
|
-
# including Big Five, Needs, and Values, from digital communications such as email, text
|
37
|
-
# messages, tweets, and forum posts.
|
38
|
-
#
|
39
|
-
# The service can automatically infer, from potentially noisy social media, portraits of
|
40
|
-
# individuals that reflect their personality characteristics. The service can infer
|
41
|
-
# consumption preferences based on the results of its analysis and, for JSON content that
|
42
|
-
# is timestamped, can report temporal behavior.
|
43
|
-
# * For information about the meaning of the models that the service uses to describe
|
44
|
-
# personality characteristics, see [Personality
|
45
|
-
# models](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-models#models).
|
46
|
-
# * For information about the meaning of the consumption preferences, see [Consumption
|
47
|
-
# preferences](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-preferences#preferences).
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# **Note:** Request logging is disabled for the Personality Insights service. Regardless
|
51
|
-
# of whether you set the `X-Watson-Learning-Opt-Out` request header, the service does not
|
52
|
-
# log or retain data from requests and responses.
|
53
|
-
|
54
|
-
require "concurrent"
|
55
|
-
require "erb"
|
56
|
-
require "json"
|
57
|
-
require "ibm_cloud_sdk_core"
|
58
|
-
require_relative "./common.rb"
|
59
|
-
|
60
|
-
module IBMWatson
|
61
|
-
##
|
62
|
-
# The Personality Insights V3 service.
|
63
|
-
class PersonalityInsightsV3 < IBMCloudSdkCore::BaseService
|
64
|
-
include Concurrent::Async
|
65
|
-
DEFAULT_SERVICE_NAME = "personality_insights"
|
66
|
-
DEFAULT_SERVICE_URL = "https://api.us-south.personality-insights.watson.cloud.ibm.com"
|
67
|
-
attr_accessor :version
|
68
|
-
##
|
69
|
-
# @!method initialize(args)
|
70
|
-
# Construct a new client for the Personality Insights service.
|
71
|
-
#
|
72
|
-
# @param args [Hash] The args to initialize with
|
73
|
-
# @option args version [String] Release date of the version of the API you want to use. Specify dates in
|
74
|
-
# YYYY-MM-DD format. The current version is `2017-10-13`.
|
75
|
-
# @option args service_url [String] The base service URL to use when contacting the service.
|
76
|
-
# The base service_url may differ between IBM Cloud regions.
|
77
|
-
# @option args authenticator [Object] The Authenticator instance to be configured for this service.
|
78
|
-
# @option args service_name [String] The name of the service to configure. Will be used as the key to load
|
79
|
-
# any external configuration, if applicable.
|
80
|
-
def initialize(args = {})
|
81
|
-
warn "On 1 December 2021, Personality Insights will no longer be available. For more information, see https://github.com/watson-developer-cloud/ruby-sdk/tree/master#personality-insights-deprecation."
|
82
|
-
@__async_initialized__ = false
|
83
|
-
defaults = {}
|
84
|
-
defaults[:service_url] = DEFAULT_SERVICE_URL
|
85
|
-
defaults[:service_name] = DEFAULT_SERVICE_NAME
|
86
|
-
defaults[:authenticator] = nil
|
87
|
-
defaults[:version] = nil
|
88
|
-
user_service_url = args[:service_url] unless args[:service_url].nil?
|
89
|
-
args = defaults.merge(args)
|
90
|
-
@version = args[:version]
|
91
|
-
raise ArgumentError.new("version must be provided") if @version.nil?
|
92
|
-
|
93
|
-
args[:authenticator] = IBMCloudSdkCore::ConfigBasedAuthenticatorFactory.new.get_authenticator(service_name: args[:service_name]) if args[:authenticator].nil?
|
94
|
-
super
|
95
|
-
@service_url = user_service_url unless user_service_url.nil?
|
96
|
-
end
|
97
|
-
|
98
|
-
#########################
|
99
|
-
# Methods
|
100
|
-
#########################
|
101
|
-
|
102
|
-
##
|
103
|
-
# @!method profile(content:, accept:, content_type: nil, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil)
|
104
|
-
# Get profile.
|
105
|
-
# Generates a personality profile for the author of the input text. The service
|
106
|
-
# accepts a maximum of 20 MB of input content, but it requires much less text to
|
107
|
-
# produce an accurate profile. The service can analyze text in Arabic, English,
|
108
|
-
# Japanese, Korean, or Spanish. It can return its results in a variety of languages.
|
109
|
-
#
|
110
|
-
#
|
111
|
-
# **See also:**
|
112
|
-
# * [Requesting a
|
113
|
-
# profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#input)
|
114
|
-
# * [Providing sufficient
|
115
|
-
# input](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#sufficient)
|
116
|
-
#
|
117
|
-
#
|
118
|
-
# ### Content types
|
119
|
-
#
|
120
|
-
# You can provide input content as plain text (`text/plain`), HTML (`text/html`),
|
121
|
-
# or JSON (`application/json`) by specifying the **Content-Type** parameter. The
|
122
|
-
# default is `text/plain`.
|
123
|
-
# * Per the JSON specification, the default character encoding for JSON content is
|
124
|
-
# effectively always UTF-8.
|
125
|
-
# * Per the HTTP specification, the default encoding for plain text and HTML is
|
126
|
-
# ISO-8859-1 (effectively, the ASCII character set).
|
127
|
-
#
|
128
|
-
# When specifying a content type of plain text or HTML, include the `charset`
|
129
|
-
# parameter to indicate the character encoding of the input text; for example,
|
130
|
-
# `Content-Type: text/plain;charset=utf-8`.
|
131
|
-
#
|
132
|
-
# **See also:** [Specifying request and response
|
133
|
-
# formats](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#formats)
|
134
|
-
#
|
135
|
-
#
|
136
|
-
# ### Accept types
|
137
|
-
#
|
138
|
-
# You must request a response as JSON (`application/json`) or comma-separated
|
139
|
-
# values (`text/csv`) by specifying the **Accept** parameter. CSV output includes a
|
140
|
-
# fixed number of columns. Set the **csv_headers** parameter to `true` to request
|
141
|
-
# optional column headers for CSV output.
|
142
|
-
#
|
143
|
-
# **See also:**
|
144
|
-
# * [Understanding a JSON
|
145
|
-
# profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-output#output)
|
146
|
-
# * [Understanding a CSV
|
147
|
-
# profile](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-outputCSV#outputCSV).
|
148
|
-
# @param content [Content] A maximum of 20 MB of content to analyze, though the service requires much less
|
149
|
-
# text; for more information, see [Providing sufficient
|
150
|
-
# input](https://cloud.ibm.com/docs/personality-insights?topic=personality-insights-input#sufficient).
|
151
|
-
# For JSON input, provide an object of type `Content`.
|
152
|
-
# @param accept [String] The type of the response. For more information, see **Accept types** in the method
|
153
|
-
# description.
|
154
|
-
# @param content_type [String] The type of the input. For more information, see **Content types** in the method
|
155
|
-
# description.
|
156
|
-
# @param content_language [String] The language of the input text for the request: Arabic, English, Japanese, Korean,
|
157
|
-
# or Spanish. Regional variants are treated as their parent language; for example,
|
158
|
-
# `en-US` is interpreted as `en`.
|
159
|
-
#
|
160
|
-
# The effect of the **Content-Language** parameter depends on the **Content-Type**
|
161
|
-
# parameter. When **Content-Type** is `text/plain` or `text/html`,
|
162
|
-
# **Content-Language** is the only way to specify the language. When
|
163
|
-
# **Content-Type** is `application/json`, **Content-Language** overrides a language
|
164
|
-
# specified with the `language` parameter of a `ContentItem` object, and content
|
165
|
-
# items that specify a different language are ignored; omit this parameter to base
|
166
|
-
# the language on the specification of the content items. You can specify any
|
167
|
-
# combination of languages for **Content-Language** and **Accept-Language**.
|
168
|
-
# @param accept_language [String] The desired language of the response. For two-character arguments, regional
|
169
|
-
# variants are treated as their parent language; for example, `en-US` is interpreted
|
170
|
-
# as `en`. You can specify any combination of languages for the input and response
|
171
|
-
# content.
|
172
|
-
# @param raw_scores [Boolean] Indicates whether a raw score in addition to a normalized percentile is returned
|
173
|
-
# for each characteristic; raw scores are not compared with a sample population. By
|
174
|
-
# default, only normalized percentiles are returned.
|
175
|
-
# @param csv_headers [Boolean] Indicates whether column labels are returned with a CSV response. By default, no
|
176
|
-
# column labels are returned. Applies only when the response type is CSV
|
177
|
-
# (`text/csv`).
|
178
|
-
# @param consumption_preferences [Boolean] Indicates whether consumption preferences are returned with the results. By
|
179
|
-
# default, no consumption preferences are returned.
|
180
|
-
# @return [IBMCloudSdkCore::DetailedResponse] A `IBMCloudSdkCore::DetailedResponse` object representing the response.
|
181
|
-
def profile(content:, accept:, content_type: nil, content_language: nil, accept_language: nil, raw_scores: nil, csv_headers: nil, consumption_preferences: nil)
|
182
|
-
raise ArgumentError.new("version must be provided") if version.nil?
|
183
|
-
|
184
|
-
raise ArgumentError.new("content must be provided") if content.nil?
|
185
|
-
|
186
|
-
raise ArgumentError.new("accept must be provided") if accept.nil?
|
187
|
-
|
188
|
-
headers = {
|
189
|
-
"Accept" => accept,
|
190
|
-
"Content-Type" => content_type,
|
191
|
-
"Content-Language" => content_language,
|
192
|
-
"Accept-Language" => accept_language
|
193
|
-
}
|
194
|
-
sdk_headers = Common.new.get_sdk_headers("personality_insights", "V3", "profile")
|
195
|
-
headers.merge!(sdk_headers)
|
196
|
-
|
197
|
-
params = {
|
198
|
-
"version" => @version,
|
199
|
-
"raw_scores" => raw_scores,
|
200
|
-
"csv_headers" => csv_headers,
|
201
|
-
"consumption_preferences" => consumption_preferences
|
202
|
-
}
|
203
|
-
|
204
|
-
if content_type.start_with?("application/json") && content.instance_of?(Hash)
|
205
|
-
data = content.to_json
|
206
|
-
else
|
207
|
-
data = content
|
208
|
-
end
|
209
|
-
|
210
|
-
method_url = "/v3/profile"
|
211
|
-
|
212
|
-
response = request(
|
213
|
-
method: "POST",
|
214
|
-
url: method_url,
|
215
|
-
headers: headers,
|
216
|
-
params: params,
|
217
|
-
data: data,
|
218
|
-
accept_json: true
|
219
|
-
)
|
220
|
-
response
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|