opener-ned 2.4.0 → 2.4.1
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 +4 -4
- data/core/target/ehu-ned-1.0.jar +0 -0
- data/lib/opener/ned/cli.rb +6 -0
- data/lib/opener/ned/version.rb +1 -1
- data/lib/opener/ned.rb +78 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6c0f8c10e46991a6c5d92768a4336a7112fdb52
|
4
|
+
data.tar.gz: 75f1f11a4d2f4e31e1bc479cf0e1a5b35535126c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c1a3843a2b23bef511adc25d4eebd5ac2072d62678d9a4ce59e7297c791dad092cc31d630b35589059d5f88d4d3b050a217d9e8c92d4b0c4b9e60447f3becb2
|
7
|
+
data.tar.gz: ca9bad5047147879798d6b237007d97918dc82a62eb2d5e6a1958ed2a8bf1b114cbbcb02f84d7ce51ffc0dc661d71aae01895bf9960023912a38f8c35b365913
|
data/core/target/ehu-ned-1.0.jar
CHANGED
Binary file
|
data/lib/opener/ned/cli.rb
CHANGED
@@ -21,6 +21,8 @@ module Opener
|
|
21
21
|
opts.program_name = 'ned'
|
22
22
|
opts.summary_indent = ' '
|
23
23
|
|
24
|
+
opts.separator "\nOptions:\n\n"
|
25
|
+
|
24
26
|
opts.on('-h', '--help', 'Shows this help message') do
|
25
27
|
show_help
|
26
28
|
end
|
@@ -33,6 +35,10 @@ module Opener
|
|
33
35
|
@options[:logging] = true
|
34
36
|
end
|
35
37
|
|
38
|
+
opts.on('--no-time', 'Disables timestamps') do
|
39
|
+
@options[:enable_time] = false
|
40
|
+
end
|
41
|
+
|
36
42
|
opts.separator <<-EOF
|
37
43
|
|
38
44
|
Examples:
|
data/lib/opener/ned/version.rb
CHANGED
data/lib/opener/ned.rb
CHANGED
@@ -2,6 +2,7 @@ require 'optparse'
|
|
2
2
|
require 'java'
|
3
3
|
require 'stringio'
|
4
4
|
require 'nokogiri'
|
5
|
+
require 'opener/core'
|
5
6
|
|
6
7
|
require File.expand_path('../../../core/target/ehu-ned-1.0.jar', __FILE__)
|
7
8
|
|
@@ -9,12 +10,11 @@ require_relative 'ned/version'
|
|
9
10
|
require_relative 'ned/cli'
|
10
11
|
|
11
12
|
import 'java.io.InputStreamReader'
|
12
|
-
|
13
13
|
import 'ixa.kaflib.KAFDocument'
|
14
14
|
|
15
15
|
module Opener
|
16
16
|
##
|
17
|
-
# Ruby wrapper around the Java based
|
17
|
+
# Ruby wrapper around the Java based NED tool that's powered by DBpedia.
|
18
18
|
#
|
19
19
|
# @!attribute [r] options
|
20
20
|
# @return [Hash]
|
@@ -22,17 +22,22 @@ module Opener
|
|
22
22
|
class Ned
|
23
23
|
attr_reader :options
|
24
24
|
|
25
|
+
##
|
26
|
+
# The DBpedia endpoints for every language code.
|
27
|
+
#
|
28
|
+
# @return [Hash]
|
29
|
+
#
|
25
30
|
LANGUAGE_ENDPOINTS = {
|
26
|
-
"en"=>"http://spotlight.sztaki.hu:2222",
|
27
|
-
"nl"=>"http://nl.dbpedia.org/spotlight",
|
28
|
-
"fr"=>"http://spotlight.sztaki.hu:2225",
|
29
|
-
"de"=>"http://de.dbpedia.org/spotlight",
|
30
|
-
"es"=>"http://spotlight.sztaki.hu:2231",
|
31
|
-
"it"=>"http://spotlight.sztaki.hu:2230",
|
32
|
-
"ru"=>"http://spotlight.sztaki.hu:2227",
|
33
|
-
"pt"=>"http://spotlight.sztaki.hu:2228",
|
34
|
-
"hu"=>"http://spotlight.sztaki.hu:2229",
|
35
|
-
"tr"=>"http://spotlight.sztaki.hu:2235"
|
31
|
+
"en" => "http://spotlight.sztaki.hu:2222",
|
32
|
+
"nl" => "http://nl.dbpedia.org/spotlight",
|
33
|
+
"fr" => "http://spotlight.sztaki.hu:2225",
|
34
|
+
"de" => "http://de.dbpedia.org/spotlight",
|
35
|
+
"es" => "http://spotlight.sztaki.hu:2231",
|
36
|
+
"it" => "http://spotlight.sztaki.hu:2230",
|
37
|
+
"ru" => "http://spotlight.sztaki.hu:2227",
|
38
|
+
"pt" => "http://spotlight.sztaki.hu:2228",
|
39
|
+
"hu" => "http://spotlight.sztaki.hu:2229",
|
40
|
+
"tr" => "http://spotlight.sztaki.hu:2235"
|
36
41
|
}
|
37
42
|
|
38
43
|
##
|
@@ -41,8 +46,9 @@ module Opener
|
|
41
46
|
# @return [Hash]
|
42
47
|
#
|
43
48
|
DEFAULT_OPTIONS = {
|
44
|
-
:args
|
45
|
-
:logging
|
49
|
+
:args => [],
|
50
|
+
:logging => false,
|
51
|
+
:enable_time => true
|
46
52
|
}.freeze
|
47
53
|
|
48
54
|
##
|
@@ -54,49 +60,84 @@ module Opener
|
|
54
60
|
# @option options [TrueClass|FalseClass] :logging When set to `true`
|
55
61
|
# logging is enabled. This is disabled by default.
|
56
62
|
#
|
63
|
+
# @option options [TrueClass|FalseClass] :enable_time When set to `true`
|
64
|
+
# the output will include timestamps.
|
65
|
+
#
|
57
66
|
def initialize(options = {})
|
58
67
|
@options = DEFAULT_OPTIONS.merge(options)
|
59
68
|
end
|
60
69
|
|
70
|
+
##
|
71
|
+
# Performs NED on the given input document. The return value is the
|
72
|
+
# resulting KAF document.
|
73
|
+
#
|
74
|
+
# @param [String] input The input KAF document.
|
75
|
+
# @return [String]
|
76
|
+
#
|
61
77
|
def run(input)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
78
|
+
if !input or input.strip.empty?
|
79
|
+
raise ArgumentError, 'No input specified'
|
80
|
+
end
|
66
81
|
|
67
|
-
|
82
|
+
language = language_from_kaf(input)
|
83
|
+
input_io = StringIO.new(input)
|
84
|
+
reader = InputStreamReader.new(input_io.to_inputstream)
|
85
|
+
document = KAFDocument.create_from_stream(reader)
|
86
|
+
annotator = new_annotator
|
87
|
+
endpoint = options.fetch(:endpoint, uri_for_language(language))
|
68
88
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
89
|
+
annotator.disambiguateNEsToKAF(
|
90
|
+
document,
|
91
|
+
endpoint.to_s
|
92
|
+
)
|
73
93
|
|
74
|
-
|
94
|
+
return document.to_string
|
75
95
|
|
76
|
-
|
96
|
+
rescue Exception => error
|
97
|
+
return Opener::Core::ErrorLayer.new(input, error.message, self.class).add
|
98
|
+
end
|
77
99
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
100
|
+
private
|
101
|
+
|
102
|
+
##
|
103
|
+
# Creates and configures a new Annotate class.
|
104
|
+
#
|
105
|
+
# @return [Java::ehu.ned.Annotate]
|
106
|
+
#
|
107
|
+
def new_annotator
|
108
|
+
annotator = Java::ehu.ned.Annotate.new
|
82
109
|
|
83
|
-
|
110
|
+
unless options[:logging]
|
111
|
+
annotator.disableLogging
|
112
|
+
end
|
84
113
|
|
85
|
-
|
86
|
-
|
114
|
+
unless options[:enable_time]
|
115
|
+
annotator.disableTimestamp
|
87
116
|
end
|
88
|
-
end
|
89
117
|
|
90
|
-
|
118
|
+
return annotator
|
119
|
+
end
|
91
120
|
|
121
|
+
##
|
122
|
+
# Returns the language from the KAF document.
|
123
|
+
#
|
124
|
+
# @param [String] input The input KAF document.
|
125
|
+
# @return [String]
|
126
|
+
#
|
92
127
|
def language_from_kaf(input)
|
93
128
|
document = Nokogiri::XML(input)
|
94
|
-
|
129
|
+
|
130
|
+
return document.at('KAF').attr('xml:lang')
|
95
131
|
end
|
96
132
|
|
133
|
+
##
|
134
|
+
# Returns the endpoint URL for the given language.
|
135
|
+
#
|
136
|
+
# @param [String] language
|
137
|
+
# @return [String]
|
138
|
+
#
|
97
139
|
def uri_for_language(language)
|
98
|
-
LANGUAGE_ENDPOINTS[language]+"/rest/disambiguate"
|
140
|
+
return LANGUAGE_ENDPOINTS[language] + "/rest/disambiguate"
|
99
141
|
end
|
100
|
-
|
101
142
|
end # Ned
|
102
143
|
end # Opener
|
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.
|
4
|
+
version: 2.4.1
|
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-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|