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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -39
  3. data/lib/ibm_watson/assistant_v1.rb +5 -4
  4. data/lib/ibm_watson/assistant_v2.rb +3 -3
  5. data/lib/ibm_watson/discovery_v1.rb +7 -14
  6. data/lib/ibm_watson/discovery_v2.rb +109 -108
  7. data/lib/ibm_watson/language_translator_v3.rb +2 -2
  8. data/lib/ibm_watson/natural_language_understanding_v1.rb +12 -14
  9. data/lib/ibm_watson/speech_to_text_v1.rb +581 -402
  10. data/lib/ibm_watson/text_to_speech_v1.rb +87 -166
  11. data/lib/ibm_watson/version.rb +1 -1
  12. data/lib/ibm_watson.rb +0 -6
  13. metadata +2 -20
  14. data/lib/ibm_watson/compare_comply_v1.rb +0 -683
  15. data/lib/ibm_watson/natural_language_classifier_v1.rb +0 -258
  16. data/lib/ibm_watson/personality_insights_v3.rb +0 -223
  17. data/lib/ibm_watson/tone_analyzer_v3.rb +0 -230
  18. data/lib/ibm_watson/visual_recognition_v3.rb +0 -517
  19. data/lib/ibm_watson/visual_recognition_v4.rb +0 -930
  20. data/test/integration/test_compare_comply_v1.rb +0 -105
  21. data/test/integration/test_natural_language_classifier_v1.rb +0 -80
  22. data/test/integration/test_personality_insights_v3.rb +0 -81
  23. data/test/integration/test_tone_analyzer_v3.rb +0 -66
  24. data/test/integration/test_visual_recognition_v3.rb +0 -68
  25. data/test/integration/test_visual_recognition_v4.rb +0 -87
  26. data/test/unit/test_compare_comply_v1.rb +0 -232
  27. data/test/unit/test_natural_language_classifier_v1.rb +0 -191
  28. data/test/unit/test_personality_insights_v3.rb +0 -192
  29. data/test/unit/test_tone_analyzer_v3.rb +0 -217
  30. data/test/unit/test_visual_recognition_v3.rb +0 -300
  31. data/test/unit/test_visual_recognition_v4.rb +0 -422
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative("./../test_helper.rb")
4
- require("minitest/hooks/test")
5
- require("ibm_cloud_sdk_core")
6
-
7
- if !ENV["COMPARE_COMPLY_APIKEY"].nil?
8
- # Integration tests for the Discovery V1 Service
9
- class CompareComplyV1Test < Minitest::Test
10
- include Minitest::Hooks
11
- attr_accessor :service, :environment_id, :collection_id
12
-
13
- def before_all
14
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
15
- apikey: ENV["COMPARE_COMPLY_APIKEY"]
16
- )
17
- @service = IBMWatson::CompareComplyV1.new(
18
- version: "2018-10-15",
19
- authenticator: authenticator
20
- )
21
- @service.add_default_headers(
22
- headers: {
23
- "X-Watson-Learning-Opt-Out" => "1",
24
- "X-Watson-Test" => "1"
25
- }
26
- )
27
- end
28
-
29
- def test_convert_to_html
30
- File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
31
- response = @service.convert_to_html(
32
- file: file_info
33
- ).result
34
- refute(response.nil?)
35
- end
36
- end
37
-
38
- def test_classiffy_elements
39
- File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
40
- response = @service.classify_elements(
41
- file: file_info
42
- ).result
43
- refute(response.nil?)
44
- end
45
- end
46
-
47
- def test_extract_tables
48
- File.open(Dir.getwd + "/resources/cnc_test.pdf") do |file_info|
49
- response = @service.extract_tables(
50
- file: file_info
51
- ).result
52
- refute(response.nil?)
53
- end
54
- end
55
-
56
- def test_compare_documents
57
- file_1 = File.open(Dir.getwd + "/resources/cnc_test.pdf")
58
- file_2 = File.open(Dir.getwd + "/resources/cnc_test.pdf")
59
- response = @service.compare_documents(
60
- file_1: file_1,
61
- file_2: file_2
62
- ).result
63
- refute(response.nil?)
64
- end
65
-
66
- def test_list_feedback
67
- response = @service.list_feedback.result
68
- refute(response.nil?)
69
- end
70
-
71
- def test_get_feedback
72
- response = @service.get_feedback(
73
- feedback_id: ENV["COMPARE_COMPLY_FEEDBACK_ID"]
74
- ).result
75
- refute(response.nil?)
76
- end
77
-
78
- def test_create_batch
79
- skip "Skip to allow for concurrent travis jobs"
80
- input_file = File.open(Dir.getwd + "/resources/cnc_input_credentials_file.json")
81
- output_file = File.open(Dir.getwd + "/resources/cnc_output_credentials_file.json")
82
- response = @service.create_batch(
83
- function: "tables",
84
- input_credentials_file: input_file,
85
- input_bucket_location: "us-south",
86
- input_bucket_name: "compare-comply-integration-test-bucket-input",
87
- output_credentials_file: output_file,
88
- output_bucket_location: "us-south",
89
- output_bucket_name: "compare-comply-integration-test-bucket-output"
90
- ).result
91
- refute(response.nil?)
92
- end
93
-
94
- def test_list_batches
95
- response = @service.list_batches.result
96
- refute(response.nil?)
97
- end
98
- end
99
- else
100
- class CompareComplyV1Test < Minitest::Test
101
- def test_missing_credentials_skip_integration
102
- skip "Skip discovery integration tests because credentials have not been provided"
103
- end
104
- end
105
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("minitest/hooks/test")
6
-
7
- if !ENV["NATURAL_LANGUAGE_CLASSIFIER_APIKEY"].nil? && !ENV["NATURAL_LANGUAGE_CLASSIFIER_URL"].nil?
8
- # Integration tests for the Natural Language Classifier V1 Service
9
- class NaturalLanguageClassifierV1Test < Minitest::Test
10
- include Minitest::Hooks
11
- attr_accessor :service
12
- def before_all
13
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
14
- apikey: ENV["NATURAL_LANGUAGE_CLASSIFIER_APIKEY"]
15
- )
16
- @service = IBMWatson::NaturalLanguageClassifierV1.new(
17
- authenticator: authenticator,
18
- url: ENV["NATURAL_LANGUAGE_CLASSIFIER_URL"]
19
- )
20
- @service.add_default_headers(
21
- headers: {
22
- "X-Watson-Learning-Opt-Out" => "1",
23
- "X-Watson-Test" => "1"
24
- }
25
- )
26
- end
27
-
28
- def test_list_classifier
29
- list_classifiers = @service.list_classifiers.result
30
- refute(list_classifiers.nil?)
31
- end
32
-
33
- def test_classify_text
34
- skip "The classifier takes more than a minute"
35
- training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
36
- metadata = { "name" => "my-classifier", "language" => "en" }
37
- status = nil
38
- classifier = @service.create_classifier(
39
- metadata: metadata,
40
- training_data: training_data
41
- ).result
42
- classifier_id = classifier["classifier_id"]
43
- iterations = 0
44
- while iterations < 15
45
- status = @service.get_classifier(classifier_id: classifier_id)
46
- iterations += 1
47
- sleep(5) unless status["status"] == "Available"
48
- end
49
- unless status["status"] == "Available"
50
- @service.delete_classifier(
51
- classifier_id: classifier_id
52
- )
53
- assert(false, msg: "Classifier is not available")
54
- end
55
-
56
- classes = @service.classify(
57
- classifier_id: classifier_id,
58
- text: "How hot will it be tomorrow?"
59
- ).result
60
- refute(classes.nil?)
61
-
62
- collection = [{ "text" => "How hot will it be today?" }, { "text" => "Is it hot outside?" }]
63
- classes = @service.classify_collection(
64
- classifier_id: classifier_id,
65
- collection: collection
66
- ).result
67
- refute(classes.nil?)
68
-
69
- @service.delete_classifier(
70
- classifier_id: classifier_id
71
- )
72
- end
73
- end
74
- else
75
- class NaturalLanguageClassifierV1Test < Minitest::Test
76
- def test_missing_credentials_skip_integration
77
- skip "Skip natural language classifier integration tests because credentials have not been provided"
78
- end
79
- end
80
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
-
6
- if !ENV["PERSONALITY_INSIGHTS_APIKEY"].nil? && !ENV["PERSONALITY_INSIGHTS_URL"].nil?
7
- # Integration tests for the Personality Insights V3 Service
8
- class PersonalityInsightsV3Test < Minitest::Test
9
- include Minitest::Hooks
10
- attr_accessor :service
11
- def before_all
12
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
13
- apikey: ENV["PERSONALITY_INSIGHTS_APIKEY"]
14
- )
15
- @service = IBMWatson::PersonalityInsightsV3.new(
16
- version: "2017-10-13",
17
- url: ENV["PERSONALITY_INSIGHTS_URL"],
18
- authenticator: authenticator
19
- )
20
- @service.add_default_headers(
21
- headers: {
22
- "X-Watson-Learning-Opt-Out" => "1",
23
- "X-Watson-Test" => "1"
24
- }
25
- )
26
- end
27
-
28
- def test_plain_to_json
29
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
30
- service_response = service.profile(
31
- accept: "application/json",
32
- content: personality_text,
33
- content_type: "text/plain;charset=utf-8"
34
- )
35
- assert((200..299).cover?(service_response.status))
36
- end
37
-
38
- def test_json_to_json
39
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
40
- service_response = service.profile(
41
- accept: "application/json",
42
- content: personality_text,
43
- content_type: "application/json",
44
- raw_scores: true,
45
- consumption_preferences: true
46
- )
47
- assert((200..299).cover?(service_response.status))
48
- end
49
-
50
- def test_json_to_csv
51
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
52
- service_response = service.profile(
53
- content: personality_text,
54
- content_type: "application/json",
55
- accept: "text/csv",
56
- csv_headers: true,
57
- raw_scores: true,
58
- consumption_preferences: true
59
- )
60
- assert((200..299).cover?(service_response.status))
61
- end
62
-
63
- def test_plain_to_json_es
64
- personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
65
- service_response = service.profile(
66
- accept: "application/json",
67
- content: personality_text,
68
- content_type: "text/plain;charset=utf-8",
69
- content_language: "es",
70
- accept_language: "es"
71
- )
72
- assert((200..299).cover?(service_response.status))
73
- end
74
- end
75
- else
76
- class PersonalityInsightsV3Test < Minitest::Test
77
- def test_missing_credentials_skip_integration
78
- skip "Skip personality insights integration tests because credentials have not been provided"
79
- end
80
- end
81
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
-
6
- if !ENV["TONE_ANALYZER_APIKEY"].nil? && !ENV["TONE_ANALYZER_URL"].nil?
7
- # Integration tests for the Tone Analyzer V3 Service
8
- class ToneAnalyzerV3Test < Minitest::Test
9
- include Minitest::Hooks
10
- attr_accessor :service
11
- def before_all
12
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
13
- apikey: ENV["TONE_ANALYZER_APIKEY"]
14
- )
15
- @service = IBMWatson::ToneAnalyzerV3.new(
16
- url: ENV["TONE_ANALYZER_URL"],
17
- version: "2017-09-21",
18
- authenticator: authenticator
19
- )
20
- @service.add_default_headers(
21
- headers: {
22
- "X-Watson-Learning-Opt-Out" => "1",
23
- "X-Watson-Test" => "1"
24
- }
25
- )
26
- end
27
-
28
- def test_tone
29
- tone_text = File.read(Dir.getwd + "/resources/tone-example.json")
30
- service_response = service.tone(
31
- tone_input: tone_text,
32
- content_type: "application/json"
33
- )
34
- assert((200..299).cover?(service_response.status))
35
- end
36
-
37
- def test_tone_with_args
38
- tone_text = File.read(Dir.getwd + "/resources/tone-example.json")
39
- service_response = service.tone(
40
- tone_input: tone_text,
41
- content_type: "application/json",
42
- sentences: false
43
- )
44
- assert((200..299).cover?(service_response.status))
45
- end
46
-
47
- def test_tone_chat
48
- utterances = [
49
- {
50
- "text" => "I am very happy",
51
- "user" => "glenn"
52
- }
53
- ]
54
- service_response = service.tone_chat(
55
- utterances: utterances
56
- )
57
- assert((200..299).cover?(service_response.status))
58
- end
59
- end
60
- else
61
- class ToneAnalyzerV3Test < Minitest::Test
62
- def test_missing_credentials_skip_integration
63
- skip "Skip tone analyzer integration tests because credentials have not been provided"
64
- end
65
- end
66
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("minitest/hooks/test")
6
-
7
- if !ENV["VISUAL_RECOGNITION_APIKEY"].nil? && !ENV["VISUAL_RECOGNITION_URL"].nil?
8
- # Integration tests for the Visual Recognition V3 Service
9
- class VisualRecognitionV3Test < Minitest::Test
10
- include Minitest::Hooks
11
- attr_accessor :service, :classifier_id
12
- def before_all
13
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
14
- apikey: ENV["VISUAL_RECOGNITION_APIKEY"]
15
- )
16
- @service = IBMWatson::VisualRecognitionV3.new(
17
- version: "2018-03-19",
18
- url: ENV["VISUAL_RECOGNITION_URL"],
19
- authenticator: authenticator
20
- )
21
- @classifier_id = "doxnotxdeletexsdksxintegration_718351350"
22
- @service.add_default_headers(
23
- headers: {
24
- "X-Watson-Learning-Opt-Out" => "1",
25
- "X-Watson-Test" => "1"
26
- }
27
- )
28
- end
29
-
30
- def test_classify
31
- image_file = File.open(Dir.getwd + "/resources/dog.jpg")
32
- dog_results = @service.classify(
33
- images_file: image_file,
34
- threshold: "0.1",
35
- classifier_ids: %w[default food]
36
- ).result
37
- refute(dog_results.nil?)
38
- end
39
-
40
- def test_custom_classifier
41
- skip "Time Consuming"
42
- cars = File.open(Dir.getwd + "/resources/cars.zip")
43
- trucks = File.open(Dir.getwd + "/resources/trucks.zip")
44
- classifier = @service.create_classifier(
45
- name: "CarsVsTrucks",
46
- positive_examples: { cars: cars },
47
- negative_examples: trucks
48
- ).result
49
- refute(classifier.nil?)
50
-
51
- classifier_id = classifier["classifier_id"]
52
- output = @service.get_classifier(
53
- classifier_id: classifier_id
54
- ).result
55
- refute(output.nil?)
56
-
57
- @service.delete_classifier(
58
- classifier_id: classifier_id
59
- )
60
- end
61
- end
62
- else
63
- class VisualRecognitionV3Test < Minitest::Test
64
- def test_missing_credentials_skip_integration
65
- skip "Skip visual recognition integration tests because credentials have not been provided"
66
- end
67
- end
68
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require("json")
4
- require_relative("./../test_helper.rb")
5
- require("minitest/hooks/test")
6
-
7
- if !ENV["VISUAL_RECOGNITION_APIKEY"].nil? && !ENV["VISUAL_RECOGNITION_URL"].nil?
8
- # Integration tests for the Visual Recognition V3 Service
9
- class VisualRecognitionV4Test < Minitest::Test
10
- include Minitest::Hooks
11
- attr_accessor :service, :classifier_id
12
- def before_all
13
- authenticator = IBMWatson::Authenticators::IamAuthenticator.new(
14
- apikey: ENV["VISUAL_RECOGNITION_APIKEY"]
15
- )
16
- @service = IBMWatson::VisualRecognitionV4.new(
17
- version: "2018-03-19",
18
- url: ENV["VISUAL_RECOGNITION_URL"],
19
- authenticator: authenticator
20
- )
21
- @collection_id = ENV["VISUAL_RECOGNITION_COLLECTION_ID"]
22
- @service.add_default_headers(
23
- headers: {
24
- "X-Watson-Learning-Opt-Out" => "1",
25
- "X-Watson-Test" => "1"
26
- }
27
- )
28
- end
29
-
30
- def test_analyze
31
- image_file = File.open(Dir.getwd + "/resources/dog.jpg")
32
- image_file_1 = File.open(Dir.getwd + "/resources/face.jpg")
33
- result = @service.analyze(
34
- images_file: [
35
- {
36
- "data": image_file,
37
- "filename": "dog.jpg",
38
- "content_type": "image/jpeg"
39
- },
40
- {
41
- "data": image_file_1,
42
- "filename": "face.jpg",
43
- "content_type": "image/jpeg"
44
- }
45
- ],
46
- collection_ids: [@collection_id],
47
- features: ["objects"]
48
- ).result
49
- assert_equal(2, result["images"].length)
50
- refute(result.nil?)
51
- end
52
-
53
- def test_list_collections
54
- result = @service.list_collections.result
55
- refute(result.nil?)
56
- end
57
-
58
- def test_get_collection
59
- result = @service.get_collection(
60
- collection_id: @collection_id
61
- ).result
62
- refute(result.nil?)
63
- end
64
-
65
- def test_list_images
66
- result = @service.list_images(
67
- collection_id: @collection_id
68
- ).result
69
- refute(result.nil?)
70
- end
71
-
72
- def test_get_model_file
73
- result = @service.get_model_file(
74
- collection_id: @collection_id,
75
- feature: "objects",
76
- model_format: "rscnn"
77
- ).result
78
- refute(result.nil?)
79
- end
80
- end
81
- else
82
- class VisualRecognitionV4Test < Minitest::Test
83
- def test_missing_credentials_skip_integration
84
- skip "Skip visual recognition integration tests because credentials have not been provided"
85
- end
86
- end
87
- end