rwordnet 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +7 -3
- data/examples/benchmark.rb +1 -1
- data/examples/dictionary.rb +1 -1
- data/examples/full_hypernym.rb +1 -1
- data/examples/morphy.rb +1 -1
- data/examples/synset_find.rb +1 -1
- data/lib/rwordnet.rb +5 -0
- data/lib/{wordnet → rwordnet}/db.rb +0 -3
- data/lib/{wordnet → rwordnet}/lemma.rb +7 -1
- data/lib/{wordnet → rwordnet}/pointer.rb +0 -0
- data/lib/{wordnet → rwordnet}/pointers.rb +0 -0
- data/lib/{wordnet → rwordnet}/synset.rb +13 -12
- data/lib/rwordnet/version.rb +3 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/synset_test.rb +7 -0
- metadata +10 -10
- data/lib/wordnet.rb +0 -5
- data/lib/wordnet/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9518288f71b4a82f57e48e62f1adb0842c799857
|
4
|
+
data.tar.gz: f56b54be645baaaff6b855745cbc122ef8e4a035
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6c0e42b463a29d85a1ece1a3eb68d1c9924dd011e1bc1c9f4058478d1e330fc78219bc5ed76ea68313a1b4944862905aa6809dace2d77b843c6295056e5e69b
|
7
|
+
data.tar.gz: c04cbcc3ead95d96d4c98c4427e3b7bdfaaa2c8f1c799877475009977bd8ebb5f54e2104f1642d9144b369476b48276d7abb20c7e8d14c9457b58a2e5036acd4
|
data/README.markdown
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# A pure Ruby interface to WordNet #
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rwordnet.svg)](http://badge.fury.io/rb/rwordnet)
|
3
4
|
[![Build Status](https://travis-ci.org/doches/rwordnet.png)](https://travis-ci.org/doches/rwordnet)
|
4
5
|
[![Documentation Status](https://inch-ci.org/github/doches/rwordnet.svg?branch=master)](https://inch-ci.org/github/doches/rwordnet)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/doches/rwordnet/badges/gpa.svg)](https://codeclimate.com/github/doches/rwordnet)
|
@@ -26,6 +27,10 @@ since it converts the WordNet database into a BerkelyDB file for quicker access.
|
|
26
27
|
writing rwordnet, I've focused more on usability and ease of installation ( *gem install
|
27
28
|
rwordnet* ) at the expense of some performance. Use at your own risk, etc.
|
28
29
|
|
30
|
+
| Note |
|
31
|
+
| --- |
|
32
|
+
| `2.0.0` changed how you require rwordnet from `require 'wordnet'` to `require 'rwordnet'` (note the extra `r`!). |
|
33
|
+
|
29
34
|
## Installation ##
|
30
35
|
|
31
36
|
One of the chief benefits of rwordnet over Ruby-WordNet is how easy it is to install:
|
@@ -45,7 +50,7 @@ use.
|
|
45
50
|
As an example, consider finding all of the noun glosses for a given word:
|
46
51
|
|
47
52
|
```Ruby
|
48
|
-
require '
|
53
|
+
require 'rwordnet'
|
49
54
|
|
50
55
|
lemma = WordNet::Lemma.find("fruit", :noun)
|
51
56
|
lemma.synsets.each { |synset| puts synset.gloss }
|
@@ -64,9 +69,8 @@ Have your own WordNet database that you've marked up with extra attributes and w
|
|
64
69
|
No problem:
|
65
70
|
|
66
71
|
```Ruby
|
67
|
-
require '
|
72
|
+
require 'rwordnet'
|
68
73
|
|
69
74
|
WordNet::DB.path = "/path/to/WordNet-3.0"
|
70
75
|
lemmas = WordNet::Lemma.find_all("fruit")
|
71
|
-
...
|
72
76
|
```
|
data/examples/benchmark.rb
CHANGED
data/examples/dictionary.rb
CHANGED
data/examples/full_hypernym.rb
CHANGED
data/examples/morphy.rb
CHANGED
data/examples/synset_find.rb
CHANGED
data/lib/rwordnet.rb
ADDED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
|
3
1
|
module WordNet
|
4
2
|
# Represents the WordNet database, and provides some basic interaction.
|
5
3
|
class DB
|
@@ -9,7 +7,6 @@ module WordNet
|
|
9
7
|
class << self; attr_accessor :cached end
|
10
8
|
@raw_wordnet = {}
|
11
9
|
|
12
|
-
|
13
10
|
class << self
|
14
11
|
# To use your own WordNet installation (rather than the one bundled with rwordnet:
|
15
12
|
# Returns the path to the WordNet installation currently in use. Defaults to the bundled version of WordNet.
|
@@ -2,6 +2,7 @@ module WordNet
|
|
2
2
|
# Represents a single word in the WordNet lexicon, which can be used to look up a set of synsets.
|
3
3
|
class Lemma
|
4
4
|
SPACE = ' '
|
5
|
+
POS_SHORTHAND = {:v => :verb, :n => :noun, :a => :adj, :r => :adv}
|
5
6
|
|
6
7
|
# The word this lemma represents
|
7
8
|
attr_accessor :word
|
@@ -58,8 +59,13 @@ module WordNet
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
# Find a lemma for a given word and pos
|
62
|
+
# Find a lemma for a given word and pos. Valid parts of speech are:
|
63
|
+
# 'adj', 'adv', 'noun', 'verb'. Additionally, you can use the shorthand
|
64
|
+
# forms of each of these ('a', 'r', 'n', 'v')/
|
62
65
|
def find(word, pos)
|
66
|
+
# Map shorthand POS to full forms
|
67
|
+
pos = POS_SHORTHAND[pos] || pos
|
68
|
+
|
63
69
|
cache = @@cache[pos] ||= build_cache(pos)
|
64
70
|
if found = cache[word]
|
65
71
|
Lemma.new(*found)
|
File without changes
|
File without changes
|
@@ -1,19 +1,19 @@
|
|
1
1
|
module WordNet
|
2
2
|
SYNSET_TYPES = {"n" => "noun", "v" => "verb", "a" => "adj", "r" => "adv"}
|
3
|
+
MORPHOLOGICAL_SUBSTITUTIONS = {
|
4
|
+
'noun' => [['s', ''], ['ses', 's'], ['ves', 'f'], ['xes', 'x'],
|
5
|
+
['zes', 'z'], ['ches', 'ch'], ['shes', 'sh'],
|
6
|
+
['men', 'man'], ['ies', 'y']],
|
7
|
+
'verb' => [['s', ''], ['ies', 'y'], ['es', 'e'], ['es', ''],
|
8
|
+
['ed', 'e'], ['ed', ''], ['ing', 'e'], ['ing', '']],
|
9
|
+
'adj' => [['er', ''], ['est', ''], ['er', 'e'], ['est', 'e']],
|
10
|
+
'adv' => []}
|
3
11
|
|
4
12
|
# Represents a synset (or group of synonymous words) in WordNet. Synsets are related to each other by various (and numerous!)
|
5
13
|
# relationships, including Hypernym (x is a hypernym of y <=> x is a parent of y) and Hyponym (x is a child of y)
|
6
14
|
class Synset
|
7
15
|
@morphy_path = File.expand_path("../../../morphy/", __FILE__)
|
8
16
|
@exception_map = {}
|
9
|
-
@morphological_substitutions = {
|
10
|
-
'noun' => [['s', ''], ['ses', 's'], ['ves', 'f'], ['xes', 'x'],
|
11
|
-
['zes', 'z'], ['ches', 'ch'], ['shes', 'sh'],
|
12
|
-
['men', 'man'], ['ies', 'y']],
|
13
|
-
'verb' => [['s', ''], ['ies', 'y'], ['es', 'e'], ['es', ''],
|
14
|
-
['ed', 'e'], ['ed', ''], ['ing', 'e'], ['ing', '']],
|
15
|
-
'adj' => [['er', ''], ['est', ''], ['er', 'e'], ['est', 'e']],
|
16
|
-
'adv' => []}
|
17
17
|
|
18
18
|
# Get the offset, in bytes, at which this synset's information is stored in WordNet's internal DB.
|
19
19
|
# You almost certainly don't care about this.
|
@@ -83,7 +83,7 @@ module WordNet
|
|
83
83
|
# Ported from python NLTK
|
84
84
|
# Load all synsets with a given lemma and part of speech tag.
|
85
85
|
# If no pos is specified, all synsets for all parts of speech
|
86
|
-
# will be loaded.
|
86
|
+
# will be loaded.
|
87
87
|
# If lang is specified, all the synsets associated with the lemma name
|
88
88
|
# of that language will be returned.
|
89
89
|
def self.find(word, pos)
|
@@ -107,7 +107,7 @@ module WordNet
|
|
107
107
|
end
|
108
108
|
|
109
109
|
def self._apply_rules(forms, pos)
|
110
|
-
substitutions =
|
110
|
+
substitutions = MORPHOLOGICAL_SUBSTITUTIONS[pos]
|
111
111
|
out = []
|
112
112
|
forms.each do |form|
|
113
113
|
substitutions.each do |old, new|
|
@@ -188,7 +188,7 @@ module WordNet
|
|
188
188
|
map! { |pointer| Synset.new(@synset_type, pointer.offset) }
|
189
189
|
end
|
190
190
|
|
191
|
-
# Get the
|
191
|
+
# Get the Synsets of this sense's antonym
|
192
192
|
def antonyms
|
193
193
|
relation(ANTONYM)
|
194
194
|
end
|
@@ -198,7 +198,8 @@ module WordNet
|
|
198
198
|
relation(HYPERNYM)[0]
|
199
199
|
end
|
200
200
|
|
201
|
-
# Get the parent synset (higher-level category, i.e. fruit -> reproductive_structure)
|
201
|
+
# Get the parent synset (higher-level category, i.e. fruit -> reproductive_structure)
|
202
|
+
# as an array.
|
202
203
|
def hypernyms
|
203
204
|
relation(HYPERNYM)
|
204
205
|
end
|
data/test/test_helper.rb
CHANGED
data/test/unit/synset_test.rb
CHANGED
@@ -73,4 +73,11 @@ describe WordNet::Synset do
|
|
73
73
|
animal = WordNet::Lemma.find("animal", :noun).synsets[0]
|
74
74
|
assert_equal animal.expanded_hypernyms_depth[1], 6
|
75
75
|
end
|
76
|
+
|
77
|
+
it 'understands short forms in lemma lookups' do
|
78
|
+
animal = WordNet::Lemma.find("animal", :noun).synsets[0]
|
79
|
+
shortform = WordNet::Lemma.find("animal", :n).synsets[0]
|
80
|
+
|
81
|
+
assert_equal animal.to_s, shortform.to_s
|
82
|
+
end
|
76
83
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rwordnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Fountain
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2016-12-20 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description:
|
16
16
|
email: trevor@texasexpat.net
|
@@ -37,13 +37,13 @@ files:
|
|
37
37
|
- examples/full_hypernym.rb
|
38
38
|
- examples/morphy.rb
|
39
39
|
- examples/synset_find.rb
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
40
|
+
- lib/rwordnet.rb
|
41
|
+
- lib/rwordnet/db.rb
|
42
|
+
- lib/rwordnet/lemma.rb
|
43
|
+
- lib/rwordnet/pointer.rb
|
44
|
+
- lib/rwordnet/pointers.rb
|
45
|
+
- lib/rwordnet/synset.rb
|
46
|
+
- lib/rwordnet/version.rb
|
47
47
|
- morphy/exceptions/adj.exc
|
48
48
|
- morphy/exceptions/adv.exc
|
49
49
|
- morphy/exceptions/noun.exc
|
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
75
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
76
|
+
rubygems_version: 2.6.8
|
77
77
|
signing_key:
|
78
78
|
specification_version: 4
|
79
79
|
summary: A pure Ruby interface to the WordNet database
|
data/lib/wordnet.rb
DELETED
data/lib/wordnet/version.rb
DELETED