ibm_watson 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,78 +4,80 @@ require("json")
4
4
  require_relative("./../test_helper.rb")
5
5
  require("minitest/hooks/test")
6
6
 
7
- # Integration tests for the Language Translator V3 Service
8
- class LanguageTranslatorV3Test < Minitest::Test
9
- include Minitest::Hooks
10
- attr_accessor :service
11
- def before_all
12
- @service = IBMWatson::LanguageTranslatorV3.new(
13
- username: ENV["LANGUAGE_TRANSLATOR_V3_USERNAME"],
14
- password: ENV["LANGUAGE_TRANSLATOR_V3_PASSWORD"],
15
- version: "2018-05-01"
16
- )
17
- @service.add_default_headers(
18
- headers: {
19
- "X-Watson-Learning-Opt-Out" => "1",
20
- "X-Watson-Test" => "1"
21
- }
22
- )
23
- end
7
+ unless ENV["LANGUAGE_TRANSLATOR_V3_USERNAME"].nil? || ENV["LANGUAGE_TRANSLATOR_V3_PASSWORD"].nil?
8
+ # Integration tests for the Language Translator V3 Service
9
+ class LanguageTranslatorV3Test < Minitest::Test
10
+ include Minitest::Hooks
11
+ attr_accessor :service
12
+ def before_all
13
+ @service = IBMWatson::LanguageTranslatorV3.new(
14
+ username: ENV["LANGUAGE_TRANSLATOR_V3_USERNAME"],
15
+ password: ENV["LANGUAGE_TRANSLATOR_V3_PASSWORD"],
16
+ version: "2018-05-01"
17
+ )
18
+ @service.add_default_headers(
19
+ headers: {
20
+ "X-Watson-Learning-Opt-Out" => "1",
21
+ "X-Watson-Test" => "1"
22
+ }
23
+ )
24
+ end
24
25
 
25
- def test_get_model
26
- service_response = service.get_model(
27
- model_id: "en-it"
28
- ).result
29
- refute(service_response.nil?)
30
- end
26
+ def test_get_model
27
+ service_response = service.get_model(
28
+ model_id: "en-it"
29
+ ).result
30
+ refute(service_response.nil?)
31
+ end
31
32
 
32
- def test_list_models
33
- service_response = service.list_models.result
34
- refute(service_response.nil?)
35
- end
33
+ def test_list_models
34
+ service_response = service.list_models.result
35
+ refute(service_response.nil?)
36
+ end
36
37
 
37
- def test_translate_source_target
38
- service_response = service.translate(
39
- text: "Hola, cómo estás? €",
40
- source: "es",
41
- target: "en"
42
- ).result
43
- refute(service_response.nil?)
44
- end
38
+ def test_translate_source_target
39
+ service_response = service.translate(
40
+ text: "Hola, cómo estás? €",
41
+ source: "es",
42
+ target: "en"
43
+ ).result
44
+ refute(service_response.nil?)
45
+ end
45
46
 
46
- def test_translate_model_id
47
- service_response = service.translate(
48
- text: "Messi is the best ever",
49
- model_id: "en-es"
50
- ).result
51
- refute(service_response.nil?)
52
- end
47
+ def test_translate_model_id
48
+ service_response = service.translate(
49
+ text: "Messi is the best ever",
50
+ model_id: "en-es"
51
+ ).result
52
+ refute(service_response.nil?)
53
+ end
53
54
 
54
- def test_identify
55
- service_response = service.identify(
56
- text: "祝你有美好的一天"
57
- ).result
58
- refute(service_response.nil?)
59
- end
55
+ def test_identify
56
+ service_response = service.identify(
57
+ text: "祝你有美好的一天"
58
+ ).result
59
+ refute(service_response.nil?)
60
+ end
60
61
 
61
- def test_list_identifiable_languages
62
- service_response = service.list_identifiable_languages.result
63
- refute(service_response.nil?)
64
- end
62
+ def test_list_identifiable_languages
63
+ service_response = service.list_identifiable_languages.result
64
+ refute(service_response.nil?)
65
+ end
65
66
 
