opener-opinion-detector 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ae3de69cda2c50f6000cc1b10f0fc8e2977a8e0
4
- data.tar.gz: 77d74736ed8aeba3bd10bd8ab74d18e5fa35cf55
3
+ metadata.gz: 10d7102f7189eda4b50af9e7930bb3bcae12d502
4
+ data.tar.gz: 19202c977c1b2795f93f5ce3ad2f66dd1317e270
5
5
  SHA512:
6
- metadata.gz: 77a17df4b51c38f1bde5780d1492e680e324a3c0997032fa16f3e8f5364e751c27d4f48f8e1bf30a9ebc29722147a31648285ec3bec839c403350bf093bcf5df
7
- data.tar.gz: 20276c643f12ffcd80e755acef9bb204ca0170d2491ddacceac9ba7c380f70b6f04f215f56b759a6d00d5770f95aafe2aec27048f2e88213a848b9d81b62623d
6
+ metadata.gz: 596d2bb8cdb95b0621775149eed9d4a5496a068f5ad6311a70bb22783380f18b0ab5a12fa5711d03f432e26ed0f77e69fb252259ab0fae6671054017cbae892d
7
+ data.tar.gz: ad3edb1547a92b62f617c5665a9806c3e24981bf6b8842afe9c46a50f0be4c54b0e26438c4292096b76d6466f404777bd0f9d47326080d242d7081e74e56b301
data/README.md CHANGED
@@ -91,7 +91,7 @@ The component is a fat wrapper around the actual language technology core. You c
91
91
  Where to go from here
92
92
  ---------------------
93
93
 
