opener-coreference 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee05da1ff5a222b40be551446c926533db97d26e
4
+ data.tar.gz: 527b3e3e9e00e4fc6b3e25ab4730dfe6e1a350fc
5
+ SHA512:
6
+ metadata.gz: 6e81370c6d5fce240446d7850cadba70263d9bda5a6b5d37082ad48fd35a194563ba35c66f6423a02475f9086f365ae4ec6ac707df37422979a30922b58eef45
7
+ data.tar.gz: 13a70c127790d1b267e234e0df65772086b6d931852f764f05169454462efe6f44d7367ebae4327833d69fde50b84193f69533fbdd3f82a6ee8e5c03dfe5dfb3
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Opener::Coreference
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'opener-coreference'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install opener-coreference
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/bin/coreference ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/opener/coreference'
4
+
5
+ cli = Opener::Coreference::CLI.new(:args => ARGV)
6
+
7
+ cli.run(STDIN.tty? ? nil : STDIN.read)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rack'
4
+
5
+ # Without calling `Rack::Server#options` manually the CLI arguments will never
6
+ # be passed, thus the application can't be specified as a constructor argument.
7
+ server = Rack::Server.new
8
+ server.options[:config] = File.expand_path('../../config.ru', __FILE__)
9
+
10
+ server.start
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ require File.expand_path('../lib/opener/coreference', __FILE__)
2
+ require File.expand_path('../lib/opener/coreference/server', __FILE__)
3
+
4
+ run Opener::Coreference::Server
@@ -0,0 +1,87 @@
1
+ module Opener
2
+ class Coreference
3
+ ##
4
+ # CLI wrapper around {Opener::Coreference} using OptionParser.
5
+ #
6
+ # @!attribute [r] options
7
+ # @return [Hash]
8
+ # @!attribute [r] option_parser
9
+ # @return [OptionParser]
10
+ #
11
+ class CLI
12
+ attr_reader :options, :option_parser
13
+
14
+ ##
15
+ # @param [Hash] options
16
+ #
17
+ def initialize(options = {})
18
+ @options = DEFAULT_OPTIONS.merge(options)
19
+
20
+ @option_parser = OptionParser.new do |opts|
21
+ opts.program_name = 'coreference'
22
+ opts.summary_indent = ' '
23
+
24
+ opts.on('-h', '--help', 'Shows this help message') do
25
+ show_help
26
+ end
27
+
28
+ opts.on('-v', '--version', 'Shows the current version') do
29
+ show_version
30
+ end
31
+
32
+ opts.separator <<-EOF
33
+
34
+ Examples:
35
+
36
+ cat example.kaf | #{opts.program_name}
37
+
38
+ Supported Languages (taken from kaf lang element):
39
+
40
+ * Dutch (nl)
41
+ * English (en)
42
+ * French (fr)
43
+ * German (de)
44
+ * Italian (it)
45
+ * Spanish (es)
46
+ EOF
47
+ end
48
+ end
49
+
50
+ ##
51
+ # @param [String] input
52
+ #
53
+ def run(input)
54
+ option_parser.parse!(options[:args])
55
+
56
+ tokenizer = Coreference.new(options)
57
+
58
+ stdout, stderr, process = tokenizer.run(input)
59
+
60
+ if process.success?
61
+ puts stdout
62
+
63
+ STDERR.puts(stderr) unless stderr.empty?
64
+ else
65
+ abort stderr
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ ##
72
+ # Shows the help message and exits the program.
73
+ #
74
+ def show_help
75
+ abort option_parser.to_s
76
+ end
77
+
78
+ ##
79
+ # Shows the version and exits the program.
80
+ #
81
+ def show_version
82
+ abort "#{option_parser.program_name} v#{VERSION} on #{RUBY_DESCRIPTION}"
83
+ end
84
+ end # CLI
85
+ end # Ner
86
+ end # Opener
87
+
@@ -0,0 +1,283 @@
1
+ input[type="text"], textarea
2
+ {
3
+ width: 500px;
4
+ }
5
+
6
+ body {
7
+ font-family: Helvetica, arial, sans-serif;
8
+ font-size: 14px;
9
+ line-height: 1.6;
10
+ padding-top: 10px;
11
+ padding-bottom: 10px;
12
+ background-color: white;
13
+ padding: 30px; }
14
+
15
+ body > *:first-child {
16
+ margin-top: 0 !important; }
17
+ body > *:last-child {
18
+ margin-bottom: 0 !important; }
19
+
20
+ a {
21
+ color: #4183C4; }
22
+ a.absent {
23
+ color: #cc0000; }
24
+ a.anchor {
25
+ display: block;
26
+ padding-left: 30px;
27
+ margin-left: -30px;
28
+ cursor: pointer;
29
+ position: absolute;
30
+ top: 0;
31
+ left: 0;
32
+ bottom: 0; }
33
+
34
+ h1, h2, h3, h4, h5, h6 {
35
+ margin: 20px 0 10px;
36
+ padding: 0;
37
+ font-weight: bold;
38
+ -webkit-font-smoothing: antialiased;
39
+ cursor: text;
40
+ position: relative; }
41
+
42
+ h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
43
+ background: url("../../images/modules/styleguide/para.png") no-repeat 10px center;
44
+ text-decoration: none; }
45
+
46
+ h1 tt, h1 code {
47
+ font-size: inherit; }
48
+
49
+ h2 tt, h2 code {
50
+ font-size: inherit; }
51
+
52
+ h3 tt, h3 code {
53
+ font-size: inherit; }
54
+
55
+ h4 tt, h4 code {
56
+ font-size: inherit; }
57
+
58
+ h5 tt, h5 code {
59
+ font-size: inherit; }
60
+
61
+ h6 tt, h6 code {
62
+ font-size: inherit; }
63
+
64
+ h1 {
65
+ font-size: 28px;
66
+ color: black; }
67
+
68
+ h2 {
69
+ font-size: 24px;
70
+ border-bottom: 1px solid #cccccc;
71
+ color: black; }
72
+
73
+ h3 {
74
+ font-size: 18px; }
75
+
76
+ h4 {
77
+ font-size: 16px; }
78
+
79
+ h5 {
80
+ font-size: 14px; }
81
+
82
+ h6 {
83
+ color: #777777;
84
+ font-size: 14px; }
85
+
86
+ p, blockquote, ul, ol, dl, li, table, pre {
87
+ margin: 15px 0; }
88
+
89
+ hr {
90
+ background: transparent url("../../images/modules/pulls/dirty-shade.png") repeat-x 0 0;
91
+ border: 0 none;
92
+ color: #cccccc;
93
+ height: 4px;
94
+ padding: 0; }
95
+
96
+ body > h2:first-child {
97
+ margin-top: 0;
98
+ padding-top: 0; }
99
+ body > h1:first-child {
100
+ margin-top: 0;
101
+ padding-top: 0; }
102
+ body > h1:first-child + h2 {
103
+ margin-top: 0;
104
+ padding-top: 0; }
105
+ body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
106
+ margin-top: 0;
107
+ padding-top: 0; }
108
+
109
+ a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
110
+ margin-top: 0;
111
+ padding-top: 0; }
112
+
113
+ h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
114
+ margin-top: 0; }
115
+
116
+ li p.first {
117
+ display: inline-block; }
118
+
119
+ ul, ol {
120
+ padding-left: 30px; }
121
+
122
+ ul :first-child, ol :first-child {
123
+ margin-top: 0; }
124
+
125
+ ul :last-child, ol :last-child {
126
+ margin-bottom: 0; }
127
+
128
+ dl {
129
+ padding: 0; }
130
+ dl dt {
131
+ font-size: 14px;
132
+ font-weight: bold;
133
+ font-style: italic;
134
+ padding: 0;
135
+ margin: 15px 0 5px; }
136
+ dl dt:first-child {
137
+ padding: 0; }
138
+ dl dt > :first-child {
139
+ margin-top: 0; }
140
+ dl dt > :last-child {
141
+ margin-bottom: 0; }
142
+ dl dd {
143
+ margin: 0 0 15px;
144
+ padding: 0 15px; }
145
+ dl dd > :first-child {
146
+ margin-top: 0; }
147
+ dl dd > :last-child {
148
+ margin-bottom: 0; }
149
+
150
+ blockquote {
151
+ border-left: 4px solid #dddddd;
152
+ padding: 0 15px;
153
+ color: #777777; }
154
+ blockquote > :first-child {
155
+ margin-top: 0; }
156
+ blockquote > :last-child {
157
+ margin-bottom: 0; }
158
+
159
+ table {
160
+ padding: 0; }
161
+ table tr {
162
+ border-top: 1px solid #cccccc;
163
+ background-color: white;
164
+ margin: 0;
165
+ padding: 0; }
166
+ table tr:nth-child(2n) {
167
+ background-color: #f8f8f8; }
168
+ table tr th {
169
+ font-weight: bold;
170
+ border: 1px solid #cccccc;
171
+ text-align: left;
172
+ margin: 0;
173
+ padding: 6px 13px; }
174
+ table tr td {
175
+ border: 1px solid #cccccc;
176
+ text-align: left;
177
+ margin: 0;
178
+ padding: 6px 13px; }
179
+ table tr th :first-child, table tr td :first-child {
180
+ margin-top: 0; }
181
+ table tr th :last-child, table tr td :last-child {
182
+ margin-bottom: 0; }
183
+
184
+ img {
185
+ max-width: 100%; }
186
+
187
+ span.frame {
188
+ display: block;
189
+ overflow: hidden; }
190
+ span.frame > span {
191
+ border: 1px solid #dddddd;
192
+ display: block;
193
+ float: left;
194
+ overflow: hidden;
195
+ margin: 13px 0 0;
196
+ padding: 7px;
197
+ width: auto; }
198
+ span.frame span img {
199
+ display: block;
200
+ float: left; }
201
+ span.frame span span {
202
+ clear: both;
203
+ color: #333333;
204
+ display: block;
205
+ padding: 5px 0 0; }
206
+ span.align-center {
207
+ display: block;
208
+ overflow: hidden;
209
+ clear: both; }
210
+ span.align-center > span {
211
+ display: block;
212
+ overflow: hidden;
213
+ margin: 13px auto 0;
214
+ text-align: center; }
215
+ span.align-center span img {
216
+ margin: 0 auto;
217
+ text-align: center; }
218
+ span.align-right {
219
+ display: block;
220
+ overflow: hidden;
221
+ clear: both; }
222
+ span.align-right > span {
223
+ display: block;
224
+ overflow: hidden;
225
+ margin: 13px 0 0;
226
+ text-align: right; }
227
+ span.align-right span img {
228
+ margin: 0;
229
+ text-align: right; }
230
+ span.float-left {
231
+ display: block;
232
+ margin-right: 13px;
233
+ overflow: hidden;
234
+ float: left; }
235
+ span.float-left span {
236
+ margin: 13px 0 0; }
237
+ span.float-right {
238
+ display: block;
239
+ margin-left: 13px;
240
+ overflow: hidden;
241
+ float: right; }
242
+ span.float-right > span {
243
+ display: block;
244
+ overflow: hidden;
245
+ margin: 13px auto 0;
246
+ text-align: right; }
247
+
248
+ code, tt {
249
+ margin: 0 2px;
250
+ padding: 0 5px;
251
+ white-space: nowrap;
252
+ border: 1px solid #eaeaea;
253
+ background-color: #f8f8f8;
254
+ border-radius: 3px; }
255
+
256
+ pre code {
257
+ margin: 0;
258
+ padding: 0;
259
+ white-space: pre;
260
+ border: none;
261
+ background: transparent; }
262
+
263
+ .highlight pre {
264
+ background-color: #f8f8f8;
265
+ border: 1px solid #cccccc;
266
+ font-size: 13px;
267
+ line-height: 19px;
268
+ overflow: auto;
269
+ padding: 6px 10px;
270
+ border-radius: 3px; }
271
+
272
+ pre {
273
+ background-color: #f8f8f8;
274
+ border: 1px solid #cccccc;
275
+ font-size: 13px;
276
+ line-height: 19px;
277
+ overflow: auto;
278
+ padding: 6px 10px;
279
+ border-radius: 3px; }
280
+ pre code, pre tt {
281
+ background-color: transparent;
282
+ border: none; }
283
+
@@ -0,0 +1,17 @@
1
+ require 'sinatra/base'
2
+ require 'opener/webservice'
3
+ require 'httpclient'
4
+
5
+ module Opener
6
+ class Coreference
7
+ ##
8
+ # Coreference server powered by Sinatra.
9
+ #
10
+ class Server < Webservice
11
+ set :views, File.expand_path('../views', __FILE__)
12
+ text_processor Coreference
13
+ accepted_params :input
14
+ end # Server
15
+ end # Ner
16
+ end # Opener
17
+
@@ -0,0 +1,5 @@
1
+ module Opener
2
+ class Coreference
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <link type="text/css" rel="stylesheet" href="markdown.css" />
5
+
6
+ <title>Coreference Webservice</title>
7
+ </head>
8
+ <body>
9
+ <h1>Coreference Webservice</h1>
10
+
11
+ <p>
12
+ * required
13
+
14
+ <br />
15
+
16
+ ** When entering a value no response will be displayed in the browser.
17
+ </p>
18
+
19
+ <form action="<%=url("/")%>" method="POST">
20
+ <div>
21
+ <label for="input">KAF input *</label>
22
+ <br />
23
+
24
+ <textarea id="input" name="input" cols="50" rows="10"></textarea>
25
+ </div>
26
+
27
+ <div>
28
+ <label for="callbacks">Callback URL (**)</label>
29
+ <br />
30
+
31
+ <input id="callbacks" type="text" name="callbacks" />
32
+ </div>
33
+
34
+ <div>
35
+ <label for="error_callback">Error Callback</label>
36
+ <br />
37
+
38
+ <input id="error_callback" type="text" name="error_callback" />
39
+ </div>
40
+
41
+ <input type="submit" value="Submit" />
42
+ </form>
43
+
44
+ <h2>Actions</h2>
45
+
46
+ <dl>
47
+ <dt>GET /</dt>
48
+ <dd>Shows this page</dd>
49
+
50
+ <dt>POST /</dt>
51
+ <dd>Submits a KAF document</dd>
52
+ </dl>
53
+
54
+ <h2>Parameters</h2>
55
+
56
+ <dl>
57
+ <dt>text *</dt>
58
+ <dd>The KAF document to tag.</dd>
59
+
60
+ <dt>callbacks</dt>
61
+ <dd>A collection of callback URLs that are processed as a chain.</dd>
62
+
63
+ <dt>error_callback</dt>
64
+ <dd>Errors are submitted to this URL in the "error" field.</dd>
65
+ </dl>
66
+ </body>
67
+ </html>
@@ -0,0 +1,76 @@
1
+ require 'optparse'
2
+ require 'opener/coreferences/base'
3
+ require 'nokogiri'
4
+
5
+ require_relative 'coreference/version'
6
+ require_relative 'coreference/cli'
7
+
8
+ module Opener
9
+ class Coreference
10
+ attr_reader :options
11
+
12
+ ##
13
+ # Hash containing the default options to use.
14
+ #
15
+ # @return [Hash]
16
+ #
17
+ DEFAULT_OPTIONS = {
18
+ :args => [],
19
+ }.freeze
20
+
21
+ ##
22
+ # @param [Hash] options
23
+ #
24
+ # @option options [Array] :args Collection of arbitrary arguments to pass
25
+ # to the underlying kernels.
26
+ # @option options [String] :language The language to use.
27
+ #
28
+ def initialize(options = {})
29
+ @options = DEFAULT_OPTIONS.merge(options)
30
+ end
31
+
32
+ ##
33
+ # Processes the input and returns an array containing the output of STDOUT,
34
+ # STDERR and an object containing process information.
35
+ #
36
+ # @param [String] input
37
+ # @return [Array]
38
+ #
39
+ def run(input)
40
+ language = language_from_kaf(input)
41
+ args = options[:args].dup
42
+
43
+ if language_constant_defined?(language)
44
+ kernel = language.new(:args => args)
45
+ else
46
+ kernel = Coreferences::Base.new(:args => args, :language => language)
47
+ end
48
+
49
+ return kernel.run(input)
50
+ end
51
+
52
+ protected
53
+
54
+ ##
55
+ # Returns `true` if the current language has a dedicated kernel class.
56
+ #
57
+ # @return [TrueClass|FalseClass]
58
+ #
59
+ def language_constant_defined?(language)
60
+ return Coreferences.const_defined?(language.upcase)
61
+ end
62
+
63
+ ##
64
+ # @return [Class]
65
+ #
66
+ def language_constant
67
+ return Coreferences.const_get(language_constant_name)
68
+ end
69
+
70
+ def language_from_kaf(input)
71
+ reader = Nokogiri::XML::Reader(input)
72
+
73
+ return reader.read.lang
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../lib/opener/coreference/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "opener-coreference"
5
+ gem.version = Opener::Coreference::VERSION
6
+ gem.authors = ["development@olery.com"]
7
+ gem.summary = "Gem that wraps the coreference code"
8
+ gem.description = gem.summary
9
+
10
+ gem.has_rdoc = "yard"
11
+ gem.required_ruby_version = ">= 1.9.2"
12
+
13
+ gem.files = Dir.glob([
14
+ 'lib/**/*',
15
+ 'config.ru',
16
+ '*.gemspec',
17
+ 'README.md'
18
+ ]).select { |file| File.file?(file) }
19
+
20
+ gem.executables = Dir.glob('bin/*').map { |file| File.basename(file) }
21
+
22
+ gem.add_dependency 'sinatra', '~> 1.4'
23
+ gem.add_dependency 'httpclient'
24
+ gem.add_dependency 'opener-coreference-base'
25
+ gem.add_dependency 'opener-webservice'
26
+
27
+ gem.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opener-coreference
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - development@olery.com
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: opener-coreference-base
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opener-webservice
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Gem that wraps the coreference code
84
+ email:
85
+ executables:
86
+ - coreference
87
+ - coreference-server
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - bin/coreference
93
+ - bin/coreference-server
94
+ - config.ru
95
+ - lib/opener/coreference.rb
96
+ - lib/opener/coreference/cli.rb
97
+ - lib/opener/coreference/public/markdown.css
98
+ - lib/opener/coreference/server.rb
99
+ - lib/opener/coreference/version.rb
100
+ - lib/opener/coreference/views/index.erb
101
+ - opener-coreference.gemspec
102
+ homepage:
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 1.9.2
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Gem that wraps the coreference code
125
+ test_files: []
126
+ has_rdoc: yard