66
- def test_create_delete_model
67
- skip "Methods not available in lite plans"
68
- custom_model = File.open(Dir.getwd + "/resources/language_translator_model.tmx")
69
- service_response = service.create_model(
70
- base_model_id: "en-fr",
71
- name: "test_glossary_ruby_integration",
72
- forced_glossary: custom_model
73
- ).result
74
- refute(service_response.nil?)
75
- model_id = service_response["model_id"]
76
- service_response = service.delete_model(
77
- model_id: model_id
78
- ).result
79
- assert_equal("OK", service_response["status"])
67
+ def test_create_delete_model
68
+ skip "Methods not available in lite plans"
69
+ custom_model = File.open(Dir.getwd + "/resources/language_translator_model.tmx")
70
+ service_response = service.create_model(
71
+ base_model_id: "en-fr",
72
+ name: "test_glossary_ruby_integration",
73
+ forced_glossary: custom_model
74
+ ).result
75
+ refute(service_response.nil?)
76
+ model_id = service_response["model_id"]
77
+ service_response = service.delete_model(
78
+ model_id: model_id
79
+ ).result
80
+ assert_equal("OK", service_response["status"])
81
+ end
80
82
  end
81
83
  end
@@ -4,66 +4,68 @@ require("json")
4
4
  require_relative("./../test_helper.rb")
5
5
  require("minitest/hooks/test")
6
6
 
7
- # Integration tests for the Natural Language Classifier V1 Service
8
- class NaturalLanguageClassifierV1Test < Minitest::Test
9
- include Minitest::Hooks
10
- attr_accessor :service
11
- def before_all
12
- @service = IBMWatson::NaturalLanguageClassifierV1.new(
13
- username: ENV["NATURAL_LANGUAGE_CLASSIFIER_USERNAME"],
14
- password: ENV["NATURAL_LANGUAGE_CLASSIFIER_PASSWORD"]
15
- )
16
- @service.add_default_headers(
17
- headers: {
18
- "X-Watson-Learning-Opt-Out" => "1",
19
- "X-Watson-Test" => "1"
20
- }
21
- )
22
- end
23
-
24
- def test_list_classifier
25
- list_classifiers = @service.list_classifiers.result
26
- refute(list_classifiers.nil?)
27
- end
7
+ unless ENV["NATURAL_LANGUAGE_CLASSIFIER_USERNAME"].nil? || ENV["NATURAL_LANGUAGE_CLASSIFIER_PASSWORD"].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
+ @service = IBMWatson::NaturalLanguageClassifierV1.new(
14
+ username: ENV["NATURAL_LANGUAGE_CLASSIFIER_USERNAME"],
15
+ password: ENV["NATURAL_LANGUAGE_CLASSIFIER_PASSWORD"]
16
+ )
17
+ @service.add_default_headers(
18
+ headers: {
19
+ "X-Watson-Learning-Opt-Out" => "1",
20
+ "X-Watson-Test" => "1"
21
+ }
22
+ )
23
+ end
28
24
 
29
- def test_classify_text
30
- skip "The classifier takes more than a minute"
31
- training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
32
- metadata = { "name" => "my-classifier", "language" => "en" }
33
- status = nil
34
- classifier = @service.create_classifier(
35
- metadata: metadata,
36
- training_data: training_data
37
- ).result
38
- classifier_id = classifier["classifier_id"]
39
- iterations = 0
40
- while iterations < 15
41
- status = @service.get_classifier(classifier_id: classifier_id)
42
- iterations += 1
43
- sleep(5) unless status["status"] == "Available"
25
+ def test_list_classifier
26
+ list_classifiers = @service.list_classifiers.result
27
+ refute(list_classifiers.nil?)
44
28
  end
45
- unless status["status"] == "Available"
29
+
30
+ def test_classify_text
31
+ skip "The classifier takes more than a minute"
32
+ training_data = File.open(Dir.getwd + "/resources/weather_data_train.csv")
33
+ metadata = { "name" => "my-classifier", "language" => "en" }
34
+ status = nil
35
+ classifier = @service.create_classifier(
36
+ metadata: metadata,
37
+ training_data: training_data
38
+ ).result
39
+ classifier_id = classifier["classifier_id"]
40
+ iterations = 0
41
+ while iterations < 15
42
+ status = @service.get_classifier(classifier_id: classifier_id)
43
+ iterations += 1
44
+ sleep(5) unless status["status"] == "Available"
45
+ end
46
+ unless status["status"] == "Available"
47
+ @service.delete_classifier(
48
+ classifier_id: classifier_id
49
+ )
50
+ assert(false, msg: "Classifier is not available")
51
+ end
52
+
53
+ classes = @service.classify(
54
+ classifier_id: classifier_id,
55
+ text: "How hot will it be tomorrow?"
56
+ ).result
57
+ refute(classes.nil?)
58
+
59
+ collection = [{ "text" => "How hot will it be today?" }, { "text" => "Is it hot outside?" }]
60
+ classes = @service.classify_collection(
61
+ classifier_id: classifier_id,
62
+ collection: collection
63
+ ).result
64
+ refute(classes.nil?)
65
+
46
66
  @service.delete_classifier(
47
67
  classifier_id: classifier_id
48
68
  )
