uwn-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +21 -0
- data/COPYING +674 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +14 -0
- data/README.md +146 -0
- data/Rakefile +1 -0
- data/lib/uwn/api.rb +13 -0
- data/lib/uwn/api/connect.rb +61 -0
- data/lib/uwn/api/meaning.rb +58 -0
- data/lib/uwn/api/statement.rb +136 -0
- data/lib/uwn/api/util.rb +22 -0
- data/lib/uwn/api/version.rb +5 -0
- data/lib/uwn/deps/lgpl-3.0.txt +165 -0
- data/lib/uwn/deps/plugins.txt +11 -0
- data/lib/uwn/deps/plugins/readme.txt +30 -0
- data/lib/uwn/deps/plugins/uwn.plg +1 -0
- data/lib/uwn/deps/plugins/wordnet.plg +1 -0
- data/lib/uwn/deps/readme.txt +21 -0
- data/lib/uwn/deps/uwnapi.jar +0 -0
- data/test/unit/uwn_connect.rb +56 -0
- data/test/unit/uwn_verify_statement.rb +45 -0
- data/test/unit/uwn_verify_tree.rb +127 -0
- data/uwn-api.gemspec +30 -0
- metadata +143 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
module Uwn
|
2
|
+
module Api
|
3
|
+
|
4
|
+
# Wrapper class for UWN Statement equivalent (with some abstracter function)
|
5
|
+
class Statement
|
6
|
+
|
7
|
+
attr_accessor :parent, :statements
|
8
|
+
|
9
|
+
# Statement constructor
|
10
|
+
def initialize options={}
|
11
|
+
self.parent = options[:parent] if options.include? :parent
|
12
|
+
@object = options[:object] if options.include? :object
|
13
|
+
self.statements = []
|
14
|
+
@parent_language = Util.parent_root(self).language
|
15
|
+
end
|
16
|
+
|
17
|
+
# term name as a string
|
18
|
+
def term_str
|
19
|
+
@object.get_object.get_term_str
|
20
|
+
end
|
21
|
+
|
22
|
+
# language of object
|
23
|
+
def language
|
24
|
+
@object.get_object.get_term_language
|
25
|
+
end
|
26
|
+
|
27
|
+
# word lexcat (noun, verb, adj etc.)
|
28
|
+
def lexcat
|
29
|
+
match = @object.get_object.to_s.match(/lexcat:([a-z]+)/)
|
30
|
+
return match[1] unless match.nil?
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
# match current to the Meaning (root object) language
|
35
|
+
def is_synonym?
|
36
|
+
@object.get_object.get_term_language == @parent_language
|
37
|
+
end
|
38
|
+
|
39
|
+
# is the current object referenced to a synset?
|
40
|
+
def has_synset?
|
41
|
+
self.synset.is_a? String
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_lexical_category?
|
45
|
+
@object.get_predicate.to_s == "rel:lexical_category"
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_subclass?
|
49
|
+
@object.get_predicate.to_s == "rel:subclass"
|
50
|
+
end
|
51
|
+
|
52
|
+
# subject object
|
53
|
+
def subject
|
54
|
+
@object.get_subject
|
55
|
+
end
|
56
|
+
|
57
|
+
# object of object (raw object)
|
58
|
+
def object
|
59
|
+
@object.get_object
|
60
|
+
end
|
61
|
+
|
62
|
+
# predicate object (tells something about the object)
|
63
|
+
def predicate
|
64
|
+
@object.get_predicate
|
65
|
+
end
|
66
|
+
|
67
|
+
# weight of the link
|
68
|
+
def weight
|
69
|
+
@object.get_weight
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s
|
73
|
+
@object.get_subject.to_s
|
74
|
+
end
|
75
|
+
|
76
|
+
# synset for current statement (not tested, depends on predicate!)
|
77
|
+
def synset
|
78
|
+
unless @object.nil?
|
79
|
+
os = @object.get_object.to_s
|
80
|
+
return os unless os.match(/([s][\/][n]){1}[0-9]+/).nil?
|
81
|
+
su = @object.get_subject.to_s
|
82
|
+
return su unless su.match(/([s][\/][n]){1}[0-9]+/).nil?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# get filtered categories (word types ex. verb, noun) from synset
|
87
|
+
def lexical_categories
|
88
|
+
self.predicate_match "rel:lexical_category"
|
89
|
+
end
|
90
|
+
|
91
|
+
# get filtered lexicalizations (translations) from synset
|
92
|
+
def lexicalizations
|
93
|
+
self.predicate_match "rel:lexicalization"
|
94
|
+
end
|
95
|
+
|
96
|
+
# get filtered synonyms from synset
|
97
|
+
def synonyms
|
98
|
+
sts = self.predicate_match "rel:lexicalization"
|
99
|
+
sts.reject{|t| !t.is_synonym? }
|
100
|
+
end
|
101
|
+
|
102
|
+
# get filtered subclasses from synset
|
103
|
+
def subclasses
|
104
|
+
self.predicate_match "rel:subclass"
|
105
|
+
end
|
106
|
+
|
107
|
+
# get filtered glosses from synset
|
108
|
+
def glosses
|
109
|
+
self.predicate_match "rel:has_gloss"
|
110
|
+
end
|
111
|
+
|
112
|
+
# get raw synsets
|
113
|
+
def synsets
|
114
|
+
self.predicate_match
|
115
|
+
end
|
116
|
+
|
117
|
+
protected
|
118
|
+
|
119
|
+
# get predicates (with or without name filter)
|
120
|
+
def predicate_match predicate_name = nil
|
121
|
+
sts = self.lookup_synset self.synset
|
122
|
+
sts.map!{|s| Statement.new(parent: self, object: s) }
|
123
|
+
return sts.reject{|t| t.predicate.to_s != predicate_name} unless predicate_name.nil?
|
124
|
+
sts
|
125
|
+
end
|
126
|
+
|
127
|
+
# get unique synsets from uwn
|
128
|
+
def lookup_synset synset
|
129
|
+
root = Util.parent_root self
|
130
|
+
root.connect.statements(synset)
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
data/lib/uwn/api/util.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Uwn
|
2
|
+
module Api
|
3
|
+
|
4
|
+
class Util
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def parent_root current_object
|
9
|
+
current = current_object
|
10
|
+
while true do
|
11
|
+
break if current.parent.nil?
|
12
|
+
current = current.parent
|
13
|
+
end
|
14
|
+
current
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
UWN plugin data missing!!!!!
|
2
|
+
|
3
|
+
It's too large for the repository, download it instead from the source below:
|
4
|
+
|
5
|
+
http://www.mpi-inf.mpg.de/yago-naga/uwn/downloads.html
|
6
|
+
http://www.mpi-inf.mpg.de/yago-naga/uwn/uwn.zip
|
7
|
+
|
8
|
+
Else, use it's online equivalent:
|
9
|
+
|
10
|
+
http://www.mpi-inf.mpg.de/yago-naga/uwn/downloads.html
|
11
|
+
http://www.mpi-inf.mpg.de/yago-naga/uwn/uwnapi.zip
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Princeton WordNet Plugin for UWN API
|
2
|
+
http://www.lexvo.org/uwn/api/
|
3
|
+
|
4
|
+
|
5
|
+
== DESCRIPTION ==
|
6
|
+
|
7
|
+
This plugin provides access to the Princeton WordNet 3.0 data
|
8
|
+
using the UWN API. It can be used in conjunction with other
|
9
|
+
multilingual plugins provided on the UWN API website.
|
10
|
+
|
11
|
+
|
12
|
+
== CREDITS AND LICENSE ==
|
13
|
+
|
14
|
+
WordNet 3.0: Copyright 2006 by Princeton University.
|
15
|
+
See LICENSE for more details.
|
16
|
+
|
17
|
+
For more information about WordNet and to download WordNet 3.0
|
18
|
+
in its original form, please visit:
|
19
|
+
http://wordnet.princeton.edu/
|
20
|
+
|
21
|
+
For academic research, consider consulting and citing the WordNet book:
|
22
|
+
Christiane Fellbaum (1998, ed.). WordNet: An Electronic Lexical Database.
|
23
|
+
Cambridge, MA: MIT Press.
|
24
|
+
|
25
|
+
For additionally citing this plugin more specifically, the following
|
26
|
+
reference can be used:
|
27
|
+
Gerard de Melo and Gerhard Weikum (2012).
|
28
|
+
UWN: A Large Multilingual Lexical Knowledge Base
|
29
|
+
In: Proceedings of ACL 2012 (Demonstration Session).
|
30
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
org.lexvo.uwn.internal.PluginStd uwn.dat
|
@@ -0,0 +1 @@
|
|
1
|
+
org.lexvo.uwn.internal.PluginStd wordnet.dat
|
@@ -0,0 +1,21 @@
|
|
1
|
+
UWN API Version 1.0
|
2
|
+
2012-07-02
|
3
|
+
|
4
|
+
This API provides access to semantic knowledge provided by different types
|
5
|
+
of plug-ins. Please refer to
|
6
|
+
http://www.lexvo.org/uwn/api/
|
7
|
+
for more information about the API and a list of plugins that can be used
|
8
|
+
with this API. Plugins should be placed in the plugins/ subdirectory in
|
9
|
+
unzipped form.
|
10
|
+
|
11
|
+
License: LGPL 3.0
|
12
|
+
The LGPL license allows for non-commercial as well as commercial use.
|
13
|
+
Note however that individual plugins may be subject to different licenses.
|
14
|
+
|
15
|
+
For academic use, please cite:
|
16
|
+
Gerard de Melo and Gerhard Weikum (2009). Towards a Universal Wordnet by Learning from Combined Evidence.
|
17
|
+
In: Proc. 18th ACM Conference on Information and Knowledge Management (CIKM 2009),
|
18
|
+
Hong Kong, China. ACM, New York, USA.
|
19
|
+
|
20
|
+
Copyright (c) 2012 Gerard de Melo
|
21
|
+
http://www.lexvo.org/gdm/
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../lib/uwn/api")
|
4
|
+
|
5
|
+
|
6
|
+
#
|
7
|
+
# Test the error handling from uwn
|
8
|
+
#
|
9
|
+
|
10
|
+
class UwnConnect < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_default_options
|
19
|
+
begin
|
20
|
+
uwn = Uwn::Api::Connect.new
|
21
|
+
assert true
|
22
|
+
rescue Exception => e
|
23
|
+
assert false, "should not get an exception"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_correct_path_option
|
28
|
+
begin
|
29
|
+
uwn = Uwn::Api::Connect.new plugins_path: Uwn::Api::Connect::DEFAULT_PATH
|
30
|
+
assert true
|
31
|
+
rescue Exception => e
|
32
|
+
assert false, "should not get an exception"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_incorrect_path_option
|
37
|
+
begin
|
38
|
+
uwn = Uwn::Api::Connect.new plugins_path: "/non/existing/path/to/plugins"
|
39
|
+
rescue Exception => e
|
40
|
+
assert e.message == "The plug-in directory '/non/existing/path/to/plugins' does not exist!"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_word_present
|
45
|
+
uwn = Uwn::Api::Connect.new
|
46
|
+
assert uwn.is_a?(Uwn::Api::Connect), "expected Connect object"
|
47
|
+
begin
|
48
|
+
meaning = uwn.meaning("gem", "eng")
|
49
|
+
assert true
|
50
|
+
rescue Exception => e
|
51
|
+
assert false, "word should be found"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|