mocodo 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/example/example.rb +198 -0
- data/lib/mocodo.rb +9 -7
- data/lib/mocodo/base.rb +56 -0
- data/lib/mocodo/character_recognition.rb +49 -169
- data/lib/mocodo/dialogue.rb +14 -39
- data/lib/mocodo/goo_language_analysis.rb +37 -141
- data/lib/mocodo/image_recognition.rb +13 -38
- data/lib/mocodo/knowledge_qa.rb +6 -17
- data/lib/mocodo/mountain_identification.rb +31 -0
- data/lib/mocodo/scenario_dialogue.rb +17 -0
- data/lib/mocodo/sentence_understanding.rb +4 -47
- data/lib/mocodo/text_to_speech.rb +53 -71
- data/lib/mocodo/version.rb +1 -1
- data/lib/mocodo/web_curation.rb +20 -63
- metadata +19 -17
- data/example/hqdefault.jpg +0 -0
- data/example/mocodo-example.rb +0 -134
- data/lib/mocodo/client.rb +0 -15
data/lib/mocodo/dialogue.rb
CHANGED
@@ -1,51 +1,26 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module Mocodo
|
5
|
-
class Dialogue
|
6
|
-
|
2
|
+
class Dialogue < Base
|
3
|
+
EndPoint = "/dialogue/v1/dialogue"
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
attr_reader :config
|
6
|
+
def initialize(*args)
|
7
|
+
super
|
8
|
+
@config = {}
|
11
9
|
end
|
12
|
-
|
10
|
+
|
13
11
|
def configure(options = {})
|
14
|
-
options
|
15
|
-
self.config[key] = value
|
16
|
-
end
|
12
|
+
@config.merge!(options)
|
17
13
|
end
|
18
14
|
|
19
15
|
def get_current_data(option=nil)
|
20
|
-
|
21
|
-
return self.config
|
22
|
-
else
|
23
|
-
return self.config[option]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def build_body(talk)
|
28
|
-
body = {}
|
29
|
-
self.config.each { |sym|
|
30
|
-
body[sym[0].id2name] = sym[1]
|
31
|
-
}
|
32
|
-
body['utt'] = talk
|
33
|
-
return body.to_json
|
16
|
+
option.nil? ? @config : @config[option]
|
34
17
|
end
|
35
|
-
|
36
|
-
def create_dialogue
|
37
|
-
|
38
|
-
|
39
|
-
http.use_ssl = true
|
40
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
|
41
|
-
request.body = build_body(talk)
|
42
|
-
response = nil
|
43
|
-
http.start do |h|
|
44
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
45
|
-
end
|
18
|
+
|
19
|
+
def create_dialogue(talk)
|
20
|
+
response = post(build_url(EndPoint), @config.merge(utt: talk).to_json, {'Content-Type' =>'application/json'})
|
21
|
+
response = JSON.parse(response, symbolize_names: true)
|
46
22
|
configure(response)
|
47
|
-
self.config.delete(:utt)
|
48
23
|
return response[:utt]
|
49
|
-
|
24
|
+
end
|
50
25
|
end
|
51
26
|
end
|
@@ -1,165 +1,61 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module Mocodo
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
self.config_m = self.config_e = self.config_s = self.config_h = {}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class Morph < GooLanguageAnalysis
|
15
|
-
def configure(options = {})
|
16
|
-
options.each do |key, value|
|
17
|
-
self.config_m[key] = value
|
2
|
+
module LanguageAnalysis
|
3
|
+
class Morph < Base
|
4
|
+
EndPoint = "/gooLanguageAnalysis/v1/morph"
|
5
|
+
def analysis(options={})
|
6
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
18
7
|
end
|
19
8
|
end
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return self.config_m[option]
|
10
|
+
class Entity < Base
|
11
|
+
EndPoint = "/gooLanguageAnalysis/v1/entity"
|
12
|
+
def extract(options={})
|
13
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
26
14
|
end
|
27
15
|
end
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
body['sentence'] = sentence
|
35
|
-
return body.to_json
|
36
|
-
end
|
37
|
-
|
38
|
-
def morph sentence
|
39
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/morph?APIKEY=#{@client.get_api_key}")
|
40
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
41
|
-
http.use_ssl = true
|
42
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
|
43
|
-
request.body = build_body(sentence)
|
44
|
-
response = nil
|
45
|
-
http.start do |h|
|
46
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
47
|
-
end
|
48
|
-
return response[:word_list]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Entity < GooLanguageAnalysis
|
53
|
-
def configure(options = {})
|
54
|
-
options.each do |key, value|
|
55
|
-
self.config_e[key] = value
|
17
|
+
class Similarity < Base
|
18
|
+
EndPoint = "/gooLanguageAnalysis/v1/similarity"
|
19
|
+
def calculate(options={})
|
20
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
56
21
|
end
|
57
22
|
end
|
58
23
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return self.config_e[option]
|
24
|
+
class Hiragana < Base
|
25
|
+
EndPoint = "/gooLanguageAnalysis/v1/hiragana"
|
26
|
+
def convert(options={})
|
27
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
64
28
|
end
|
65
29
|
end
|
66
30
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
72
|
-
body['sentence'] = sentence
|
73
|
-
return body.to_json
|
74
|
-
end
|
75
|
-
|
76
|
-
def entity sentence
|
77
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/entity?APIKEY=#{@client.get_api_key}")
|
78
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
79
|
-
http.use_ssl = true
|
80
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
|
81
|
-
request.body = build_body(sentence)
|
82
|
-
response = nil
|
83
|
-
http.start do |h|
|
84
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
85
|
-
end
|
86
|
-
return response[:ne_list]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class Similarity < GooLanguageAnalysis
|
91
|
-
def configure(options = {})
|
92
|
-
options.each do |key, value|
|
93
|
-
self.config_s[key] = value
|
31
|
+
class Shortsum < Base
|
32
|
+
EndPoint = "/gooLanguageAnalysisCorp/v1/shortsum"
|
33
|
+
def sum(options={})
|
34
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
94
35
|
end
|
95
36
|
end
|
96
37
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
return self.config_s[option]
|
38
|
+
class Keyword < Base
|
39
|
+
EndPoint = "/gooLanguageAnalysisCorp/v1/keyword"
|
40
|
+
def extract(options={})
|
41
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
102
42
|
end
|
103
43
|
end
|
104
44
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
return body.to_json
|
112
|
-
end
|
113
|
-
|
114
|
-
def similarity(sentence1, sentence2)
|
115
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/similarity?APIKEY=#{@client.get_api_key}")
|
116
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
117
|
-
http.use_ssl = true
|
118
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
|
119
|
-
request.body = build_body(sentence1, sentence2)
|
120
|
-
response = nil
|
121
|
-
http.start do |h|
|
122
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
123
|
-
end
|
124
|
-
return response[:score]
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class Hiragana < GooLanguageAnalysis
|
129
|
-
def configure(options = {})
|
130
|
-
options.each do |key, value|
|
131
|
-
self.config_h[key] = value
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def get_current_data(option=nil)
|
136
|
-
if option.nil?
|
137
|
-
return self.config_h
|
138
|
-
else
|
139
|
-
return self.config_h[option]
|
45
|
+
module Truetext
|
46
|
+
class Clusteranalytics < Base
|
47
|
+
EndPoint = "/truetext/v1/clusteranalytics"
|
48
|
+
def analysis(options={})
|
49
|
+
post(build_url(EndPoint), build_params(options.merge(text: URI.escape(options[:text]))), {'Content-Type' =>'application/x-www-form-urlencoded'})
|
50
|
+
end
|
140
51
|
end
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
148
|
-
body['sentence'] = sentence
|
149
|
-
return body.to_json
|
150
|
-
end
|
151
|
-
|
152
|
-
def hiragana sentence
|
153
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/gooLanguageAnalysis/v1/hiragana?APIKEY=#{@client.get_api_key}")
|
154
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
155
|
-
http.use_ssl = true
|
156
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/json'})
|
157
|
-
request.body = build_body(sentence)
|
158
|
-
response = nil
|
159
|
-
http.start do |h|
|
160
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
52
|
+
|
53
|
+
class Sensitivecheck < Base
|
54
|
+
EndPoint = "/truetext/v1/sensitivecheck"
|
55
|
+
def analysis(options={})
|
56
|
+
post(build_url(EndPoint), build_params(options.merge(text: URI.escape(options[:text]))), {'Content-Type' =>'application/x-www-form-urlencoded'})
|
57
|
+
end
|
161
58
|
end
|
162
|
-
return response[:converted]
|
163
59
|
end
|
164
60
|
end
|
165
61
|
end
|
@@ -1,47 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require 'open-uri'
|
3
|
-
require 'json'
|
1
|
+
require 'httpclient'
|
4
2
|
|
5
3
|
module Mocodo
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
binary_image = File.binread(open(path))
|
15
|
-
else
|
16
|
-
binary_image = File.binread(File.open(path))
|
17
|
-
end
|
18
|
-
return binary_image
|
19
|
-
end
|
20
|
-
|
21
|
-
def image_recognition(path, num=1)
|
22
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/imageRecognition/v1/recognize?APIKEY=#{@client.get_api_key}&recog=product-all&numOfCandidates=#{num}")
|
23
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
24
|
-
http.use_ssl = true
|
25
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/octet-stream'})
|
26
|
-
request.body = File.binread(open(path)) #image_open(path)
|
27
|
-
response = nil
|
28
|
-
http.start do |h|
|
29
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
4
|
+
module ImageRecognize
|
5
|
+
class Category < Base
|
6
|
+
EndPoint = "/imageRecognition/v1/concept/classify/"
|
7
|
+
def recognize(options={})
|
8
|
+
response = HTTPClient.new.post_content(build_url(EndPoint), options, {
|
9
|
+
"content-type" => "multipart/form-data; boundary=boundary",
|
10
|
+
})
|
11
|
+
JSON.parse(response, symbolize_names: true)
|
30
12
|
end
|
31
|
-
return response[:candidates]
|
32
13
|
end
|
33
14
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/octet-stream'})
|
39
|
-
request.body = File.binread(File.open(path))
|
40
|
-
response = nil
|
41
|
-
http.start do |h|
|
42
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
15
|
+
class Object < Base
|
16
|
+
EndPoint = "/imageRecognition/v1/recognize"
|
17
|
+
def recognize(image, options)
|
18
|
+
post(build_url(EndPoint, options), image, {'Content-Type' =>'application/octet-stream'})
|
43
19
|
end
|
44
|
-
return response[:candidates]
|
45
20
|
end
|
46
21
|
end
|
47
22
|
end
|
data/lib/mocodo/knowledge_qa.rb
CHANGED
@@ -1,21 +1,10 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module Mocodo
|
5
|
-
class KnowledgeQA
|
6
|
-
|
7
|
-
@client = Client.new(api_key)
|
8
|
-
end
|
2
|
+
class KnowledgeQA < Base
|
3
|
+
EndPoint = "/knowledgeQA/v1/ask"
|
9
4
|
|
10
|
-
def create_qa
|
11
|
-
uri =
|
12
|
-
|
13
|
-
|
14
|
-
res = http.start {
|
15
|
-
http.get(uri.request_uri)
|
16
|
-
}
|
17
|
-
data = JSON.parse(res.body)
|
18
|
-
return data
|
19
|
-
end
|
5
|
+
def create_qa text
|
6
|
+
uri = build_url(EndPoint, q: URI.encode(text))
|
7
|
+
JSON.parse(open(uri).read)
|
8
|
+
end
|
20
9
|
end
|
21
10
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Mocodo
|
2
|
+
module MountainIdentification
|
3
|
+
class RidgeRendering < Base
|
4
|
+
EndPoint = "/mountainIdentification/v1/ridgeRendering"
|
5
|
+
def rendering(options={})
|
6
|
+
response = get(build_url(EndPoint, options), {'Content-Type' =>'application/json'})
|
7
|
+
JSON.parse(response, symbolize_names: true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class RidgeMatching < Base
|
12
|
+
EndPoint = "/mountainIdentification/v1/ridgeMatching"
|
13
|
+
def get(options={})
|
14
|
+
response = HTTPClient.new.post_content(build_url(EndPoint), options, {
|
15
|
+
"content-type" => "multipart/form-data; boundary=boundary",
|
16
|
+
})
|
17
|
+
JSON.parse(response, symbolize_names: true)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class RidgeRecognition < Base
|
22
|
+
EndPoint = "/mountainIdentification/v1/ridgeRecognition"
|
23
|
+
def get(options={})
|
24
|
+
response = HTTPClient.new.post_content(build_url(EndPoint), options, {
|
25
|
+
"content-type" => "multipart/form-data; boundary=boundary",
|
26
|
+
})
|
27
|
+
JSON.parse(response, symbolize_names: true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mocodo
|
2
|
+
module ScenarioDialogue
|
3
|
+
class Registration < Base
|
4
|
+
EndPoint = "/scenarioDialogue/v1/registration"
|
5
|
+
def registration(options={})
|
6
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class Dialogue < Base
|
11
|
+
EndPoint = "/scenarioDialogue/v1/dialogue"
|
12
|
+
def create_dialogue(options={})
|
13
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/json'})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,51 +1,8 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module Mocodo
|
5
|
-
class SentenceUnderstanding
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@client = Client.new(api_key)
|
10
|
-
self.config = {}
|
2
|
+
class SentenceUnderstanding < Base
|
3
|
+
EndPoint = "/sentenceUnderstanding/v1/task"
|
4
|
+
def sentenceUnderstanding(options={})
|
5
|
+
post(build_url(EndPoint), options.to_json, {'Content-Type' =>'application/x-www-form-urlencoded'})
|
11
6
|
end
|
12
|
-
|
13
|
-
def configure(options = {})
|
14
|
-
options.each do |key, value|
|
15
|
-
self.config[key] = value
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def get_current_data(option=nil)
|
20
|
-
if option.nil?
|
21
|
-
return self.config
|
22
|
-
else
|
23
|
-
return self.config[option]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def build_body(talk)
|
28
|
-
body = {}
|
29
|
-
self.config.each { |sym|
|
30
|
-
body[sym[0].id2name] = sym[1]
|
31
|
-
}
|
32
|
-
body['userUtterance'] = {}
|
33
|
-
body['userUtterance']['utteranceText'] = talk
|
34
|
-
return body.to_json
|
35
|
-
end
|
36
|
-
|
37
|
-
def sentenceUnderstanding talk
|
38
|
-
uri = URI.parse("https://api.apigw.smt.docomo.ne.jp/sentenceUnderstanding/v1/task?APIKEY=#{@client.get_api_key}")
|
39
|
-
http = Net::HTTP.new('api.apigw.smt.docomo.ne.jp', 443)
|
40
|
-
http.use_ssl = true
|
41
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' =>'application/x-www-form-urlencoded'})
|
42
|
-
request.body = build_body(talk)
|
43
|
-
response = nil
|
44
|
-
http.start do |h|
|
45
|
-
response = JSON.parse(h.request(request).body, symbolize_names: true)
|
46
|
-
end
|
47
|
-
configure(response)
|
48
|
-
return response
|
49
|
-
end
|
50
7
|
end
|
51
8
|
end
|