49
- assert(false, msg: "Classifier is not available")
50
69
  end
51
-
52
- classes = @service.classify(
53
- classifier_id: classifier_id,
54
- text: "How hot will it be tomorrow?"
55
- ).result
56
- refute(classes.nil?)
57
-
58
- collection = [{ "text" => "How hot will it be today?" }, { "text" => "Is it hot outside?" }]
59
- classes = @service.classify_collection(
60
- classifier_id: classifier_id,
61
- collection: collection
62
- ).result
63
- refute(classes.nil?)
64
-
65
- @service.delete_classifier(
66
- classifier_id: classifier_id
67
- )
68
70
  end
69
71
  end
@@ -3,96 +3,98 @@
3
3
  require("json")
4
4
  require_relative("./../test_helper.rb")
5
5
 
6
- # Integration tests for the Natural Language Understanding V1 Service
7
- class NaturalLanguageUnderstandingV1Test < Minitest::Test
8
- def test_text_analyze
9
- service = IBMWatson::NaturalLanguageUnderstandingV1.new(
10
- version: "2018-03-16",
11
- username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
12
- password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
13
- )
14
- service.add_default_headers(
15
- headers: {
16
- "X-Watson-Learning-Opt-Out" => "1",
17
- "X-Watson-Test" => "1"
18
- }
19
- )
20
- text = "IBM is an American multinational technology company "
21
- text += "headquartered in Armonk, New York, United States, "
22
- text += "with operations in over 170 countries."
23
- service_response = service.analyze(
24
- features: {
25
- entities: {
26
- emotion: true,
27
- sentiment: true,
28
- limit: 2
29
- },
30
- keywords: {
31
- emotion: true,
32
- sentiment: true,
33
- limit: 2
6
+ unless ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"].nil? || ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"].nil?
7
+ # Integration tests for the Natural Language Understanding V1 Service
8
+ class NaturalLanguageUnderstandingV1Test < Minitest::Test
9
+ def test_text_analyze
10
+ service = IBMWatson::NaturalLanguageUnderstandingV1.new(
11
+ version: "2018-03-16",
12
+ username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
13
+ password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
14
+ )
15
+ service.add_default_headers(
16
+ headers: {
17
+ "X-Watson-Learning-Opt-Out" => "1",
18
+ "X-Watson-Test" => "1"
34
19
  }
35
- },
36
- text: text
37
- )
38
- assert((200..299).cover?(service_response.status))
39
- end
20
+ )
21
+ text = "IBM is an American multinational technology company "
22
+ text += "headquartered in Armonk, New York, United States, "
23
+ text += "with operations in over 170 countries."
24
+ service_response = service.analyze(
25
+ features: {
26
+ entities: {
27
+ emotion: true,
28
+ sentiment: true,
29
+ limit: 2
30
+ },
31
+ keywords: {
32
+ emotion: true,
33
+ sentiment: true,
34
+ limit: 2
35
+ }
36
+ },
37
+ text: text
38
+ )
39
+ assert((200..299).cover?(service_response.status))
40
+ end
40
41
 
41
- def test_html_analyze
42
- service = IBMWatson::NaturalLanguageUnderstandingV1.new(
43
- version: "2018-03-16",
44
- username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
45
- password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
46
- )
47
- service.add_default_headers(
48
- headers: {
49
- "X-Watson-Learning-Opt-Out" => "1",
50
- "X-Watson-Test" => "1"
51
- }
52
- )
53
- service_response = service.analyze(
54
- features: {
55
- sentiment: {}
56
- },
57
- html: "<span>hello this is a test </span>"
58
- )
59
- assert((200..299).cover?(service_response.status))
60
- end
42
+ def test_html_analyze
43
+ service = IBMWatson::NaturalLanguageUnderstandingV1.new(
44
+ version: "2018-03-16",
45
+ username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
46
+ password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
47
+ )
48
+ service.add_default_headers(
49
+ headers: {
50
+ "X-Watson-Learning-Opt-Out" => "1",
51
+ "X-Watson-Test" => "1"
52
+ }
53
+ )
54
+ service_response = service.analyze(
55
+ features: {
56
+ sentiment: {}
57
+ },
58
+ html: "<span>hello this is a test </span>"
59
+ )
60
+ assert((200..299).cover?(service_response.status))
61
+ end
61
62
 
