opener-ned 2.0.3 → 2.0.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: d35edcc5163e7ee4acf369a40f5ed7ffc6cfed6b
4
- data.tar.gz: dfa909cba69922c488a5facd694f1971fd4cc0d0
3
+ metadata.gz: ee1efe28b8ebe6ded998c4c332d54d223373696a
4
+ data.tar.gz: 442d071af7a75fae2dc59199106944c269196168
5
5
  SHA512:
6
- metadata.gz: 42524f900603fdad922bff9a40a5f50ca69b3e6c9466706f42f6d8f5608b1cb5f59b81460d57249eabe489a55cbbd46cb90c515d3134a59040e0050e5d411014
7
- data.tar.gz: e9e2f0e4ab781a3c853b6883549923239c531751036e2a9501d13918a6b801fd7631016ec4783ad1bfb15f674a11465801124dcaecd54e5dc97c749de32da7c4
6
+ metadata.gz: 4c68995447104271cc30b3cd0e94a560c8c931c86274735c2a9091fa3dc1455a0219328c4bed28e909c5d3fcb18a2d13355a28c6759d3f4a5064de0f67dd1647
7
+ data.tar.gz: edae0c4ca159a514d809fcd67f5ca75db2eed3df88d394e1095147cdac59d607c9bd2d37f78d59cebd91388648dbc523736892a8aa6795bc79d70a9ba7224a6c
data/README.md CHANGED
@@ -97,7 +97,7 @@ Language Extension
97
97
  Where to go from here
98
98
  ---------------------
99
99
 
100
- * [Check the project websitere](http://opener-project.github.io)
100
+ * [Check the project website](http://opener-project.github.io)
101
101
  * [Checkout the webservice](http://opener.olery.com/ned)
102
102
 
103
103
  Report problem/Get help
Binary file
@@ -7,6 +7,7 @@ require File.expand_path('../../../core/target/ehu-ned-1.0.jar', __FILE__)
7
7
 
8
8
  require_relative 'ned/version'
9
9
  require_relative 'ned/cli'
10
+ require_relative 'ned/error_layer'
10
11
 
11
12
  import 'java.io.InputStreamReader'
12
13
 
@@ -60,25 +61,30 @@ module Opener
60
61
  end
61
62
 
62
63
  def run(input)
63
- if !input or input.strip.empty?
64
- raise ArgumentError, 'No input specified'
65
- end
64
+ begin
65
+ if !input or input.strip.empty?
66
+ raise ArgumentError, 'No input specified'
67
+ end
66
68
 
67
- language = language_from_kaf(input)
69
+ language = language_from_kaf(input)
68
70
 
69
- input_io = StringIO.new(input)
70
- reader = InputStreamReader.new(input_io.to_inputstream)
71
- document = KAFDocument.create_from_stream(reader)
72
- annotator = Java::ehu.ned.Annotate.new
71
+ input_io = StringIO.new(input)
72
+ reader = InputStreamReader.new(input_io.to_inputstream)
73
+ document = KAFDocument.create_from_stream(reader)
74
+ annotator = Java::ehu.ned.Annotate.new
73
75
 
74
- endpoint = @options.fetch(:endpoint, uri_for_language(language))
76
+ endpoint = @options.fetch(:endpoint, uri_for_language(language))
75
77
 
76
- annotator.disambiguateNEsToKAF(
77
- document,
78
- endpoint.to_s
79
- )
78
+ annotator.disambiguateNEsToKAF(
79
+ document,
80
+ endpoint.to_s
81
+ )
80
82
 
81
- return document.to_string
83
+ return document.to_string
84
+
85
+ rescue Exception => error
86
+ return ErrorLayer.new(input, error.message, self.class).add
87
+ end
82
88
  end
83
89
 
84
90
  private
@@ -0,0 +1,89 @@
1
+ module Opener
2
+ class Ned
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
82
+ error_node['version'] = klass::VERSION
83
+ error_node.inner_html = error
84
+ node.add_child(error_node)
85
+ end
86
+
87
+ end # ErrorLayer
88
+ end # Ned
89
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  class Ned
3
- VERSION = '2.0.3'
3
+ VERSION = '2.0.4'
4
4
  end # Ned
5
5
  end # Opener
@@ -29,6 +29,6 @@ Gem::Specification.new do |gem|
29
29
  gem.add_dependency 'opener-daemons'
30
30
  gem.add_dependency 'opener-core', ['>= 0.1.2']
31
31
 
32
- gem.add_development_dependency 'opener-build-tools'
33
32
  gem.add_development_dependency 'rake'
33
+ gem.add_development_dependency 'cliver'
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-ned
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -109,7 +109,7 @@ dependencies:
109
109
  prerelease: false
110
110
  type: :runtime
111
111
  - !ruby/object:Gem::Dependency
112
- name: opener-build-tools
112
+ name: rake
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '>='
@@ -123,7 +123,7 @@ dependencies:
123
123
  prerelease: false
124
124
  type: :development
125
125
  - !ruby/object:Gem::Dependency
126
- name: rake
126
+ name: cliver
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '>='
@@ -154,6 +154,7 @@ files:
154
154
  - exec/ned.rb
155
155
  - lib/opener/ned.rb
156
156
  - lib/opener/ned/cli.rb
157
+ - lib/opener/ned/error_layer.rb
157
158
  - lib/opener/ned/public/markdown.css
158
159
  - lib/opener/ned/server.rb
159
160
  - lib/opener/ned/version.rb
@@ -183,4 +184,3 @@ signing_key:
183
184
  specification_version: 4
184
185
  summary: NED client using DBpedia
185
186
  test_files: []
186
- has_rdoc: yard