docomo-nlu 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +32 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +198 -0
  10. data/README.md +38 -0
  11. data/Rakefile +8 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/docomo-nlu.gemspec +37 -0
  15. data/lib/docomo-nlu.rb +11 -0
  16. data/lib/docomo-nlu/config.rb +25 -0
  17. data/lib/docomo-nlu/management.rb +28 -0
  18. data/lib/docomo-nlu/management/account.rb +32 -0
  19. data/lib/docomo-nlu/management/aiml_base.rb +126 -0
  20. data/lib/docomo-nlu/management/base.rb +87 -0
  21. data/lib/docomo-nlu/management/bot.rb +18 -0
  22. data/lib/docomo-nlu/management/config.rb +25 -0
  23. data/lib/docomo-nlu/management/default_predicate.rb +15 -0
  24. data/lib/docomo-nlu/management/map.rb +10 -0
  25. data/lib/docomo-nlu/management/multipart_base.rb +82 -0
  26. data/lib/docomo-nlu/management/ng_word.rb +10 -0
  27. data/lib/docomo-nlu/management/ok_word.rb +10 -0
  28. data/lib/docomo-nlu/management/organization.rb +23 -0
  29. data/lib/docomo-nlu/management/organization_member.rb +15 -0
  30. data/lib/docomo-nlu/management/predicate_name.rb +15 -0
  31. data/lib/docomo-nlu/management/project.rb +16 -0
  32. data/lib/docomo-nlu/management/project_member.rb +15 -0
  33. data/lib/docomo-nlu/management/property.rb +10 -0
  34. data/lib/docomo-nlu/management/provider.rb +17 -0
  35. data/lib/docomo-nlu/management/scenario.rb +18 -0
  36. data/lib/docomo-nlu/management/scenario_project.rb +10 -0
  37. data/lib/docomo-nlu/management/scenario_util.rb +30 -0
  38. data/lib/docomo-nlu/management/set.rb +10 -0
  39. data/lib/docomo-nlu/management/task_project.rb +20 -0
  40. data/lib/docomo-nlu/spontaneous.rb +8 -0
  41. data/lib/docomo-nlu/spontaneous/dialogue.rb +58 -0
  42. data/lib/docomo-nlu/spontaneous/registration.rb +58 -0
  43. data/lib/docomo-nlu/version.rb +5 -0
  44. data/lib/generators/docomo_nlu/install/install_generator.rb +11 -0
  45. data/lib/generators/templates/template.rb +7 -0
  46. data/vcr/vcr_cassettes/account/count.yml +42 -0
  47. data/vcr/vcr_cassettes/account/create.yml +44 -0
  48. data/vcr/vcr_cassettes/account/delete.yml +38 -0
  49. data/vcr/vcr_cassettes/account/index.yml +43 -0
  50. data/vcr/vcr_cassettes/account/show.yml +43 -0
  51. data/vcr/vcr_cassettes/account/update.yml +41 -0
  52. data/vcr/vcr_cassettes/baes/login.yml +44 -0
  53. data/vcr/vcr_cassettes/base/login.yml +44 -0
  54. data/vcr/vcr_cassettes/base/login_400.yml +42 -0
  55. data/vcr/vcr_cassettes/base/logout.yml +40 -0
  56. data/vcr/vcr_cassettes/base/logout_400.yml +40 -0
  57. data/vcr/vcr_cassettes/bot/create.yml +43 -0
  58. data/vcr/vcr_cassettes/bot/create_conflict.yml +45 -0
  59. data/vcr/vcr_cassettes/bot/delete.yml +38 -0
  60. data/vcr/vcr_cassettes/bot/deploy.yml +164 -0
  61. data/vcr/vcr_cassettes/bot/download_aiml.yml +51 -0
  62. data/vcr/vcr_cassettes/bot/download_archive.yml +43 -0
  63. data/vcr/vcr_cassettes/bot/download_dat.yml +43 -0
  64. data/vcr/vcr_cassettes/bot/index.yml +43 -0
  65. data/vcr/vcr_cassettes/bot/index_not_found.yml +42 -0
  66. data/vcr/vcr_cassettes/bot/show.yml +43 -0
  67. data/vcr/vcr_cassettes/bot/upload_aiml.yml +51 -0
  68. data/vcr/vcr_cassettes/bot/upload_archive.yml +46 -0
  69. data/vcr/vcr_cassettes/bot/upload_dat.yml +46 -0
  70. data/vcr/vcr_cassettes/config/delete.yml +38 -0
  71. data/vcr/vcr_cassettes/config/index.yml +120 -0
  72. data/vcr/vcr_cassettes/config/update.yml +42 -0
  73. data/vcr/vcr_cassettes/default_predicate/create.yml +42 -0
  74. data/vcr/vcr_cassettes/default_predicate/delete.yml +38 -0
  75. data/vcr/vcr_cassettes/default_predicate/index.yml +120 -0
  76. data/vcr/vcr_cassettes/default_predicate/index_not_found.yml +120 -0
  77. data/vcr/vcr_cassettes/default_predicate/update.yml +40 -0
  78. data/vcr/vcr_cassettes/map/create.yml +45 -0
  79. data/vcr/vcr_cassettes/map/create_400.yml +48 -0
  80. data/vcr/vcr_cassettes/map/delete.yml +38 -0
  81. data/vcr/vcr_cassettes/map/index_all.yml +43 -0
  82. data/vcr/vcr_cassettes/map/index_find.yml +43 -0
  83. data/vcr/vcr_cassettes/map/index_where.yml +43 -0
  84. data/vcr/vcr_cassettes/map/save.yml +45 -0
  85. data/vcr/vcr_cassettes/map/save_400.yml +48 -0
  86. data/vcr/vcr_cassettes/map/show_find.yml +43 -0
  87. data/vcr/vcr_cassettes/map/show_where.yml +43 -0
  88. data/vcr/vcr_cassettes/organization/create.yml +44 -0
  89. data/vcr/vcr_cassettes/organization/delete.yml +38 -0
  90. data/vcr/vcr_cassettes/organization/index.yml +42 -0
  91. data/vcr/vcr_cassettes/organization/show.yml +42 -0
  92. data/vcr/vcr_cassettes/organization/update.yml +40 -0
  93. data/vcr/vcr_cassettes/organization_member/create.yml +42 -0
  94. data/vcr/vcr_cassettes/organization_member/delete.yml +38 -0
  95. data/vcr/vcr_cassettes/organization_member/index.yml +42 -0
  96. data/vcr/vcr_cassettes/organization_member/index_404.yml +42 -0
  97. data/vcr/vcr_cassettes/organization_member/index_not_found.yml +42 -0
  98. data/vcr/vcr_cassettes/predicate_name/create.yml +42 -0
  99. data/vcr/vcr_cassettes/predicate_name/delete.yml +38 -0
  100. data/vcr/vcr_cassettes/predicate_name/index.yml +42 -0
  101. data/vcr/vcr_cassettes/predicate_name/index_all.yml +42 -0
  102. data/vcr/vcr_cassettes/predicate_name/index_find.yml +42 -0
  103. data/vcr/vcr_cassettes/predicate_name/index_where.yml +42 -0
  104. data/vcr/vcr_cassettes/project/create.yml +44 -0
  105. data/vcr/vcr_cassettes/project/create_conflict.yml +44 -0
  106. data/vcr/vcr_cassettes/project/delete.yml +38 -0
  107. data/vcr/vcr_cassettes/project/index.yml +227 -0
  108. data/vcr/vcr_cassettes/project/show.yml +43 -0
  109. data/vcr/vcr_cassettes/project_member/create.yml +42 -0
  110. data/vcr/vcr_cassettes/project_member/delete.yml +38 -0
  111. data/vcr/vcr_cassettes/project_member/index.yml +42 -0
  112. data/vcr/vcr_cassettes/project_member/index_403.yml +40 -0
  113. data/vcr/vcr_cassettes/project_member/index_not_found.yml +42 -0
  114. data/vcr/vcr_cassettes/provider/create.yml +44 -0
  115. data/vcr/vcr_cassettes/provider/delete.yml +38 -0
  116. data/vcr/vcr_cassettes/provider/index.yml +42 -0
  117. data/vcr/vcr_cassettes/provider/show.yml +42 -0
  118. data/vcr/vcr_cassettes/scenario/create.yml +42 -0
  119. data/vcr/vcr_cassettes/scenario/create_conflict.yml +44 -0
  120. data/vcr/vcr_cassettes/scenario/delete.yml +38 -0
  121. data/vcr/vcr_cassettes/scenario/deploy.yml +164 -0
  122. data/vcr/vcr_cassettes/scenario/download_aiml.yml +51 -0
  123. data/vcr/vcr_cassettes/scenario/index.yml +42 -0
  124. data/vcr/vcr_cassettes/scenario/index_not_found.yml +42 -0
  125. data/vcr/vcr_cassettes/scenario/show.yml +42 -0
  126. data/vcr/vcr_cassettes/scenario/update.yml +40 -0
  127. data/vcr/vcr_cassettes/scenario/upload.yml +51 -0
  128. data/vcr/vcr_cassettes/scenario/upload_aiml.yml +51 -0
  129. data/vcr/vcr_cassettes/scenario/upload_archive.yml +46 -0
  130. data/vcr/vcr_cassettes/scenario/upload_dat.yml +46 -0
  131. data/vcr/vcr_cassettes/set/create.yml +45 -0
  132. data/vcr/vcr_cassettes/set/create_400.yml +48 -0
  133. data/vcr/vcr_cassettes/set/delete.yml +38 -0
  134. data/vcr/vcr_cassettes/set/index_all.yml +42 -0
  135. data/vcr/vcr_cassettes/set/index_find.yml +42 -0
  136. data/vcr/vcr_cassettes/set/index_where.yml +42 -0
  137. data/vcr/vcr_cassettes/set/save.yml +45 -0
  138. data/vcr/vcr_cassettes/set/save_400.yml +48 -0
  139. data/vcr/vcr_cassettes/set/show_find.yml +43 -0
  140. data/vcr/vcr_cassettes/set/show_where.yml +43 -0
  141. metadata +336 -0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class NGWord < Base
