opener-opinion-detector-basic 1.0.2 → 1.0.3

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: 0fba3c1e1c36909714262f98b74b56d063e001ce
4
- data.tar.gz: d9373a0f72ae696444c98c5a5fb164a64123618e
3
+ metadata.gz: 173429b1415402fbd4d6c14010d3706a95dc3c70
4
+ data.tar.gz: febe0e858ba5af068ed9c5bf242f098223ad133a
5
5
  SHA512:
6
- metadata.gz: 59f04729557973091725070c69e4313fbc1466c3dafed71e8ef8ad92b987c264ea4beeb85ebfbc7128adfb6651dc5459189a6f49f78be537eb531f630dada5db
7
- data.tar.gz: 26bcd2d87e98bdd6f8483aaffb42e39e04e07cd8d97f1fd822cc169c9ab81879148a305e804bcae8f1e7deb0b6fff02fc7af2fc88aba6fdb75903702caa947fe
6
+ metadata.gz: 746417484cd6597a9df72938f8d020a9d4ef38a492d0e475881b12b068c832096f6ed96c9fd93668034391cc14015ea504a72baf827160b119de748c06c18b12
7
+ data.tar.gz: 3ce4ff9e02b75daeedf3757459545919efed36b64c1a6cdbaf2e7546ec82fca5c051ff8be5cc0530359224ba5dee38d07bfed412cae0b16eb42726de6a30c556
data/README.md CHANGED
@@ -1,22 +1,19 @@
1
1
  Opinion Detector Basic
2
2
  ---------------------
3
3
 
4
- This module implements a opinion detector for English (also works for Dutch and
5
- German). The language is determined by the "xml:lang" attribut in the input KAF
6
- file. Depending on the value of this attribute, the corresponding lexicon will
7
- be loaded. This module detects three elements of the opinions:
4
+ This module implements a opinion detector for all the languages covered in the OpeNER project (English, Dutch, German, Italian,
5
+ Spanish and French). The language is determined by the "xml:lang" attribut in the input KAF file. Depending on the value of this attribute, the corresponding lexicon will be loaded. This module detects three elements of the opinions:
8
6
 
9
7
  * Expression: the actual opinion expression
10
8
  * Target: about what is the previous expression
11
9
  * Holder: who is stating that expression
12
10
 
11
+ This module is based on a set of rules for extracting the opinion expressions first (taking into account polarity words and sentiment modifiers) and then other
12
+ rules to determine the targets and holders for those expressions. The input KAF file needs to be processed at least with the tokenizer, pos-tagger and polarity-tagger.
13
+
13
14
  ### Confused by some terminology?
14
15
 