62
- def test_url_analyze
63
- service = IBMWatson::NaturalLanguageUnderstandingV1.new(
64
- version: "2018-03-16",
65
- username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
66
- password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
67
- )
68
- service.add_default_headers(
69
- headers: {
70
- "X-Watson-Learning-Opt-Out" => "1",
71
- "X-Watson-Test" => "1"
72
- }
73
- )
74
- service_response = service.analyze(
75
- features: {
76
- categories: {}
77
- },
78
- url: "www.ibm.com"
79
- )
80
- assert((200..299).cover?(service_response.status))
81
- end
63
+ def test_url_analyze
64
+ service = IBMWatson::NaturalLanguageUnderstandingV1.new(
65
+ version: "2018-03-16",
66
+ username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
67
+ password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
68
+ )
69
+ service.add_default_headers(
70
+ headers: {
71
+ "X-Watson-Learning-Opt-Out" => "1",
72
+ "X-Watson-Test" => "1"
73
+ }
74
+ )
75
+ service_response = service.analyze(
76
+ features: {
77
+ categories: {}
78
+ },
79
+ url: "www.ibm.com"
80
+ )
81
+ assert((200..299).cover?(service_response.status))
82
+ end
82
83
 
83
- def test_list_models
84
- service = IBMWatson::NaturalLanguageUnderstandingV1.new(
85
- version: "2018-03-16",
86
- username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
87
- password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
88
- )
89
- service.add_default_headers(
90
- headers: {
91
- "X-Watson-Learning-Opt-Out" => "1",
92
- "X-Watson-Test" => "1"
93
- }
94
- )
95
- service_response = service.list_models
96
- assert((200..299).cover?(service_response.status))
84
+ def test_list_models
85
+ service = IBMWatson::NaturalLanguageUnderstandingV1.new(
86
+ version: "2018-03-16",
87
+ username: ENV["NATURAL_LANGUAGE_UNDERSTANDING_USERNAME"],
88
+ password: ENV["NATURAL_LANGUAGE_UNDERSTANDING_PASSWORD"]
89
+ )
90
+ service.add_default_headers(
91
+ headers: {
92
+ "X-Watson-Learning-Opt-Out" => "1",
93
+ "X-Watson-Test" => "1"
94
+ }
95
+ )
96
+ service_response = service.list_models
97
+ assert((200..299).cover?(service_response.status))
98
+ end
97
99
  end
98
100
  end
@@ -3,93 +3,95 @@
3
3
  require("json")
4
4
  require_relative("./../test_helper.rb")
5
5
 
6
- # Integration tests for the Personality Insights V3 Service
7
- class PersonalityInsightsV3Test < Minitest::Test
8
- def test_plain_to_json
9
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
10
- service = IBMWatson::PersonalityInsightsV3.new(
11
- version: "2017-10-13",
12
- username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
13
- password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
14
- )
15
- service.add_default_headers(
16
- headers: {
17
- "X-Watson-Learning-Opt-Out" => "1",
18
- "X-Watson-Test" => "1"
19
- }
20
- )
21
- service_response = service.profile(
22
- content: personality_text,
23
- content_type: "text/plain;charset=utf-8"
24
- )
25
- assert((200..299).cover?(service_response.status))
26
- end
6
+ unless ENV["PERSONALITY_INSIGHTS_USERNAME"].nil? || ENV["PERSONALITY_INSIGHTS_PASSWORD"].nil?
7
+ # Integration tests for the Personality Insights V3 Service
8
+ class PersonalityInsightsV3Test < Minitest::Test
9
+ def test_plain_to_json
10
+ personality_text = File.read(Dir.getwd + "/resources/personality-v3.txt")
11
+ service = IBMWatson::PersonalityInsightsV3.new(
12
+ version: "2017-10-13",
13
+ username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
14
+ password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
15
+ )
16
+ service.add_default_headers(
17
+ headers: {
18
+ "X-Watson-Learning-Opt-Out" => "1",
19
+ "X-Watson-Test" => "1"
20
+ }
21
+ )
22
+ service_response = service.profile(
23
+ content: personality_text,
24
+ content_type: "text/plain;charset=utf-8"
25
+ )
26
+ assert((200..299).cover?(service_response.status))
27
+ end
27
28
 
