opener-polarity-tagger 2.5.0 → 3.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b61b46308899fa357e1217d9eba388552adb714
4
- data.tar.gz: 5480d6b4772655c21f08407ae2971e7dd3188bf1
3
+ metadata.gz: 4704e0e656fbe2aeed40ebad8f54aef94c950294
4
+ data.tar.gz: 4b80616f84a4286973bd7473f9b805c023f44ded
5
5
  SHA512:
6
- metadata.gz: 173103678afe3d74c9e6454b7c45429945c7cec135402ec6eacccfa7d806edbf8646f6e14b9fb3d29d9efbf79ad081347ffc85c37b71d0a93a2c94621048bc2b
7
- data.tar.gz: e496e0cfa60db2e307f369f229b6e06c11806b5d759244eb68c923124f57642fae51b18c14b802dadb9d549c54cd75c4573bbc9cf5c7be4afbacaafe97eb6794
6
+ metadata.gz: daca3e529b5c0dfe94f01f77ea7c4b2dbc5380e57a29971ab3254d628ef8dc9e16483fc3ee9da0bc901a34c56d0c81349552465c5fe257101a26d1378082fec7
7
+ data.tar.gz: 30b5efbf6caf1892e8c3d9210399448a53a84dff3634f1ff1463d59f2924340cb48bb9062d09325018e1af429cbcbe0c8f5f5683a41b30242ecf7057c3534677
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
- Introduction
2
- ------------
1
+ # Introduction
3
2
 
4
- This repository contains the code for the OpeNER polarity tagger. This tool tags words in a KAF file with polarity information, which basically is:
3
+ This repository contains the code for the OpeNER polarity tagger. This tool tags
4
+ words in a KAF file with polarity information, which basically is:
5
5
 
6
- * Polarity information, which represents positive or negative facts in a certain domain. Good, cheap and clean can be positive words in a hotel domain, while bad, expensive and dirty could be negative ones.
7
- * Sentiment modifiers, which modify the polarity of a surrounding polarity word. For instance very or no are sentiment modifiers
6
+ * Polarity information, which represents positive or negative facts in a certain
7
+ domain. Good, cheap and clean can be positive words in a hotel domain, while
8
+ bad, expensive and dirty could be negative ones.
9
+ * Sentiment modifiers, which modify the polarity of a surrounding polarity word.
10
+ For instance very or no are sentiment modifiers
8
11
 
9
12
  The polarity tagger supports the following languages:
10
13
 
@@ -15,72 +18,82 @@ The polarity tagger supports the following languages:
15
18
  * Italian
16
19
  * Spanish
17
20
 
