rwordnet 0.1.0 → 0.1.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.
- data/README.markdown +15 -7
- data/lib/wordnet/index.rb +16 -7
- data/lib/wordnet/wordnetdb.rb +1 -1
- data/test/unit/index_test.rb +1 -1
- data/test/unit/synset_test.rb +1 -1
- data/test/unit/wordnetdb_test.rb +2 -3
- metadata +17 -5
data/README.markdown
CHANGED
@@ -15,10 +15,11 @@ rwordnet* ) at the expense of some performance. Use at your own risk, etc.
|
|
15
15
|
|
16
16
|
## Installation ##
|
17
17
|
|
18
|
-
One of the chief benefits of rwordnet over Ruby-WordNet is how easy it is to install
|
18
|
+
One of the chief benefits of rwordnet over Ruby-WordNet is how easy it is to install:
|
19
19
|
|
20
|
-
gem
|
21
|
-
|
20
|
+
gem install gemcutter # These two steps are only necessary if you haven't
|
21
|
+
gem tumble # yet installed the gemcutter tools
|
22
|
+
gem install rwordnet
|
22
23
|
|
23
24
|
That's it! rwordnet comes bundled with the WordNet database which it uses by default,
|
24
25
|
so there's absolutely nothing else to download, install, or configure.
|
@@ -30,15 +31,22 @@ set the path to WordNet's database files before using the library (see examples
|
|
30
31
|
The other benefit of rwordnet over Ruby-WordNet is that it's so much easier (IMHO) to
|
31
32
|
use.
|
32
33
|
|
33
|
-
As a quick example, consider finding all of the glosses for a given word:
|
34
|
+
As a quick example, consider finding all of the noun glosses for a given word:
|
34
35
|
|
35
36
|
require 'rubygems'
|
36
37
|
require 'wordnet'
|
37
38
|
|
38
|
-
index = WordNet::NounIndex.
|
39
|
+
index = WordNet::NounIndex.instance
|
39
40
|
lemma = index.find("fruit")
|
40
41
|
lemma.synsets.each { |synset| puts synset.gloss }
|
41
42
|
|
43
|
+
...or all of the glosses, period:
|
44
|
+
|
45
|
+
lemmas = WordNet::WordNetDB.find("fruit")
|
46
|
+
synsets = lemmas.map { |lemma| lemma.synsets }
|
47
|
+
words = synsets.flatten
|
48
|
+
words.each { |word| puts word.gloss }
|
49
|
+
|
42
50
|
Have your own WordNet database that you've marked up with extra attributes and whatnot?
|
43
51
|
No problem:
|
44
52
|
|
@@ -47,5 +55,5 @@ No problem:
|
|
47
55
|
|
48
56
|
include WordNet
|
49
57
|
WordNetDB.path = "/path/to/WordNet-3.0"
|
50
|
-
|
51
|
-
...
|
58
|
+
lemmas = WordNetDB.find("fruit")
|
59
|
+
...
|
data/lib/wordnet/index.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require 'singleton'
|
1
2
|
module WordNet
|
2
3
|
|
3
4
|
# Index is a WordNet lexicon. Note that Index is the base class; you probably want to be using the NounIndex, VerbIndex, etc. classes instead.
|
5
|
+
# Note that Indices are Singletons -- get an Index object by calling <POS>Index.instance, not <POS>Index.new.
|
4
6
|
class Index
|
5
7
|
# Create a new index for the given part of speech. +pos+ can be one of +noun+, +verb+, +adj+, or +adv+.
|
6
8
|
def initialize(pos)
|
@@ -11,9 +13,7 @@ class Index
|
|
11
13
|
# Find a lemma for a given word. Returns a Lemma which can then be used to access the synsets for the word.
|
12
14
|
def find(lemma_str)
|
13
15
|
# Look for the lemma in the part of the DB already read...
|
14
|
-
@db
|
15
|
-
return @db[word] if word == lemma_str
|
16
|
-
end
|
16
|
+
return @db[lemma_str] if @db.include?(lemma_str)
|
17
17
|
|
18
18
|
# If we didn't find it, read in some more from the DB. Some optimisation is possible here. TODO.
|
19
19
|
index = WordNetDB.open(File.join(WordNetDB.path,"dict","index.#{@pos}"))
|
@@ -30,33 +30,42 @@ class Index
|
|
30
30
|
index.close
|
31
31
|
end
|
32
32
|
|
33
|
+
# If we *still* didn't find it, return nil. It must not be in the database...
|
33
34
|
return nil
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
# An Index of nouns.
|
38
|
+
# An Index of nouns. Create a NounIndex by calling `NounIndex.instance`
|
38
39
|
class NounIndex < Index
|
40
|
+
include Singleton
|
41
|
+
|
39
42
|
def initialize
|
40
43
|
super("noun")
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
44
|
-
# An Index of verbs.
|
47
|
+
# An Index of verbs. Create a VerbIndex by calling `VerbIndex.instance`
|
45
48
|
class VerbIndex < Index
|
49
|
+
include Singleton
|
50
|
+
|
46
51
|
def initialize
|
47
52
|
super("verb")
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
# An Index of adjectives.
|
56
|
+
# An Index of adjectives. Create an AdjectiveIndex by `AdjectiveIndex.instance`
|
52
57
|
class AdjectiveIndex < Index
|
58
|
+
include Singleton
|
59
|
+
|
53
60
|
def initialize
|
54
61
|
super("adj")
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
58
|
-
# An Index of adverbs.
|
65
|
+
# An Index of adverbs. Create an AdverbIndex by `AdverbIndex.instance`
|
59
66
|
class AdverbIndex < Index
|
67
|
+
include Singleton
|
68
|
+
|
60
69
|
def initialize
|
61
70
|
super("adv")
|
62
71
|
end
|
data/lib/wordnet/wordnetdb.rb
CHANGED
@@ -20,7 +20,7 @@ class WordNetDB
|
|
20
20
|
def WordNetDB.find(word)
|
21
21
|
lemmas = []
|
22
22
|
[NounIndex, VerbIndex, AdjectiveIndex, AdverbIndex].each do |index|
|
23
|
-
lemmas.push index.
|
23
|
+
lemmas.push index.instance.find(word)
|
24
24
|
end
|
25
25
|
return lemmas.flatten.reject { |x| x.nil? }
|
26
26
|
end
|
data/test/unit/index_test.rb
CHANGED
data/test/unit/synset_test.rb
CHANGED
data/test/unit/wordnetdb_test.rb
CHANGED
@@ -4,12 +4,11 @@ class TestWordNetDB < Test::Unit::TestCase
|
|
4
4
|
include WordNet
|
5
5
|
|
6
6
|
test 'set and read path' do
|
7
|
-
WordNetDB.path = WordNetPath
|
8
|
-
assert_equal WordNetPath,WordNetDB.path
|
7
|
+
WordNetDB.path = "WordNetPath"
|
8
|
+
assert_equal "WordNetPath",WordNetDB.path
|
9
9
|
end
|
10
10
|
|
11
11
|
test 'find a word' do
|
12
|
-
WordNetDB.path = WordNetPath
|
13
12
|
lemmas = WordNetDB.find("fruit")
|
14
13
|
assert_equal 2,lemmas.size
|
15
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rwordnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Trevor Fountain
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-09-03 00:00:00 +01:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -60,21 +66,27 @@ rdoc_options:
|
|
60
66
|
require_paths:
|
61
67
|
- lib
|
62
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
63
70
|
requirements:
|
64
71
|
- - ">="
|
65
72
|
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
66
76
|
version: "0"
|
67
|
-
version:
|
68
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
69
79
|
requirements:
|
70
80
|
- - ">="
|
71
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
72
85
|
version: "0"
|
73
|
-
version:
|
74
86
|
requirements: []
|
75
87
|
|
76
88
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.3.
|
89
|
+
rubygems_version: 1.3.7
|
78
90
|
signing_key:
|
79
91
|
specification_version: 3
|
80
92
|
summary: A pure Ruby interface to the WordNet database
|