28
- def test_json_to_json
29
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
30
- service = IBMWatson::PersonalityInsightsV3.new(
31
- version: "2017-10-13",
32
- username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
33
- password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
34
- )
35
- service.add_default_headers(
36
- headers: {
37
- "X-Watson-Learning-Opt-Out" => "1",
38
- "X-Watson-Test" => "1"
39
- }
40
- )
41
- service_response = service.profile(
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
29
+ def test_json_to_json
30
+ personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
31
+ service = IBMWatson::PersonalityInsightsV3.new(
32
+ version: "2017-10-13",
33
+ username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
34
+ password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
35
+ )
36
+ service.add_default_headers(
37
+ headers: {
38
+ "X-Watson-Learning-Opt-Out" => "1",
39
+ "X-Watson-Test" => "1"
40
+ }
41
+ )
42
+ service_response = service.profile(
43
+ content: personality_text,
44
+ content_type: "application/json",
45
+ raw_scores: true,
46
+ consumption_preferences: true
47
+ )
48
+ assert((200..299).cover?(service_response.status))
49
+ end
49
50
 
50
- def test_json_to_csv
51
- personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
52
- service = IBMWatson::PersonalityInsightsV3.new(
53
- version: "2017-10-13",
54
- username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
55
- password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
56
- )
57
- service.add_default_headers(
58
- headers: {
59
- "X-Watson-Learning-Opt-Out" => "1",
60
- "X-Watson-Test" => "1"
61
- }
62
- )
63
- service_response = service.profile(
64
- content: personality_text,
65
- content_type: "application/json",
66
- accept: "text/csv",
67
- csv_headers: true,
68
- raw_scores: true,
69
- consumption_preferences: true
70
- )
71
- assert((200..299).cover?(service_response.status))
72
- end
51
+ def test_json_to_csv
52
+ personality_text = File.read(Dir.getwd + "/resources/personality-v3.json")
53
+ service = IBMWatson::PersonalityInsightsV3.new(
54
+ version: "2017-10-13",
55
+ username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
56
+ password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
57
+ )
58
+ service.add_default_headers(
59
+ headers: {
60
+ "X-Watson-Learning-Opt-Out" => "1",
61
+ "X-Watson-Test" => "1"
62
+ }
63
+ )
64
+ service_response = service.profile(
65
+ content: personality_text,
66
+ content_type: "application/json",
67
+ accept: "text/csv",
68
+ csv_headers: true,
69
+ raw_scores: true,
70
+ consumption_preferences: true
71
+ )
72
+ assert((200..299).cover?(service_response.status))
73
+ end
73
74
 
74
- def test_plain_to_json_es
75
- personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
76
- service = IBMWatson::PersonalityInsightsV3.new(
77
- version: "2017-10-13",
78
- username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
79
- password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
80
- )
81
- service.add_default_headers(
82
- headers: {
83
- "X-Watson-Learning-Opt-Out" => "1",
84
- "X-Watson-Test" => "1"
85
- }
86
- )
87
- service_response = service.profile(
88
- content: personality_text,
89
- content_type: "text/plain;charset=utf-8",
90
- content_language: "es",
91
- accept_language: "es"
92
- )
93
- assert((200..299).cover?(service_response.status))
75
+ def test_plain_to_json_es
76
+ personality_text = File.read(Dir.getwd + "/resources/personality-v3-es.txt")
77
+ service = IBMWatson::PersonalityInsightsV3.new(
78
+ version: "2017-10-13",
79
+ username: ENV["PERSONALITY_INSIGHTS_USERNAME"],
80
+ password: ENV["PERSONALITY_INSIGHTS_PASSWORD"]
81
+ )
82
+ service.add_default_headers(
83
+ headers: {
84
+ "X-Watson-Learning-Opt-Out" => "1",
85
+ "X-Watson-Test" => "1"
86
+ }
87
+ )
88
+ service_response = service.profile(
89
+ content: personality_text,
90
+ content_type: "text/plain;charset=utf-8",
91
+ content_language: "es",
92
+ accept_language: "es"
93
+ )
94
+ assert((200..299).cover?(service_response.status))
95
+ end
94
96
  end
95
97
  end