18
- ##How-to##
19
-
20
- The main script of this tool is a python file, which accepts a set of parameters to determine which features
21
- or options we want to use. The language is read from the KAF file, so it doesn't need to be specified as a parameter
22
- The program reads a KAF file from the standard input and writes the resulting KAf in the standard output.
23
- To see the options you can call to the main script with the -h or --help option
24
- ````shell
25
- $ python core/poltagger-basic-multi.py -h
26
- usage: poltagger-basic-multi.py [-h] [--no-time] [--ignore-pos]
27
- [--show-lexicons {nl,en,de,es,it,fr}]
28
- [--lexicon LEXICON] [--silent] [--version]
29
-
30
- Tags a text with polarities at lemma level
31
-
32
- optional arguments:
33
- -h, --help show this help message and exit
34
- --no-time For not including timestamp in header
35
- --ignore-pos Ignore the pos labels
36
- --show-lexicons {nl,en,de,es,it,fr}
37
- Show lexicons for the given language and exit
38
- --lexicon LEXICON Lexicon identifier, check with --show-lexicons LANG
39
- for options
40
- --lexicon-path LEXICON The path of the lexicons
41
- --silent Turn off debug info
42
- --version show program's version number and exit
43
- ````
44
-
45
- The `--ignore-pos` parameter must be used when want to ignore the part-of-speech information assigned to the lemmas, and we want to assign polarities
46
- just to the lemmas, not considering the POS tag. This could be useful when the information provided by the pos-tagger is not accurate or the pos-tagging
47
- has not been processed.
48
-
49
- The main options are those concerning with the usage of different lexicons. The lexicons are provided by the
50
- VU-sentiment-lexicon library (https://github.com/opener-project/VU-sentiment-lexicon), which needs to be installed.
51
- You can see what the lexicons available for a given language are by calling to the program with the option --show-lexicons LANG,
52
- for instance:
53
- ````shell
54
- core/poltagger-basic-multi.py --show-lexicons nl
55
-
56
- ##############################
57
- Available lexicons for nl
58
- Identifier: "hotel" (Default)
59
- Desc: Hotel domain lexicon for Dutch
60
- Res: VUA_olery_lexicon_nl_lmf
61
- File: /Users/ruben/python_envs/python2.7/lib/python2.7/VUSentimentLexicon/NL-lexicon/Sentiment-Dutch-HotelDomain.xml
62
-
63
- Identifier:"general"
64
- Desc: General lexicon for Dutch
65
- Res: VUA_olery_lexicon_nl_lmf
66
- File: /Users/ruben/python_envs/python2.7/lib/python2.7/VUSentimentLexicon/NL-lexicon/Sentiment-Dutch-general.xml
67
-
68
- ##############################
69
- ````
70
-
71
- Then you can use the lexicon identifiers to select the proper lexicon, with the option --lexicon
72
- ````shell
73
- cat my_input.nl.kaf | core/poltagger-basic-multi.py --lexicon general
74
- ````
75
-
76
- This command will call to the polarity tagger using the general lexicon for Dutch. The lexicon identifiers are unique only per language.
77
- If the lexicon id is not specified(you skip the --lexicon option), or you provide a wrong identifier, the default lexicon will be loaded.
78
- If there is no lexicon marked as default in the --show-lexicon options, the first one in the list will be used. Check the VU-sentiment-lexicon
79
- for further information about how to manage lexicons and add new ones
21
+ ## How-To
22
+
23
+ The main script of this tool is a python file, which accepts a set of parameters
24
+ to determine which features or options we want to use. The language is read from
25
+ the KAF file, so it doesn't need to be specified as a parameter The program
26
+ reads a KAF file from the standard input and writes the resulting KAf in the
27
+ standard output. To see the options you can call to the main script with the -h
28
+ or `--help` option.
29
+
30
+ $ python core/poltagger-basic-multi.py -h
31
+ usage: poltagger-basic-multi.py [-h] [--no-time] [--ignore-pos]
32
+ [--show-lexicons {nl,en,de,es,it,fr}]
33
+ [--lexicon LEXICON] [--silent] [--version]
34
+
35
+ Tags a text with polarities at lemma level
36
+
37
+ optional arguments:
38
+ -h, --help show this help message and exit
39
+ --no-time For not including timestamp in header
40
+ --ignore-pos Ignore the pos labels
41
+ --show-lexicons {nl,en,de,es,it,fr}
42
+ Show lexicons for the given language and exit
43
+ --lexicon LEXICON Lexicon identifier, check with --show-lexicons LANG
44
+ for options
45
+ --lexicon-path LEXICON The path of the lexicons
46
+ --silent Turn off debug info
47
+ --version show program's version number and exit
48
+
49
+ The `--ignore-pos` parameter must be used when want to ignore the part-of-speech
50
+ information assigned to the lemmas, and we want to assign polarities just to the
51
+ lemmas, not considering the POS tag. This could be useful when the information
52
+ provided by the pos-tagger is not accurate or the pos-tagging has not been
53
+ processed.
54
+
55
+ The main options are those concerning with the usage of different lexicons. The
56
+ lexicons are provided by the VU-sentiment-lexicon library
57
+ (https://github.com/opener-project/VU-sentiment-lexicon), which needs to be
58
+ installed. You can see what the lexicons available for a given language are by
59
+ calling to the program with the option --show-lexicons LANG, for instance:
60
+
61
+ core/poltagger-basic-multi.py --show-lexicons nl
62
+
63
+ ##############################
64
+ Available lexicons for nl
65
+ Identifier: "hotel" (Default)
66
+ Desc: Hotel domain lexicon for Dutch
67
+ Res: VUA_olery_lexicon_nl_lmf
68
+ File: /Users/ruben/python_envs/python2.7/lib/python2.7/VUSentimentLexicon/NL-lexicon/Sentiment-Dutch-HotelDomain.xml
69
+
70
+ Identifier:"general"
71
+ Desc: General lexicon for Dutch
72
+ Res: VUA_olery_lexicon_nl_lmf
73
+ File: /Users/ruben/python_envs/python2.7/lib/python2.7/VUSentimentLexicon/NL-lexicon/Sentiment-Dutch-general.xml
74
+
75
+ ##############################
76
+
77
+ Then you can use the lexicon identifiers to select the proper lexicon, with the
78
+ option --lexicon
79
+
80
+ cat my_input.nl.kaf | core/poltagger-basic-multi.py --lexicon general
81
+
82
+ This command will call to the polarity tagger using the general lexicon for
83
+ Dutch. The lexicon identifiers are unique only per language. If the lexicon id
84
+ is not specified(you skip the --lexicon option), or you provide a wrong
85
+ identifier, the default lexicon will be loaded. If there is no lexicon marked
86
+ as default in the --show-lexicon options, the first one in the list will be
87
+ used. Check the VU-sentiment-lexicon for further information about how to manage
88
+ lexicons and add new ones.
80
89
 
81
90
  ### Confused by some terminology?
82
91
 
83
- 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.
92
+ This software is part of a larger collection of natural language processing
93
+ tools known as "the OpeNER project". You can find more information about the
94
+ project at [the OpeNER portal](http://opener-project.github.io). There you can
95
+ also find references to terms like KAF (an XML standard to represent linguistic
96
+ annotations in texts), component, cores, scenario's and pipelines.
84
97
 
85
98
  Quick Use Example
86
99
  -----------------
@@ -89,32 +102,33 @@ Installing the polarity-tagger can be done by executing:
89
102
 
90
103
  gem install opener-polarity-tagger
91
104
 
92
- The polarity tagger uses python. So it is advised to run a virtualenv before installing the gem.
105
+ The polarity tagger uses python. So it is advised to run a virtualenv before
106
+ installing the gem.
93
107
 
94
- Please bare in mind that all components in OpeNER take KAF as an input and output KAF by default.
108
+ Please bare in mind that all components in OpeNER take KAF as an input and
109
+ output KAF by default.
95
110
 
96
111
  ### Command line interface
97
112
 
98
- You should now be able to call the polarity tagger as a regular shell command: by its name. Once installed the gem normally sits in your path so you can call it directly from anywhere.
113
+ You should now be able to call the polarity tagger as a regular shell command:
114
+ by its name. Once installed the gem normally sits in your path so you can call
115
+ it directly from anywhere.
99
116
 
100
117
  This aplication reads a text from standard input in order process it.
101
118
 
102
119
  cat some_kind_of_kaf_file.kaf | polarity-tagger
103
120
 
104
-
105
121
  This will output:
106
122
 
107
- ```
108
- <term lemma="donner" morphofeat="VP3s" pos="V" tid="t119" type="open">
109
- <span>
110
- <!--donne-->
111
- <target id="w119"/>
112
- </span>
113
- <sentiment polarity="neutral" resource="General domain lexicon for French . Vicomtech_general_lexicon_french"/>
114
- </term>
115
- ```
123
+ <term lemma="donner" morphofeat="VP3s" pos="V" tid="t119" type="open">
124
+ <span>
125
+ <!--donne-->
126
+ <target id="w119"/>
127
+ </span>
128
+ <sentiment polarity="neutral" resource="General domain lexicon for French . Vicomtech_general_lexicon_french"/>
129
+ </term>
116
130
 
117
- ##Requirements##
131
+ ## Requirements
118
132
 
119
133
  * Python 2.7.0 or newer
120
134
  * Ruby 1.9.2 or newer
@@ -127,7 +141,8 @@ You can launch a webservice by executing:
127
141
 
128
142
  polarity-tagger-server
129
143
 
130
- This will launch a mini webserver with the webservice. It defaults to port 9292, so you can access it at <http://localhost:9292>.
144
+ This will launch a mini webserver with the webservice. It defaults to port 9292,
145
+ so you can access it at <http://localhost:9292>.
131
146
 
132
147
  To launch it on a different port provide the `-p [port-number]` option like this:
133
148
 
@@ -135,20 +150,24 @@ To launch it on a different port provide the `-p [port-number]` option like this
135
150
 
136
151
  It then launches at <http://localhost:1234>
137
152
 
138
- 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.
139
-
153
+ Documentation on the Webservice is provided by surfing to the urls provided
154
+ above. For more information on how to launch a webservice run the command with
155
+ the `--help` option.
140
156
 
141
157
  ### Daemon
142
158
 
143
- Last but not least the polarity tagger comes shipped with a daemon that can read jobs (and write) jobs to and from Amazon SQS queues. For more information type:
159
+ Last but not least the polarity tagger comes shipped with a daemon that can read
160
+ jobs (and write) jobs to and from Amazon SQS queues. For more information type:
144
161
 
145
162
  polarity-tagger-daemon -h
146
163
 
147
-
148
164
  Description of dependencies
149
165
  ---------------------------
150
166
 
151
- 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)
167
+ This component runs best if you run it in an environment suited for OpeNER
168
+ components. You can find an installation guide and helper tools in the
169
+ [OpeNER installer](https://github.com/opener-project/opener-installer) and an
170
+ [installation guide on the Opener Website](http://opener-project.github.io/getting-started/how-to/local-installation.html)
152
171
 
153
172
  At least you need the following system setup:
154
173
 
@@ -171,7 +190,8 @@ Language Extension
171
190
  The Core
172
191
  --------
173
192
 
174
- The component is a fat wrapper around the actual language technology core. You can find the core technolies in the ``\`core/``` folder.
193
+ The component is a wrapper around the actual language technology core. You
194
+ can find the core technolies in the `core/` folder.
175
195
 
176
196
  Where to go from here
177
197
  ---------------------
@@ -182,10 +202,10 @@ Where to go from here
182
202
  Report problem/Get help
183
203
  -----------------------
184
204
 
185
- If you encounter problems, please email <support@opener-project.eu> or leave an issue in the
205
+ If you encounter problems, please email <support@opener-project.eu> or leave an
206
+ issue in the
186
207
  [issue tracker](https://github.com/opener-project/polarity-tagger/issues).
187
208
 
188
-
189
209
  Contributing
190
210
  ------------
191
211
 
@@ -194,4 +214,3 @@ Contributing
194
214
  3. Commit your changes (`git commit -am 'Add some feature'`)
195
215
  4. Push to the branch (`git push origin my-new-feature`)
196
216
  5. Create new Pull Request
197
-
data/bin/polarity-tagger CHANGED
@@ -1,6 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'opener/core'
4
+
3
5
  require_relative '../lib/opener/polarity_tagger'
4
6
 
5
- cli = Opener::PolarityTagger::CLI.new(:args => ARGV)
6
- cli.run(STDIN.tty? ? nil : STDIN.read)
7
+ switcher = Opener::Core::ResourceSwitcher.new
8
+ cli = Opener::PolarityTagger::CLI.new
9
+
10
+ switcher.bind(cli.parser)
11
+
12
+ cli.run
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'opener/daemons'
4
+ require 'opener/core'
4
5
 
5
- exec_path = File.expand_path('../../exec/polarity-tagger.rb', __FILE__)
6
+ switcher = Opener::Core::ResourceSwitcher.new
7
+ controller = Opener::Daemons::Controller.new(
8
+ :name => 'opener-polarity-tagger',
9
+ :exec_path => File.expand_path('../../exec/polarity-tagger.rb', __FILE__)
10
+ )
6
11
 
7
- Opener::Daemons::Controller.new(
8
- :name => 'polarity-tagger',
9
- :exec_path => exec_path
10
- )
12
+ switcher.bind(controller.parser.parser)
13
+
14
+ controller.run
@@ -1,54 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'puma/cli'
4
- require 'optparse'
3
+ require 'opener/webservice'
5
4
  require 'opener/core'
6
5
 
7
- rack_config = File.expand_path('../../config.ru', __FILE__)
8
- switcher = Opener::Core::ResourceSwitcher.new
9
- puma_args = [rack_config]
10
- switcher_opts = {}
6
+ switcher = Opener::Core::ResourceSwitcher.new
7
+ parser = Opener::Webservice::OptionParser.new(
8
+ 'opener-polarity-tagger',
9
+ File.expand_path('../../config.ru', __FILE__)
10
+ )
11
11
 
12
- option_parser = OptionParser.new do |opts|
13
- opts.banner = "Usage: #{File.basename($0)} [OPTIONS]"
12
+ switcher.bind(parser.parser)
14
13
 
15
- opts.separator "\nOptions:\n\n"
16
-
17
- opts.on('-h', '--help', 'Shows this help message') do
18
- abort option_parser.to_s
19
- end
20
-
21
- opts.on('-S', '--state PATH', 'Where to store the state details') do |val|
22
- puma_args += ['--state', val]
23
- end
24
-
25
- opts.on('-b', '--bind URI', 'URI to bind to (tcp://, unix://, ssl://)') do |val|
26
- puma_args += ['--bind', val]
27
- end
28
-
29
- opts.on('--pidfile PATH', 'Use PATH as a pidfile') do |val|
30
- puma_args += ['--pidfile', val]
31
- end
32
-
33
- opts.on('--daemon', 'Daemonize the server into the background') do |val|
34
- puma_args << '--daemon'
35
- end
36
-
37
- opts.on('-e', '--environment ENVIRONMENT', 'The environment to use') do |val|
38
- puma_args += ['--environment', val]
39
- end
40
-
41
- opts.separator "\nResource Options:\n\n"
42
-
43
- switcher.bind(opts, switcher_opts)
44
- end
45
-
46
- option_parser.parse!(ARGV)
47
-
48
- switcher.install(switcher_opts)
49
-
50
- # Puma on JRuby does some weird stuff with forking/exec. As a result of this we
51
- # *have to* update ARGV as otherwise running Puma as a daemon does not work.
52
- ARGV.replace(puma_args)
53
-
54
- Puma::CLI.new(ARGV).run
14
+ parser.run
@@ -1,19 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'opener/daemons'
4
- require 'opener/core'
5
4
 
6
5
  require_relative '../lib/opener/polarity_tagger'
7
6
 
8
- switcher = Opener::Core::ResourceSwitcher.new
9
- switcher_opts = {}
7
+ daemon = Opener::Daemons::Daemon.new(Opener::PolarityTagger)
10
8
 
11
- parser = Opener::Daemons::OptParser.new do |opts|
12
- switcher.bind(opts, switcher_opts)
13
- end
14
-
15
- options = parser.parse!(ARGV)
16
- daemon = Opener::Daemons::Daemon.new(Opener::PolarityTagger, options)
17
-
18
- switcher.install(switcher_opts)
19
9
  daemon.start
@@ -3,74 +3,64 @@ require 'opener/core'
3
3
  module Opener
4
4
  class PolarityTagger
5
5
  ##
6
- # CLI wrapper around {Opener::LanguageIdentifier} using OptionParser.
6
+ # CLI wrapper around {Opener::LanguageIdentifier} using Slop.
7
7
  #
8
- # @!attribute [r] options
9
- # @return [Hash]
10
- # @!attribute [r] option_parser
11
- # @return [OptionParser]
8
+ # @!attribute [r] parser
9
+ # @return [Slop]
12
10
  #
13
11
  class CLI
14
- attr_reader :options, :option_parser, :resource_switcher
12
+ attr_reader :parser
13
+
14
+ def initialize
15
+ @parser = configure_slop
16
+ end
15
17
 
16
18
  ##
17
- # @param [Hash] options
19
+ # @param [Array] argv
18
20
  #
19
- def initialize(options = {})
20
- @options = options
21
+ def run(argv = ARGV)
22
+ parser.parse(argv)
23
+ end
21
24
 
22
- @resource_switcher = Opener::Core::ResourceSwitcher.new
23
- component_options, options[:args] = Opener::Core::ArgvSplitter.split(options[:args])
25
+ ##
26
+ # @return [Slop]
27
+ #
28
+ def configure_slop
29
+ return Slop.new(:strict => false, :indent => 2, :help => true) do
30
+ banner 'Usage: polarity-tagger [OPTIONS] -- [PYTHON OPTIONS]'
24
31
 
25
- @option_parser = OptionParser.new do |opts|
26
- opts.program_name = 'polarity-tagger'
27
- opts.summary_indent = ' '
32
+ separator <<-EOF.chomp
28
33
 
29
- resource_switcher.bind(opts, @options)
34
+ About:
30
35
 
31
- opts.on('-h', '--help', 'Shows this help message') do
32
- show_help
33
- end
36
+ Component for tagging the polarity of elements in a KAF document. This
37
+ command reads input from STDIN.
34
38
 
35
- opts.on('-v', '--version', 'Shows the current version') do
36
- show_version
37
- end
39
+ Examples:
38
40
 
39
- opts.on('-l', '--log', 'Enable logging to STDERR') do
40
- @options[:logging] = true
41
- end
42
- end
41
+ Processing a KAF file:
43
42
 
44
- option_parser.parse!(component_options)
45
- force = false
46
- resource_switcher.install(@options, force)
47
- end
43
+ cat some_file.kaf | polarity-tagger
48
44
 
49
- ##
50
- # @param [String] input
51
- #
52
- def run(input)
53
- tagger = PolarityTagger.new(options)
45
+ Displaying the underlying kernel options:
54
46
 
55
- stdout, stderr, process = tagger.run(input)
47
+ polarity-tagger -- --help
56
48
 
57
- puts stdout
58
- end
49
+ EOF
59
50
 
60
- private
51
+ separator "\nOptions:\n"
61
52
 
62
- ##
63
- # Shows the help message and exits the program.
64
- #
65
- def show_help
66
- abort option_parser.to_s
67
- end
53
+ on :v, :version, 'Shows the current version' do
54
+ abort "polarity-tagger v#{VERSION} on #{RUBY_DESCRIPTION}"
55
+ end
68
56
 
69
- ##
70
- # Shows the version and exits the program.
71
- #
72
- def show_version
73
- abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
57
+ run do |opts, args|
58
+ tagger = PolarityTagger.new(:args => args)
59
+ input = STDIN.tty? ? nil : STDIN.read
60
+
61
+ puts tagger.run(input)
62
+ end
63
+ end
74
64
  end
75
65
  end # CLI
76
66
  end # PolarityTagger
@@ -1,5 +1,3 @@
1
- require 'sinatra/base'
2
- require 'httpclient'
3
1
  require 'opener/webservice'
4
2
 
5
3
  module Opener
@@ -7,10 +5,11 @@ module Opener
7
5
  ##
8
6
  # Polarity tagger server powered by Sinatra.
9
7
  #
10
- class Server < Webservice
8
+ class Server < Webservice::Server
11
9
  set :views, File.expand_path('../views', __FILE__)
12
- text_processor PolarityTagger
13
- accepted_params :input
10
+
11
+ self.text_processor = PolarityTagger
12
+ self.accepted_params = [:input]
14
13
  end # Server
15
14
  end # PolarityTagger
16
15
  end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class PolarityTagger
3
- VERSION = '2.5.0'
3
+ VERSION = '3.0.0'
4
4
  end # PolarityTagger
5
5
  end # Opener
@@ -11,6 +11,9 @@ module Opener
11
11
  # @!attribute [r] options
12
12
  # @return [Hash]
13
13
  #
14
+ # @!attribute [r] args
15
+ # @return [Array]
16
+ #
14
17
  class PolarityTagger
15
18
  attr_reader :options, :args
16
19
 
@@ -20,6 +23,8 @@ module Opener
20
23
  # @option options [Array] :args Collection of arbitrary arguments to pass
21
24
  # to the underlying kernel.
22
25
  #
26
+ # @option options [String] :resource_path Path to the lexicons to use.
27
+ #
23
28
  def initialize(options = {})
24
29
  @args = options.delete(:args) || []
25
30
  @options = options
@@ -34,14 +39,14 @@ module Opener
34
39
  return "#{adjust_python_path} python -E #{kernel} #{lexicon_path} #{args.join(" ")}"
35
40
  end
36
41
 
42
+ ##
43
+ # @return [String]
44
+ #
37
45
  def lexicon_path
38
- if path = options[:resource_path]
39
- return "--lexicon-path #{path}"
40
- elsif path = ENV['POLARITY_LEXICON_PATH']
41
- return "--lexicon-path #{path}"
42
- else
43
- return nil
44
- end
46
+ path = options[:resource_path] || ENV['RESOURCE_PATH'] ||
47
+ ENV['POLARITY_LEXICON_PATH']
48
+
49
+ return path ? "--lexicon-path #{path}" : nil
45
50
  end
46
51
 
47
52
  ##
@@ -52,21 +57,21 @@ module Opener
52
57
  # @return [Array]
53
58
  #
54
59
  def run(input)
55
- begin
56
- stdout, stderr, process = capture(input)
57
- raise stderr unless process.success?
58
- return stdout
59
- rescue Exception => error
60
- return Opener::Core::ErrorLayer.new(input, error.message, self.class).add
61
- end
60
+ stdout, stderr, process = capture(input)
61
+
62
+ raise stderr unless process.success?
63
+
64
+ return stdout
62
65
  end
63
66
 
64
67
  protected
68
+
65
69
  ##
66
70
  # @return [String]
67
71
  #
68
72
  def adjust_python_path
69
73
  site_packages = File.join(core_dir, 'site-packages')
74
+
70
75
  "env PYTHONPATH=#{site_packages}:$PYTHONPATH"
71
76
  end
72
77
 
@@ -29,15 +29,14 @@ Gem::Specification.new do |gem|
29
29
 
30
30
  gem.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
31
31
 
32
+ gem.add_dependency 'opener-daemons', '~> 2.2'
33
+ gem.add_dependency 'opener-webservice', '~> 2.1'
34
+ gem.add_dependency 'opener-core', '~> 2.2'
35
+
32
36
  gem.add_dependency 'rake'
33
- gem.add_dependency 'sinatra'
34
- gem.add_dependency 'httpclient'
35
- gem.add_dependency 'puma'
36
- gem.add_dependency 'opener-daemons'
37
- gem.add_dependency 'opener-webservice'
38
- gem.add_dependency 'opener-core', '~> 1.0'
39
37
  gem.add_dependency 'nokogiri'
40
38
  gem.add_dependency 'cliver'
39
+ gem.add_dependency 'slop', '~> 3.5'
41
40
 
42
41
  gem.add_development_dependency 'rspec', '~> 3.0'
43
42
  gem.add_development_dependency 'cucumber'
metadata CHANGED
@@ -1,59 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-polarity-tagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-25 00:00:00.000000000 Z
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: opener-daemons
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: sinatra
28
+ name: opener-webservice
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
- name: httpclient
42
+ name: opener-core
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '2.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '2.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: puma
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: opener-daemons
70
+ name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: opener-webservice
84
+ name: cliver
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,47 +95,19 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: opener-core
98
+ name: slop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '1.0'
103
+ version: '3.5'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '1.0'
111
- - !ruby/object:Gem::Dependency
112
- name: nokogiri
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: cliver
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
110
+ version: '3.5'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: rspec
141
113
  requirement: !ruby/object:Gem::Requirement