watson-conversation 0.1.3 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/watson/conversation.rb +79 -18
- data/lib/watson/conversation/version.rb +1 -1
- data/watson-conversation.gemspec +1 -1
- metadata +3 -6
- data/hoge.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f419989bfc6287a190e81de6e29da7137ab1c5a
|
4
|
+
data.tar.gz: 2b8dda9b003b5e96150f6f555f3bb25ee0cf69ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0906c61f4b767df75c3d481dcc225cb6a2e713d18b7ff73b46cdc1883db9565fbf3fd34c4b661e15ac3e79ca12a7920b0e533745f6193719232a0ea0866adb2
|
7
|
+
data.tar.gz: a56a7811d1ccb62d9ebf7803514e15d98354f53da7eaf21274194c6038f07deb7dde5fa24eb0c232a386537e8a9933a8b9992b3afc7ec1f459c6d8e91fa4d189
|
data/lib/watson/conversation.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "watson/conversation/version"
|
2
2
|
require 'rest-client'
|
3
3
|
require "json"
|
4
|
+
require "thread"
|
5
|
+
|
4
6
|
|
5
|
-
|
6
7
|
module Watson
|
7
8
|
module Conversation
|
8
9
|
|
@@ -13,9 +14,11 @@ module Watson
|
|
13
14
|
|
14
15
|
@endpoint = "#{url}/v1/workspaces/#{workspace_id}/message?version=#{version}"
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
|
18
19
|
def talk(question, context)
|
20
|
+
future_data = FutureData.new()
|
21
|
+
|
19
22
|
if context == ""
|
20
23
|
body = {}.to_json
|
21
24
|
else
|
@@ -28,22 +31,69 @@ module Watson
|
|
28
31
|
}.to_json
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
|
35
|
+
Thread.start do
|
36
|
+
begin
|
37
|
+
response = RestClient.post @endpoint, body, content_type: :json, accept: :json
|
38
|
+
code = response.code
|
39
|
+
body = JSON.parse(response.body)
|
40
|
+
rescue RestClient::ExceptionWithResponse => e
|
41
|
+
code = e.response.code
|
42
|
+
body = e.response.body
|
43
|
+
end
|
44
|
+
future_data.setRealData(code, body)
|
38
45
|
end
|
39
46
|
|
47
|
+
return future_data
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def getData()
|
40
52
|
return code, body
|
41
53
|
end
|
42
54
|
end
|
55
|
+
|
56
|
+
|
57
|
+
class FutureData
|
58
|
+
def initialize()
|
59
|
+
@is_ready = false
|
60
|
+
@real_data = nil
|
61
|
+
|
62
|
+
@mutex = Mutex.new
|
63
|
+
@cv = ConditionVariable.new
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def setRealData(code, body)
|
68
|
+
@mutex.synchronize do
|
69
|
+
if (@is_ready == true)
|
70
|
+
return
|
71
|
+
end
|
72
|
+
end
|
43
73
|
|
74
|
+
@real_data = code, body
|
75
|
+
@is_ready = true
|
76
|
+
|
77
|
+
@cv.broadcast
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def getData()
|
82
|
+
@mutex.synchronize do
|
83
|
+
while (@is_ready == false)
|
84
|
+
@cv.wait(@mutex)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
return @real_data
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
44
91
|
|
92
|
+
|
45
93
|
class ManageDialog
|
46
94
|
def initialize(username: "", password: "", workspace_id: "")
|
95
|
+
@mutex = Mutex.new
|
96
|
+
|
47
97
|
@cnv = Dialog.new(
|
48
98
|
username: username,
|
49
99
|
password: password,
|
@@ -55,24 +105,35 @@ module Watson
|
|
55
105
|
|
56
106
|
|
57
107
|
def talk(user, question)
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
108
|
+
future_data = nil
|
109
|
+
@mutex.synchronize do
|
110
|
+
if @users.key?(user) == false
|
111
|
+
future_data = @cnv.talk("", "")
|
112
|
+
else
|
113
|
+
future_data = @cnv.talk(question, context = @users[user])
|
114
|
+
end
|
62
115
|
end
|
63
116
|
|
64
|
-
|
117
|
+
code, response = future_data.getData()
|
118
|
+
|
119
|
+
output_texts = []
|
65
120
|
if code == 200
|
66
121
|
context = response["context"]
|
67
|
-
@users[user] = context
|
68
|
-
|
69
|
-
output_texts = Array.new
|
70
122
|
response["output"]["text"].each do | output_text |
|
71
123
|
output_texts.push(output_text)
|
72
124
|
end
|
73
125
|
end
|
74
126
|
|
75
|
-
|
127
|
+
|
128
|
+
@mutex.synchronize do
|
129
|
+
if code == 200
|
130
|
+
@users[user] = context
|
131
|
+
else
|
132
|
+
@users.delete(user)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
return {user: user, status_code: code, output: output_texts}.to_json
|
76
137
|
end
|
77
138
|
end
|
78
139
|
|
data/watson-conversation.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["alpha.netzilla@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Client library to use the IBM Watson Conversation service}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{Client library to use the IBM Watson Conversation service}
|
14
14
|
spec.homepage = "https://github.com/alpha-netzilla/watson-conversation.git"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watson-conversation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alpha.netzilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,9 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '2.0'
|
83
|
-
description:
|
84
|
-
and uses machine learning to respond to customers in a way that simulates a conversation
|
85
|
-
between humans.
|
83
|
+
description: Client library to use the IBM Watson Conversation service
|
86
84
|
email:
|
87
85
|
- alpha.netzilla@gmail.com
|
88
86
|
executables: []
|
@@ -99,7 +97,6 @@ files:
|
|
99
97
|
- Rakefile
|
100
98
|
- bin/console
|
101
99
|
- bin/setup
|
102
|
-
- hoge.rb
|
103
100
|
- lib/watson/conversation.rb
|
104
101
|
- lib/watson/conversation/version.rb
|
105
102
|
- watson-conversation.gemspec
|
data/hoge.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require './lib/watson/conversation'
|
2
|
-
|
3
|
-
manage = Watson::Conversation::ManageDialog.new(
|
4
|
-
username: "2dc1e553-7caf-42a6-9566-7b09563973b6",
|
5
|
-
password: "scXHOmBTv5Po",
|
6
|
-
workspace_id: "3efc86e6-ba1b-425a-a3f1-3dd69d4f2432"
|
7
|
-
)
|
8
|
-
|
9
|
-
p response = manage.talk("Smith", "")
|
10
|
-
p response = manage.talk("Smith", "料金案内")
|
11
|
-
p response = manage.talk("Smith", "当月")
|
12
|
-
p response = manage.talk("Smith", "090-1234-1234")
|
13
|
-
p response = manage.talk("Smith", "1234")
|
14
|
-
p response = manage.talk("Smith2", "")
|
15
|
-
p response = manage.talk("Smith", "はい")
|
16
|
-
p response = manage.talk("Smith", "はい")
|