94
- * [Check the project websitere](http://opener-project.github.io)
94
+ * [Check the project website](http://opener-project.github.io)
95
95
  * [Checkout the webservice](http://opener.olery.com/opinion-detector)
96
96
 
97
97
  Report problem/Get help
@@ -5,6 +5,7 @@ require 'optparse'
5
5
 
6
6
  require_relative 'opinion_detector/version'
7
7
  require_relative 'opinion_detector/cli'
8
+ require_relative 'opinion_detector/error_layer'
8
9
 
9
10
  module Opener
10
11
  ##
@@ -44,14 +45,21 @@ module Opener
44
45
  # @return [Array]
45
46
  #
46
47
  def run(input)
47
- language = language_from_kaf(input)
48
+ begin
49
+ language = language_from_kaf(input)
48
50
 
49
- unless valid_language?(language)
50
- raise ArgumentError, "The specified language (#{language}) is invalid"
51
- end
51
+ unless valid_language?(language)
52
+ raise ArgumentError, "The specified language (#{language}) is invalid"
53
+ end
52
54
 
53
- kernel = language_constant(language).new(options)
54
- return kernel.run(input)
55
+ kernel = language_constant(language).new(:args => options[:args])
56
+ stdout, stderr, process = kernel.run(input)
57
+ raise stderr unless process.success?
58
+ return stdout
59
+
60
+ rescue Exception => error
61
+ return ErrorLayer.new(input, error.message, self.class).add
62
+ end
55
63
  end
56
64
 
57
65
  protected
@@ -37,6 +37,18 @@ module Opener
37
37
  opts.on('-l', '--log', 'Enables logging to STDERR') do
38
38
  @options[:logging] = true
39
39
  end
40
+
41
+ opts.on('-d', '--domain DOMAIN_NAME', 'Domain name of the models.') do |v|
42
+ @options[:domain] = v
43
+ end
44
+
45
+ opts.separator <<-EOF
46
+
47
+ Examples:
48
+
49
+ cat example.kaf | #{opts.program_name}
50
+ cat example.kaf | #{opts.program_name} -l # Enables logging to STDERR
51
+ EOF
40
52
  end
41
53
 
42
54
  option_parser.parse!(options[:args])
@@ -53,15 +65,7 @@ module Opener
53
65
 
54
66
  stdout, stderr, process = tagger.run(input)
55
67
 
56
- if process.success?
57
- puts stdout
58
-
59
- if options[:logging] and !stderr.empty?
60
- STDERR.puts(stderr)
61
- end
62
- else
63
- abort stderr
64
- end
68
+ puts stdout
65
69
  end
66
70
 
67
71
  private
@@ -0,0 +1,88 @@
1
+ module Opener
2
+ class OpinionDetector
3
+ ##
4
+ # Add Error Layer to KAF file instead of throwing an error.
5
+ #
6
+ class ErrorLayer
7
+ attr_accessor :input, :document, :error, :klass
8
+
9
+ def initialize(input, error, klass)
10
+ @input = input.to_s
11
+ # Make sure there is always a document, even if it is empty.
12
+ @document = Nokogiri::XML(input) rescue Nokogiri::XML(nil)
13
+ @error = error
14
+ @klass = klass
15
+ end
16
+
17
+ def add
18
+ if is_xml?
19
+ unless has_errors_layer?
20
+ add_errors_layer
21
+ end
22
+ else
23
+ add_root
24
+ add_text
25
+ add_errors_layer
26
+ end
27
+ add_error
28
+
29
+ xml = !!document.encoding ? document.to_xml : document.to_xml(:encoding => "UTF-8")
30
+
31
+ return xml
32
+ end
33
+
34
+ ##
35
+ # Check if the document is a valid XML file.
36
+ #
37
+ def is_xml?
38
+ !!document.root
39
+ end
40
+
41
+ ##
42
+ # Add root element to the XML file.
43
+ #
44
+ def add_root
45
+ root = Nokogiri::XML::Node.new "KAF", document
46
+ document.add_child(root)
47
+ end
48
+
49
+ ##
50
+ # Check if the document already has an errors layer.
51
+ #
52
+ def has_errors_layer?
53
+ !!document.at('errors')
54
+ end
55
+
56
+ ##
57
+ # Add errors element to the XML file.
58
+ #
59
+ def add_errors_layer
60
+ node = Nokogiri::XML::Node.new "errors", document
61
+ document.root.add_child(node)
62
+ end
63
+
64
+ ##
65
+ # Add the text file incase it is not a valid XML document. More
66
+ # info for debugging.
67
+ #
68
+ def add_text
69
+ node = Nokogiri::XML::Node.new "raw", document
70
+ node.inner_html = input
71
+ document.root.add_child(node)
72
+
73
+ end
74
+
75
+ ##
76
+ # Add the actual error to the errors layer.
77
+ #
78
+ def add_error
79
+ node = document.at('errors')
80
+ error_node = Nokogiri::XML::Node.new "error", node
81
+ error_node['class'] = "#{klass.to_s} #{klass::VERSION}"
82
+ error_node.inner_html = error
83
+ node.add_child(error_node)
84
+ end
85
+
86
+ end # ErrorLayer
87
+ end # OpinionDetector
88
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class OpinionDetector
3
- VERSION = "1.1.3"
3
+ VERSION = "1.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,189 +1,189 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-opinion-detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-23 00:00:00.000000000 Z
11
+ date: 2014-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opener-opinion-detector-base
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
15
20
  requirement: !ruby/object:Gem::Requirement
16
21
  requirements:
17
- - - ">="
22
+ - - '>='
18
23
  - !ruby/object:Gem::Version
19
24
  version: '0'
20
- type: :runtime
21
25
  prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
- - - ">="
31
+ - - '>='
25
32
  - !ruby/object:Gem::Version
26
33
  version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: nokogiri
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
36
+ - - '>='
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :runtime
35
39
  prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - ">="
45
+ - - ~>
39
46
  - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: sinatra
47
+ version: 1.4.2
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - "~>"
50
+ - - ~>
46
51
  - !ruby/object:Gem::Version
47
52
  version: 1.4.2
48
- type: :runtime
49
53
  prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: httpclient
50
57
  version_requirements: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - "~>"
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
- version: 1.4.2
55
- - !ruby/object:Gem::Dependency
56
- name: httpclient
61
+ version: '0'
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
- - - ">="
64
+ - - '>='
60
65
  - !ruby/object:Gem::Version
61
66
  version: '0'
62
- type: :runtime
63
67
  prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: puma
64
71
  version_requirements: !ruby/object:Gem::Requirement
65
72
  requirements:
66
- - - ">="
73
+ - - '>='
67
74
  - !ruby/object:Gem::Version
68
75
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: puma
71
76
  requirement: !ruby/object:Gem::Requirement
72
77
  requirements:
73
- - - ">="
78
+ - - '>='
74
79
  - !ruby/object:Gem::Version
75
80
  version: '0'
76
- type: :runtime
77
81
  prerelease: false
82
+ type: :runtime
83
+ - !ruby/object:Gem::Dependency
84
+ name: opener-daemons
78
85
  version_requirements: !ruby/object:Gem::Requirement
79
86
  requirements:
80
- - - ">="
87
+ - - '>='
81
88
  - !ruby/object:Gem::Version
82
89
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: opener-daemons
85
90
  requirement: !ruby/object:Gem::Requirement
86
91
  requirements:
87
- - - ">="
92
+ - - '>='
88
93
  - !ruby/object:Gem::Version
89
94
  version: '0'
90
- type: :runtime
91
95
  prerelease: false
96
+ type: :runtime
97
+ - !ruby/object:Gem::Dependency
98
+ name: opener-core
92
99
  version_requirements: !ruby/object:Gem::Requirement
93
100
  requirements:
94
- - - ">="
101
+ - - '>='
95
102
  - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: opener-core
103
+ version: 0.1.2
99
104
  requirement: !ruby/object:Gem::Requirement
100
105
  requirements:
101
- - - ">="
106
+ - - '>='
102
107
  - !ruby/object:Gem::Version
103
108
  version: 0.1.2
104
- type: :runtime
105
109
  prerelease: false
110
+ type: :runtime
111
+ - !ruby/object:Gem::Dependency
112
+ name: opener-webservice
106
113
  version_requirements: !ruby/object:Gem::Requirement
107
114
  requirements:
108
- - - ">="
115
+ - - '>='
109
116
  - !ruby/object:Gem::Version
110
- version: 0.1.2
111
- - !ruby/object:Gem::Dependency
112
- name: opener-webservice
117
+ version: '0'
113
118
  requirement: !ruby/object:Gem::Requirement
114
119
  requirements:
115
- - - ">="
120
+ - - '>='
116
121
  - !ruby/object:Gem::Version
117
122
  version: '0'
118
- type: :runtime
119
123
  prerelease: false
124
+ type: :runtime
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
120
127
  version_requirements: !ruby/object:Gem::Requirement
121
128
  requirements:
122
- - - ">="
129
+ - - '>='
123
130
  - !ruby/object:Gem::Version
124
131
  version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
132
  requirement: !ruby/object:Gem::Requirement
128
133
  requirements:
129
- - - ">="
134
+ - - '>='
130
135
  - !ruby/object:Gem::Version
131
136
  version: '0'
132
- type: :development
133
137
  prerelease: false
138
+ type: :development
139
+ - !ruby/object:Gem::Dependency
140
+ name: cucumber
134
141
  version_requirements: !ruby/object:Gem::Requirement
135
142
  requirements:
136
- - - ">="
143
+ - - '>='
137
144
  - !ruby/object:Gem::Version
138
145
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: cucumber
141
146
  requirement: !ruby/object:Gem::Requirement
142
147
  requirements:
143
- - - ">="
148
+ - - '>='
144
149
  - !ruby/object:Gem::Version
145
150
  version: '0'
146
- type: :development
147
151
  prerelease: false
152
+ type: :development
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
148
155
  version_requirements: !ruby/object:Gem::Requirement
149
156
  requirements:
150
- - - ">="
157
+ - - '>='
151
158
  - !ruby/object:Gem::Version
152
159
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: pry
155
160
  requirement: !ruby/object:Gem::Requirement
156
161
  requirements:
157
- - - ">="
162
+ - - '>='
158
163
  - !ruby/object:Gem::Version
159
164
  version: '0'
160
- type: :development
161
165
  prerelease: false
166
+ type: :development
167
+ - !ruby/object:Gem::Dependency
168
+ name: rake
162
169
  version_requirements: !ruby/object:Gem::Requirement
163
170
  requirements:
164
- - - ">="
171
+ - - '>='
165
172
  - !ruby/object:Gem::Version
166
173
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rake
169
174
  requirement: !ruby/object:Gem::Requirement
170
175
  requirements:
171
- - - ">="
176
+ - - '>='
172
177
  - !ruby/object:Gem::Version
173
178
  version: '0'
174
- type: :development
175
179
  prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
180
+ type: :development
181
181
  description: Gem that wraps up the different existing opinion detectors
182
- email:
182
+ email:
183
183
  executables:
184
- - opinion-detector-server
185
184
  - opinion-detector
186
185
  - opinion-detector-daemon
186
+ - opinion-detector-server
187
187
  extensions: []
188
188
  extra_rdoc_files: []
189
189
  files:
@@ -195,6 +195,7 @@ files:
195
195
  - exec/opinion-detector.rb
196
196
  - lib/opener/opinion_detector.rb
197
197
  - lib/opener/opinion_detector/cli.rb
198
+ - lib/opener/opinion_detector/error_layer.rb
198
199
  - lib/opener/opinion_detector/public/markdown.css
199
200
  - lib/opener/opinion_detector/server.rb
200
201
  - lib/opener/opinion_detector/version.rb
@@ -204,25 +205,24 @@ files:
204
205
  homepage: http://opener-project.github.com/
205
206
  licenses: []
206
207
  metadata: {}
207
- post_install_message:
208
+ post_install_message:
208
209
  rdoc_options: []
209
210
  require_paths:
210
211
  - lib
211
212
  required_ruby_version: !ruby/object:Gem::Requirement
212
213
  requirements:
213
- - - ">="
214
+ - - '>='
214
215
  - !ruby/object:Gem::Version
215
216
  version: 1.9.2
216
217
  required_rubygems_version: !ruby/object:Gem::Requirement
217
218
  requirements:
218
- - - ">="
219
+ - - '>='
219
220
  - !ruby/object:Gem::Version
220
221
  version: '0'
221
222
  requirements: []
222
- rubyforge_project:
223
+ rubyforge_project:
223
224
  rubygems_version: 2.2.2
224
- signing_key:
225
+ signing_key:
225
226
  specification_version: 4
226
227
  summary: Gem that wraps up the different existing opinion detectors
227
228
  test_files: []
228
- has_rdoc: yard