opener-ned 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/core/target/ehu-ned-1.0.jar +0 -0
- data/lib/opener/ned.rb +20 -14
- data/lib/opener/ned/error_layer.rb +89 -0
- data/lib/opener/ned/version.rb +1 -1
- data/opener-ned.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b3f47e84d065fd802d47943ae7a506a06d6b6ba
|
4
|
+
data.tar.gz: 88c4921c36cf5b5c5e8660cc966a5c0ae412dc5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a92ff540c2377590d52352f8d8dbb0e4b0a0366d74749ec7491df1416c20b792c9d5e5227994e6b36082948dbefcc3e9e758eb1613b05ac6213b1d1cede0a219
|
7
|
+
data.tar.gz: 8a386f5a65e565fe03fd820445b27f50163ba7f01095aaeb6eba94fa68e2d24017a60674db41953919f51b4dfb369179f6cdd816e7d41c419db0b7af3ef39e15
|
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
|
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
|
data/core/target/ehu-ned-1.0.jar
CHANGED
Binary file
|
data/lib/opener/ned.rb
CHANGED
@@ -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
|
-
|
64
|
-
|
65
|
-
|
64
|
+
begin
|
65
|
+
if !input or input.strip.empty?
|
66
|
+
raise ArgumentError, 'No input specified'
|
67
|
+
end
|
66
68
|
|
67
|
-
|
69
|
+
language = language_from_kaf(input)
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
76
|
+
endpoint = @options.fetch(:endpoint, uri_for_language(language))
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
78
|
+
annotator.disambiguateNEsToKAF(
|
79
|
+
document,
|
80
|
+
endpoint.to_s
|
81
|
+
)
|
80
82
|
|
81
|
-
|
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
|
data/lib/opener/ned/version.rb
CHANGED
data/opener-ned.gemspec
CHANGED
@@ -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.
|
4
|
+
version: 2.3.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-
|
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:
|
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:
|
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
|