opener-ner 2.0.2 → 2.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: 5c77d158e1dd7057cdde02e255491363f5ec351f
4
- data.tar.gz: f6dceeec56433da36aff8f86e400386505251992
3
+ metadata.gz: b7e44ba3a70a79bde04d36f74e250a6d0de510df
4
+ data.tar.gz: 0c5dc588060d3d8fc9b87f291f186d3efc37d655
5
5
  SHA512:
6
- metadata.gz: 0a0bf3e06f4dfa59b632d35918a2c6b325061d30d753856660acf5998eecc97e2443e83b7ffe6c313e3504311918d3e2d3b207fd6f5b4c563d3faeff1731422d
7
- data.tar.gz: ec1b103186afb95179b4edaa70f2a7148e47c4e96167de8113ad6ed6d78f1bb470a5389397de534502b667699f40d14c0ae923ac98dda802d058fa503692fd48
6
+ metadata.gz: 0ed9b436a48192cd51e291bfd65f312d5d526a9cef8f1d20f71362f05b31f1e9cd9881d8c39340e30dadf0b380bc656049111d2df144cdbe0b5a6610d75a345a
7
+ data.tar.gz: ea6ef030833d7c91906a892240ab651c5904d4ed52db927ebc5171c4e41193c03d3a8802a1fe2dee9ac1da82d25f37acd7a3e0fd30d80bfecb9399fa1656b58f
data/README.md CHANGED
@@ -1,16 +1,11 @@
1
1
  # NER
2
2
 
3
- This repository contains the source code for the primary NER component of the
4
- OpeNER project. This component provides a CLI interface for the various kernels
5
- as well as providing a Sinatra based web service.
3
+ This repository contains the source code for the primary NER component of the OpeNER project. This component provides a CLI interface for the various kernels as well as providing a Sinatra based web service.
6
4
 
7
5
  ### Confused by some terminology?
8
6
 
