uwn-api 0.0.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 +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
data/COPYING.LESSER
ADDED
@@ -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.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2013 Dennis Blommesteijn
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
This code is free software: you can redistribute it and/or modify it under
|
5
|
+
the terms of the GNU Lesser General Public License version 3 only, as
|
6
|
+
published by the Free Software Foundation.
|
7
|
+
|
8
|
+
This code is distributed in the hope that it will be useful, but WITHOUT
|
9
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
10
|
+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
11
|
+
version 3 for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU Lesser General Public License
|
14
|
+
version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Uwn::Api
|
2
|
+
|
3
|
+
This project is a Ruby on Rails (gem) wrapper for the UWN database (build from Wordnet), using JRuby (Java) and uwnapi.jar (which are included). Ruby MRI users will NOT be successful using this gem!!
|
4
|
+
|
5
|
+
* UWN/MENTA: Towards a Universal Multilingual Wordnet API.
|
6
|
+
* http://www.mpi-inf.mpg.de/yago-naga/uwn/downloads.html
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile (bundler):
|
11
|
+
|
12
|
+
gem 'uwn-api', git: "git://github.com/dblommesteijn/uwn-api.git"
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as (RubyGems):
|
19
|
+
|
20
|
+
$ gem install uwn-api
|
21
|
+
|
22
|
+
|
23
|
+
## Roadmap
|
24
|
+
|
25
|
+
* Version (0.0.2)
|
26
|
+
|
27
|
+
Depth query on synset subclasses
|
28
|
+
|
29
|
+
Depth search over multiple nodes
|
30
|
+
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Download and install
|
35
|
+
|
36
|
+
Before using UWN you'll need to download Wordnet and UWN plugin libraries (http://www.mpi-inf.mpg.de/yago-naga/uwn/downloads.html) which are ~100Mb, and place it in the appropriate directory.
|
37
|
+
|
38
|
+
Place the uwn.dat/plg (and/or) wordnet.dat/plg into your plugins directory
|
39
|
+
|
40
|
+
~/yourgems/uwn-api/lib/uwn/api/deps/plugins (default directory)
|
41
|
+
|
42
|
+
OR Point Uwn::Api::Connect to the plugins path.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
uwn = Uwn::Api::Connect.new plugins_path: "/location/of/your/plugins"
|
46
|
+
```
|
47
|
+
|
48
|
+
### Connecting and word Query
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# connect to UWN and point the plugins dir
|
52
|
+
uwn = Uwn::Api::Connect.new plugins_path: "/location/of/your/plugins"
|
53
|
+
# perform query word gem in English
|
54
|
+
meaning = uwn.meaning "gem", "eng"
|
55
|
+
# iterate the found statements
|
56
|
+
meaning.statements.each do |statement|
|
57
|
+
# print statement
|
58
|
+
puts statement
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### More advanced lists
|
63
|
+
|
64
|
+
Uwn::Api::Meaning includes shorthand methods that invocate, and flatten nested statement lists. Therefor meaning_instance.synsets are equivalent to meaning_instance.statments.flat_map{|s| s.synsets}.
|
65
|
+
|
66
|
+
|
67
|
+
#### Basic iteration example
|
68
|
+
```ruby
|
69
|
+
# connect to UWN and point the plugins dir
|
70
|
+
uwn = Uwn::Api::Connect.new plugins_path: "/location/of/your/plugins"
|
71
|
+
# perform query word gem in English
|
72
|
+
meaning = uwn.meaning "gem", "eng"
|
73
|
+
|
74
|
+
# iterate synsets (part of speech) on all nested statements
|
75
|
+
meaning.synsets.each do |synset|
|
76
|
+
# print statement synset
|
77
|
+
puts synset
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
#### Lexical Categories (word type: verb, noun etc.)
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
# iterate lexical_categories (word type: verb, noun etc.)
|
85
|
+
meaning.lexical_categories.each do |lexical_category|
|
86
|
+
# print statement lexical_category
|
87
|
+
puts lexical_category
|
88
|
+
# you can verify lexical_categories using:
|
89
|
+
lexical_category.is_lexical_category?
|
90
|
+
# word types can be retreived using:
|
91
|
+
lexical_category.lexcat
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
#### Synonyms (based on synset word)
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
# iterate synonyms (word synonyms based on synset)
|
99
|
+
meaning.synonyms.each do |synonym|
|
100
|
+
# print statement synonym
|
101
|
+
puts synonym
|
102
|
+
# you can verify synonyms using:
|
103
|
+
synonym.is_synonym?
|
104
|
+
# word retreival can be done using:
|
105
|
+
synonym.term_str
|
106
|
+
end
|
107
|
+
```
|
108
|
+
|
109
|
+
#### Lexicalizations (translations)
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
# iterate lexicalizations (translations)
|
113
|
+
meaning.lexicalizations.each do |lexicalization|
|
114
|
+
# print statement lexicalization
|
115
|
+
puts lexicalization
|
116
|
+
# word language
|
117
|
+
lexicalization.language
|
118
|
+
# word itself
|
119
|
+
lexicalization.term_str
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
#### Subclasses (synset related classes)
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
# iterate related classes
|
127
|
+
meaning.subclasses.each do |subclass|
|
128
|
+
# the related subclass (synset id)
|
129
|
+
subclass.to_s
|
130
|
+
#TODO: do an in depth query on this synset is not yet supported!
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
#### Glossary (text explanation of word)
|
135
|
+
|
136
|
+
```ruby
|
137
|
+
meaning.glosses.each do |gloss|
|
138
|
+
# print statement glossary
|
139
|
+
puts gloss
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/uwn/api.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/api/version")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/api/connect")
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + "/api/statement")
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/api/meaning")
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + "/api/util")
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
module Uwn
|
10
|
+
module Api
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'java'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../deps/uwnapi.jar")
|
3
|
+
|
4
|
+
|
5
|
+
module Uwn
|
6
|
+
module Api
|
7
|
+
|
8
|
+
class Connect
|
9
|
+
|
10
|
+
DEFAULT_PATH = File.dirname(__FILE__) + "/../deps/plugins"
|
11
|
+
|
12
|
+
import 'org.lexvo.uwn.UWN'
|
13
|
+
import 'org.lexvo.uwn.Entity'
|
14
|
+
import 'org.lexvo.uwn.Statement'
|
15
|
+
|
16
|
+
|
17
|
+
def initialize options={}
|
18
|
+
begin
|
19
|
+
# setup plugin directory
|
20
|
+
unless options.include? :plugins_path
|
21
|
+
plugins_path = DEFAULT_PATH
|
22
|
+
else
|
23
|
+
plugins_path = options[:plugins_path]
|
24
|
+
end
|
25
|
+
f = java.io.File.new(plugins_path.to_s)
|
26
|
+
# load uwn
|
27
|
+
@uwn = UWN.new(f)
|
28
|
+
rescue Exception => e
|
29
|
+
# hide java verbose output
|
30
|
+
raise e.message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# lookup meaning of term by name and language
|
35
|
+
def meaning term, language
|
36
|
+
meaning = Meaning.new connect: self, term: term, language: language
|
37
|
+
# get meaning entities
|
38
|
+
mes = @uwn.get_meaning_entities term, language
|
39
|
+
# iterate entities
|
40
|
+
while mes.has_next do
|
41
|
+
# append statment to meaning object
|
42
|
+
meaning.append_statement mes.next
|
43
|
+
end
|
44
|
+
meaning
|
45
|
+
end
|
46
|
+
|
47
|
+
# get statements by direct uwn query
|
48
|
+
def statements object_string
|
49
|
+
ret = []
|
50
|
+
mes = @uwn.get(Entity.new(object_string))
|
51
|
+
while mes.has_next do
|
52
|
+
ret << mes.next
|
53
|
+
end
|
54
|
+
ret
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
module Uwn
|
3
|
+
module Api
|
4
|
+
|
5
|
+
# Class for Abstract UWN Statement wrapper (with some high level functions)
|
6
|
+
class Meaning
|
7
|
+
|
8
|
+
attr_accessor :connect, :parent, :term, :language, :statements
|
9
|
+
|
10
|
+
def initialize options={}
|
11
|
+
self.connect = options[:connect] if options.include? :connect
|
12
|
+
self.term = options[:term] if options.include? :term
|
13
|
+
self.language = options[:language] if options.include? :language
|
14
|
+
self.statements = []
|
15
|
+
end
|
16
|
+
|
17
|
+
# contains a statement set?
|
18
|
+
def has_meaning?
|
19
|
+
!self.statements.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
# append a statement, and wrap with a Statement object
|
23
|
+
def append_statement statement
|
24
|
+
self.statements << Statement.new(parent: self, object: statement)
|
25
|
+
end
|
26
|
+
|
27
|
+
# short handeded (high level) methods
|
28
|
+
|
29
|
+
def synsets
|
30
|
+
self.statements.flat_map{ |s| s.synsets }
|
31
|
+
end
|
32
|
+
|
33
|
+
def synonyms
|
34
|
+
self.statements.flat_map{ |s| s.synonyms }
|
35
|
+
end
|
36
|
+
|
37
|
+
def lexicalizations
|
38
|
+
self.statements.flat_map{ |s| s.lexicalizations }
|
39
|
+
end
|
40
|
+
|
41
|
+
def glosses
|
42
|
+
self.statements.flat_map{ |s| s.glosses }
|
43
|
+
end
|
44
|
+
|
45
|
+
def subclasses
|
46
|
+
self.statements.flat_map{ |s| s.subclasses }
|
47
|
+
end
|
48
|
+
|
49
|
+
def lexical_categories
|
50
|
+
self.statements.flat_map{ |s| s.lexical_categories }
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|