6
+ self.element_name = 'ngWords'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class OKWord < Base
6
+ self.element_name = 'okWords'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Organization < Base
6
+ self.element_name = 'organizations'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+
9
+ # Parameter create
10
+ # {
11
+ # "organizationName": "your organization name",
12
+ # "address": "address",
13
+ # "tel": "tel"
14
+ # }
15
+
16
+ def to_json(options = {})
17
+ attributes.delete('organizationId')
18
+ attributes.delete('id')
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class OrganizationMember < Base
6
+ self.element_name = 'members'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/organizations/:organization_id/"
8
+
9
+ def destroy
10
+ self.id = accountId
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class PredicateName < Base
6
+ self.element_name = 'predicateNames'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+
9
+ def destroy(keys)
10
+ self.id = keys.join(',')
11
+ super()
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Project < Base
6
+ self.element_name = 'projects'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+
9
+ # Parameter for create
10
+ # {
11
+ # "projectName": "your project name"
12
+ # "organizationId": "your organization id"
13
+ # }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class ProjectMember < Base
6
+ self.element_name = 'members'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/"
8
+
9
+ def destroy
10
+ self.id = accountId
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Property < Base
6
+ self.element_name = 'properties'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Provider < Base
6
+ self.element_name = 'providers'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+
9
+ # Parameter for create
10
+ # {
11
+ # "organizationId": "id",
12
+ # "serverKind":"SS",
13
+ # "serverId": "DSU"
14
+ # }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Scenario < AIMLBase
6
+ self.element_name = 'scenarios'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+
9
+ def destroy
10
+ self.id = userScenarios.map(&:scenarioId).join(',')
11
+ super
12
+ end
13
+
14
+ class UserScenarios < Base; end
15
+ class TemplateScenarios < Base; end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class ScenarioProject < Base
6
+ self.element_name = 'scenarioProjects'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class ScenarioUtil < Base
6
+ self.element_name = 'scenarioUtils'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+
9
+ def normalize
10
+ # TODO
11
+ end
12
+
13
+ def matches
14
+ # TODO
15
+ end
16
+
17
+ def save
18
+ print 'Method not used'
19
+ end
20
+
21
+ def destroy
22
+ print 'Method not used'
23
+ end
24
+
25
+ def delete
26
+ print 'Method not used'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class Set < MultipartBase
6
+ self.element_name = 'sets'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/projects/:project_id/bots/:bot_id/"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Management
5
+ class TaskProject < Base
6
+ self.element_name = 'taskProjects'
7
+ self.prefix = "/management/#{DocomoNlu.config.nlu_version}/"
8
+
9
+ # Parameter for create
10
+ # {
11
+ # "scenarioProjectId": "",
12
+ # "description": "",
13
+ # "publicHost": "",
14
+ # "internalHosts": [
15
+ # "nnn.nnn.nnn.nnn", "nnn.nnn.nnn.nnn", "nnn.nnn.nnn.nnn"
16
+ # ]
17
+ # }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ module Spontaneous
5
+ autoload :Dialogue, 'docomo-nlu/spontaneous/dialogue'
6
+ autoload :Registration, 'docomo-nlu/spontaneous/registration'
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module DocomoNlu
5
+ module Spontaneous
6
+ class Dialogue < ActiveResource::Base
7
+ attr_accessor :result
8
+ self.site = "http://#{DocomoNlu.config.nlu_host}/"
9
+
10
+ ## Remove format in path (remove .json)
11
+ self.include_format_in_path = false
12
+
13
+ ## Setting Format
14
+ self.format = :json
15
+
16
+ # 対話サーバからのapp_Id払い出し処理
17
+ # Parameter
18
+ # {
19
+ # "app_id" : "sebastien-marketplace",
20
+ # "bot_id" : "botId",
21
+ # "registration_id" : "null",
22
+ # "app_kind" : "sebastien-marketplace",
23
+ # "notification" : false
24
+ # }
25
+ def registration(app_id, bot_id, app_kind = 'developer_dashboard')
26
+ request_body =
27
+ { 'app_id' => app_id, 'bot_id' => bot_id, 'registration_id' => nil, 'app_kind' => app_kind, 'notification' => false }.to_json
28
+ res = connection.post('/UserRegistrationServer/users/applications', request_body, self.class.headers)
29
+ if res.code == '200'
30
+ attributes.store('appId', app_id)
31
+ else
32
+ attributes.store('errors', res.body)
33
+ end
34
+ end
35
+
36
+ def execute(voiceText, initTopicId = nil)
37
+ self.voiceText = voiceText
38
+ self.initTopicId = initTopicId unless initTopicId.nil?
39
+ res = connection.post('/SpontaneousDialogueServer/dialogue', attributes.to_json, self.class.headers)
40
+ @result = res
41
+ end
42
+
43
+ class << self
44
+ def collection_path(prefix_options = {}, query_options = nil)
45
+ check_prefix_options(prefix_options)
46
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
47
+ "#{prefix(prefix_options)}#{collection_name}#{format_extension}#{query_string(query_options)}"
48
+ end
49
+ # Override. Native code is here
50
+ # @collection_name ||= ActiveSupport::Inflector.pluralize(element_name)
51
+
52
+ def collection_name
53
+ @collection_name ||= element_name
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ module DocomoNlu
5
+ module Spontaneous
6
+ class Registration < ActiveResource::Base
7
+ attr_accessor :result
8
+ self.site = "http://#{DocomoNlu.config.nlu_host}/"
9
+
10
+ ## Remove format in path (remove .json)
11
+ self.include_format_in_path = false
12
+
13
+ ## Setting Format
14
+ self.format = :json
15
+
16
+ # 対話サーバからのapp_Id払い出し処理
17
+ # Parameter
18
+ # {
19
+ # "app_id" : "sebastien-marketplace",
20
+ # "bot_id" : "botId",
21
+ # "registration_id" : "null",
22
+ # "app_kind" : "sebastien-marketplace",
23
+ # "notification" : false
24
+ # }
25
+ def registration(app_id, bot_id, app_kind = 'developer_dashboard')
26
+ request_body =
27
+ { 'app_id' => app_id, 'bot_id' => bot_id, 'registration_id' => nil, 'app_kind' => app_kind, 'notification' => false }.to_json
28
+ res = connection.post('/UserRegistrationServer/users/applications', request_body, self.class.headers)
29
+ if res.code == '200'
30
+ attributes.store('appId', app_id)
31
+ else
32
+ attributes.store('errors', res.body)
33
+ end
34
+ end
35
+
36
+ def execute(voice_text, _init_topic_d = nil)
37
+ self.voiceText = voice_text
38
+ self.initTopicId = init_topic_id unless init_topic_id.nil?
39
+ res = connection.post('/SpontaneousDialogueServer/dialogue', attributes.to_json, self.class.headers)
40
+ @result = res
41
+ end
42
+
43
+ class << self
44
+ def collection_path(prefix_options = {}, query_options = nil)
45
+ check_prefix_options(prefix_options)
46
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
47
+ "#{prefix(prefix_options)}#{collection_name}#{format_extension}#{query_string(query_options)}"
48
+ end
49
+ # Override. Native code is here
50
+ # @collection_name ||= ActiveSupport::Inflector.pluralize(element_name)
51
+
52
+ def collection_name
53
+ @collection_name ||= element_name
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ VERSION = '0.1.1'
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DocomoNlu
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../../templates', __dir__)
6
+
7
+ def copy_initializer
8
+ copy_file 'template.rb', 'config/initializers/docomo-nlu.rb'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ DocomoNlu.configure do |config|
4
+ config.nlu_host = 'Set your host'
5
+ config.nlu_version = 'Set version'
6
+ config.admin_access_token = 'Set token that able to create account'
7
+ end
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://nlu-external-dev-977165653.ap-northeast-1.elb.amazonaws.com/management/v2.2/accounts/count
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Authorization:
13
+ - NLP f68518ed5a40907ec6b754caeaadc32b0af4920f69955c22749e38e17946ea57
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Tue, 21 Aug 2018 07:42:52 GMT
25
+ Content-Type:
26
+ - application/json;charset=utf-8
27
+ Content-Length:
28
+ - '13'
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - Apache
33
+ X-Content-Type-Options:
34
+ - nosniff
35
+ X-Frame-Options:
36
+ - SAMEORIGIN
37
+ body:
38
+ encoding: UTF-8
39
+ string: '{"count":207}'
40
+ http_version:
41
+ recorded_at: Tue, 21 Aug 2018 07:42:52 GMT
42
+ recorded_with: VCR 4.0.0