9
- This software is part of a larger collection of natural language processing
10
- tools known as "the OpeNER project". You can find more information about the
11
- project at [the OpeNER portal](http://opener-project.github.io). There you can
12
- also find references to terms like KAF (an XML standard to represent linguistic
13
- annotations in texts), component, cores, scenario's and pipelines.
7
+ 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.
8
+
14
9
 
15
10
  Quick Use Example
16
11
  -----------------
@@ -19,21 +14,18 @@ Installing the ner can be done by executing:
19
14
 
20
15
  gem install opener-ner
21
16
 
22
- Please bare in mind that all components in OpeNER take KAF as an input and
23
- output KAF by default.
17
+ Please bare in mind that all components in OpeNER take KAF as an input and output KAF by default.
24
18
 
25
19
  ### Command line interface
26
20
 
27
- You should now be able to call the NER as a regular shell
28
- command: by its name. Once installed the gem normalyl sits in your path so you can call it directly from anywhere.
21
+ You should now be able to call the NER as a regular shell command: by its name. Once installed the gem normalyl sits in your path so you can call it directly from anywhere.
29
22
 
30
23
  This aplication reads a text from standard input in order to identify the language.
31
24
 
32
25
  cat some_kind_of_kaf_file.kaf | ner
33
26
 
34
27
 
35
- This will output a kaf file containing the named entities. An excerpt can be
36
- seen here
28
+ This will output a kaf file containing the named entities. An excerpt can be seen here
37
29
 
38
30
  ```
39
31
  <entity eid="e3" type="organization">
@@ -54,26 +46,20 @@ You can launch a language identification webservice by executing:
54
46
 
55
47
  ner-server
56
48
 
57
- This will launch a mini webserver with the webservice. It defaults to port 9292,
58
- so you can access it at <http://localhost:9292>.
49
+ This will launch a mini webserver with the webservice. It defaults to port 9292, so you can access it at <http://localhost:9292>.
59
50
 
60
- To launch it on a different port provide the `-p [port-number]` option like
61
- this:
51
+ To launch it on a different port provide the `-p [port-number]` option like this:
62
52
 
63
53
  ner-server -p 1234
64
54
 
65
55
  It then launches at <http://localhost:1234>
66
56
 
67
- Documentation on the Webservice is provided by surfing to the urls provided
68
- above. For more information on how to launch a webservice run the command with
69
- the ```-h``` option.
57
+ 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.
70
58
 
71
59
 
72
60
  ### Daemon
73
61
 
74
- Last but not least the NER comes shipped with a daemon that
75
- can read jobs (and write) jobs to and from Amazon SQS queues. For more
76
- information type:
62
+ Last but not least the NER comes shipped with a daemon that can read jobs (and write) jobs to and from Amazon SQS queues. For more information type:
77
63
 
78
64
  ner-daemon -h
79
65
 
@@ -81,8 +67,7 @@ information type:
81
67
  Description of dependencies
82
68
  ---------------------------
83
69
 
84
- This component runs best if you run it in an environment suited for OpeNER
85
- components. You can find an installation guide and helper tools in the [OpeNER installer](https://github.com/opener-project/opener-installer) and an
70
+ 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
86
71
  [installation guide on the Opener Website](http://opener-project.github.io/getting-started/how-to/local-installation.html)
87
72
 
88
73
  At least you need the following system setup:
@@ -109,8 +94,7 @@ Language Extension
109
94
  The Core
110
95
  --------
111
96
 
112
- The component is a fat wrapper around the actual language technology core. You
113
- can find the core technolies in the following repositories:
97
+ The component is a fat wrapper around the actual language technology core. You can find the core technolies in the following repositories:
114
98
 
115
99
  * [ner-base](https://github.com/opener-project/ner-base)
116
100
 
@@ -118,14 +102,14 @@ can find the core technolies in the following repositories:
118
102
  Where to go from here
119
103
  ---------------------
120
104
 
121
- * [Check the project websitere](http://opener-project.github.io)
105
+ * [Check the project website](http://opener-project.github.io)
122
106
  * [Checkout the webservice](http://opener.olery.com/ner)
123
107
 
124
108
  Report problem/Get help
125
109
  -----------------------
126
110
 
127
- If you encounter problems, please email <support@opener-project.eu> or leave an
128
- issue in the [issue tracker](https://github.com/opener-project/ner/issues).
111
+ If you encounter problems, please email <support@opener-project.eu> or leave an issue in the
112
+ [issue tracker](https://github.com/opener-project/ner/issues).
129
113
 
130
114
 
131
115
  Contributing
@@ -4,6 +4,7 @@ require 'nokogiri'
4
4
 
5
5
  require_relative 'ner/version'
6
6
  require_relative 'ner/cli'
7
+ require_relative 'ner/error_layer'
7
8
 
8
9
  module Opener
9
10
  ##
@@ -52,16 +53,20 @@ module Opener
52
53
  # @return [Array]
53
54
  #
54
55
  def run(input)
55
- language = language_from_kaf(input) || DEFAULT_LANGUAGE
56
- args = options[:args].dup
56
+ begin
57
+ language = language_from_kaf(input) || DEFAULT_LANGUAGE
58
+ args = options[:args].dup
57
59
 
58
- if language_constant_defined?(language)
59
- kernel = language_constant(language).new(:args => args)
60
- else
61
- kernel = Ners::Base.new(:args => args, :language => language)
62
- end
60
+ if language_constant_defined?(language)
61
+ kernel = language_constant(language).new(:args => args)
62
+ else
63
+ kernel = Ners::Base.new(:args => args, :language => language)
64
+ end
63
65
 
64
- return kernel.run(input)
66
+ return kernel.run(input)
67
+ rescue Exception => error
68
+ return ErrorLayer.new(input, error.message, self.class).add
69
+ end
65
70
  end
66
71
 
67
72
  protected
@@ -0,0 +1,88 @@
1
+ module Opener
2
+ class Ner
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 # Ner
88
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class Ner
3
- VERSION = '2.0.2'
3
+ VERSION = '2.0.3'
4
4
  end # NER
5
5
  end # Opener
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-ner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
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-05-23 00:00:00.000000000 Z
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -140,24 +140,25 @@ description: Primary NER component that wraps the various NER kernels.
140
140
  email:
141
141
  executables:
142
142
  - ner
143
- - ner-server
144
143
  - ner-daemon
144
+ - ner-server
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
+ - README.md
149
+ - bin/ner
150
+ - bin/ner-daemon
151
+ - bin/ner-server
152
+ - config.ru
153
+ - exec/ner.rb
148
154
  - lib/opener/ner.rb
149
- - lib/opener/ner/version.rb
150
- - lib/opener/ner/server.rb
151
155
  - lib/opener/ner/cli.rb
156
+ - lib/opener/ner/error_layer.rb
152
157
  - lib/opener/ner/public/markdown.css
158
+ - lib/opener/ner/server.rb
159
+ - lib/opener/ner/version.rb
153
160
  - lib/opener/ner/views/index.erb
154
- - config.ru
155
161
  - opener-ner.gemspec
156
- - README.md
157
- - exec/ner.rb
158
- - bin/ner
159
- - bin/ner-server
160
- - bin/ner-daemon
161
162
  homepage:
162
163
  licenses: []
163
164
  metadata: {}
@@ -177,9 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  version: '0'
178
179
  requirements: []
179
180
  rubyforge_project:
180
- rubygems_version: 2.1.9
181
+ rubygems_version: 2.2.2
181
182
  signing_key:
182
183
  specification_version: 4
183
184
  summary: Primary NER component that wraps the various NER kernels.
184
185
  test_files: []
185
- has_rdoc: yard