15
- This software is part of a larger collection of natural language processing
16
- tools known as "the OpeNER project". You can find more information about the
17
- project at [the OpeNER portal](http://opener-project.github.io). There you can
18
- also find references to terms like KAF (an XML standard to represent linguistic
19
- annotations in texts), component, cores, scenario's and pipelines.
16
+ This software is part of a larger collection of natural language processing tools known as "the OpeNER project". You can find more information about the project at [the OpeNER portal](http://opener-project.github.io). There you can also find references to terms like KAF (an XML standard to represent linguistic annotations in texts), component, cores, scenario's and pipelines.
20
17
 
21
18
  Quick Use Example
22
19
  -----------------
@@ -25,14 +22,11 @@ Installing the opinion-detector-basic can be done by executing:
25
22
 
26
23
  gem install opener-opinion-detector-basic
27
24
 
28
- Please bare in mind that all components in OpeNER take KAF as an input and
29
- output KAF by default.
25
+ Please bare in mind that all components in OpeNER take KAF as an input and output KAF by default.
30
26
 
31
27
  ### Command line interface
32
28
 
33
- The input KAF file has to be annotated with at least the term layer, with
34
- polarity information. Correct input files for this module are the output KAF
35
- files from the polarity tagger module
29
+ The input KAF file has to be annotated with at least the term layer, with polarity information. Correct input files for this module are the output KAF files from the polarity tagger module
36
30
 
37
31
  To tag an input KAF file example.kaf with opinions you can run:
38
32
 
@@ -68,26 +62,19 @@ You can launch a webservice by executing:
68
62
 
69
63
  opinion-detector-basic-server
70
64
 
71
- This will launch a mini webserver with the webservice. It defaults to port 9292,
72
- so you can access it at <http://localhost:9292>.
65
+ This will launch a mini webserver with the webservice. It defaults to port 9292, so you can access it at <http://localhost:9292>.
73
66
 
74
- To launch it on a different port provide the `-p [port-number]` option like
75
- this:
67
+ To launch it on a different port provide the `-p [port-number]` option like this:
76
68
 
77
69
  opinion-detector-basic-server -p 1234
78
70
 
79
71
  It then launches at <http://localhost:1234>
80
72
 
81
- Documentation on the Webservice is provided by surfing to the urls provided
82
- above. For more information on how to launch a webservice run the command with
83
- the ```-h``` option.
84
-
73
+ Documentation on the Webservice is provided by surfing to the urls provided above. For more information on how to launch a webservice run the command with the ```-h``` option.
85
74
 
86
75
  ### Daemon
87
76
 
88
- Last but not least the opinion detector basic comes shipped with a daemon that
89
- can read jobs (and write) jobs to and from Amazon SQS queues. For more
90
- information type:
77
+ Last but not least the opinion detector basic comes shipped with a daemon that can read jobs (and write) jobs to and from Amazon SQS queues. For more information type:
91
78
 
92
79
  opinion-detector-basic-daemon -h
93
80
 
@@ -95,9 +82,7 @@ information type:
95
82
  Description of dependencies
96
83
  ---------------------------
97
84
 
98
- This component runs best if you run it in an environment suited for OpeNER
99
- components. You can find an installation guide and helper tools in the [OpeNER installer](https://github.com/opener-project/opener-installer) and an
100
- [installation guide on the Opener Website](http://opener-project.github.io/getting-started/how-to/local-installation.html)
85
+ This component runs best if you run it in an environment suited for OpeNER components. You can find an installation guide and helper tools in the [OpeNER installer](https://github.com/opener-project/opener-installer) and an [installation guide on the Opener Website](http://opener-project.github.io/getting-started/how-to/local-installation.html)
101
86
 
102
87
  At least you need the following system setup:
103
88
 
@@ -121,14 +106,14 @@ Language Extension
121
106
  Where to go from here
122
107
  ---------------------
123
108
 
124
- * [Check the project websitere](http://opener-project.github.io)
109
+ * [Check the project website](http://opener-project.github.io)
125
110
  * [Checkout the webservice](http://opener.olery.com/opinion-detector-basic)
126
111
 
127
112
  Report problem/Get help
128
113
  -----------------------
129
114
 
130
- If you encounter problems, please email <support@opener-project.eu> or leave an
131
- issue in the [issue tracker](https://github.com/opener-project/opinion-detector-basic/issues).
115
+ If you encounter problems, please email <support@opener-project.eu> or leave an issue in the
116
+ [issue tracker](https://github.com/opener-project/opinion-detector-basic/issues).
132
117
 
133
118
 
134
119
  Contributing
@@ -12,8 +12,4 @@ end
12
12
  kernel = Opener::OpinionDetectorBasic.new(:args => ARGV)
13
13
  stdout, stderr, process = kernel.run(input)
14
14
 
15
- if process.success?
16
- puts stdout
17
- else
18
- abort stderr
19
- end
15
+ puts stdout
@@ -0,0 +1,90 @@
1
+ require 'nokogiri'
2
+
3
+ module Opener
4
+ class OpinionDetectorBasic
5
+ ##
6
+ # Add Error Layer to KAF file instead of throwing an error.
7
+ #
8
+ class ErrorLayer
9
+ attr_accessor :input, :document, :error, :klass
10
+
11
+ def initialize(input, error, klass)
12
+ @input = input.to_s
13
+ # Make sure there is always a document, even if it is empty.
14
+ @document = Nokogiri::XML(input) rescue Nokogiri::XML(nil)
15
+ @error = error
16
+ @klass = klass
17
+ end
18
+
19
+ def add
20
+ if is_xml?
21
+ unless has_errors_layer?
22
+ add_errors_layer
23
+ end
24
+ else
25
+ add_root
26
+ add_text
27
+ add_errors_layer
28
+ end
29
+ add_error
30
+
31
+ xml = !!document.encoding ? document.to_xml : document.to_xml(:encoding => "UTF-8")
32
+
33
+ return xml
34
+ end
35
+
36
+ ##
37
+ # Check if the document is a valid XML file.
38
+ #
39
+ def is_xml?
40
+ !!document.root
41
+ end
42
+
43
+ ##
44
+ # Add root element to the XML file.
45
+ #
46
+ def add_root
47
+ root = Nokogiri::XML::Node.new "KAF", document
48
+ document.add_child(root)
49
+ end
50
+
51
+ ##
52
+ # Check if the document already has an errors layer.
53
+ #
54
+ def has_errors_layer?
55
+ !!document.at('errors')
56
+ end
57
+
58
+ ##
59
+ # Add errors element to the XML file.
60
+ #
61
+ def add_errors_layer
62
+ node = Nokogiri::XML::Node.new "errors", document
63
+ document.root.add_child(node)
64
+ end
65
+
66
+ ##
67
+ # Add the text file incase it is not a valid XML document. More
68
+ # info for debugging.
69
+ #
70
+ def add_text
71
+ node = Nokogiri::XML::Node.new "raw", document
72
+ node.inner_html = input
73
+ document.root.add_child(node)
74
+
75
+ end
76
+
77
+ ##
78
+ # Add the actual error to the errors layer.
79
+ #
80
+ def add_error
81
+ node = document.at('errors')
82
+ error_node = Nokogiri::XML::Node.new "error", node
83
+ error_node['class'] = "#{klass.to_s} #{klass::VERSION}"
84
+ error_node.inner_html = error
85
+ node.add_child(error_node)
86
+ end
87
+
88
+ end # ErrorLayer
89
+ end # OpinionDetectorBasic
90
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class OpinionDetectorBasic
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'open3'
2
2
 
3
3
  require_relative 'opinion_detector_basic/version'
4
+ require_relative 'opinion_detector_basic/error_layer'
4
5
 
5
6
  module Opener
6
7
 
@@ -38,7 +39,15 @@ module Opener
38
39
  # @return [Array]
39
40
  #
40
41
  def run(input)
41
- capture(input)
42
+ begin
43
+ capture(input)
44
+ stdout, stderr, process = capture(input)
45
+ raise stderr unless process.success?
46
+ return stdout
47
+
48
+ rescue Exception => error
49
+ return ErrorLayer.new(input, error.message, self.class).add
50
+ end
42
51
  end
43
52
 
44
53
  protected
@@ -12,7 +12,6 @@ Gem::Specification.new do |gem|
12
12
  gem.required_ruby_version = '>= 1.9.2'
13
13
 
14
14
  gem.files = Dir.glob([
15
- 'core/site-packages/pre_build/**/*',
16
15
  'core/packages/*',
17
16
  'core/vendor/src/**/*',
18
17
  'core/*',
@@ -35,6 +34,7 @@ Gem::Specification.new do |gem|
35
34
  gem.add_dependency 'opener-daemons'
36
35
  gem.add_dependency 'opener-core', ['>= 0.1.2']
37
36
  gem.add_dependency 'opener-webservice'
37
+ gem.add_dependency 'nokogiri'
38
38
 
39
39
  gem.add_development_dependency 'rspec'
40
40
  gem.add_development_dependency 'cucumber'
metadata CHANGED
@@ -1,161 +1,175 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-opinion-detector-basic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
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-build-tools
15
- requirement: !ruby/object:Gem::Requirement
15
+ version_requirements: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.2.7
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
20
+ requirement: !ruby/object:Gem::Requirement
23
21
  requirements:
24
- - - ">="
22
+ - - '>='
25
23
  - !ruby/object:Gem::Version
26
24
  version: 0.2.7
25
+ prerelease: false
26
+ type: :runtime
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
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
47
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: sinatra
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - ">="
50
+ - - '>='
46
51
  - !ruby/object:Gem::Version
47
52
  version: '0'
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
61
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: httpclient
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: nokogiri
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: :runtime
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
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: cucumber
148
155
  version_requirements: !ruby/object:Gem::Requirement
149
156
  requirements:
150
- - - ">="
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirement: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
151
163
  - !ruby/object:Gem::Version
152
164
  version: '0'
165
+ prerelease: false
166
+ type: :development
153
167
  description: Basic Opinion Detector.
154
- email:
168
+ email:
155
169
  executables:
156
- - opinion-detector-basic-server
157
170
  - opinion-detector-basic
158
171
  - opinion-detector-basic-daemon
172
+ - opinion-detector-basic-server
159
173
  extensions:
160
174
  - ext/hack/Rakefile
161
175
  extra_rdoc_files: []
@@ -308,6 +322,7 @@ files:
308
322
  - ext/hack/Rakefile
309
323
  - ext/hack/support.rb
310
324
  - lib/opener/opinion_detector_basic.rb
325
+ - lib/opener/opinion_detector_basic/error_layer.rb
311
326
  - lib/opener/opinion_detector_basic/public/markdown.css
312
327
  - lib/opener/opinion_detector_basic/server.rb
313
328
  - lib/opener/opinion_detector_basic/version.rb
@@ -318,25 +333,24 @@ files:
318
333
  homepage: http://opener-project.github.com/
319
334
  licenses: []
320
335
  metadata: {}
321
- post_install_message:
336
+ post_install_message:
322
337
  rdoc_options: []
323
338
  require_paths:
324
339
  - lib
325
340
  required_ruby_version: !ruby/object:Gem::Requirement
326
341
  requirements:
327
- - - ">="
342
+ - - '>='
328
343
  - !ruby/object:Gem::Version
329
344
  version: 1.9.2
330
345
  required_rubygems_version: !ruby/object:Gem::Requirement
331
346
  requirements:
332
- - - ">="
347
+ - - '>='
333
348
  - !ruby/object:Gem::Version
334
349
  version: '0'
335
350
  requirements: []
336
- rubyforge_project:
351
+ rubyforge_project:
337
352
  rubygems_version: 2.2.2
338
- signing_key:
353
+ signing_key:
339
354
  specification_version: 4
340
355
  summary: Basic Opinion Detector.
341
356
  test_files: []
342
- has_rdoc: