rwordnet2 2.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 +7 -0
- data/History.txt +21 -0
- data/README.markdown +76 -0
- data/WordNet-3.0/AUTHORS +6 -0
- data/WordNet-3.0/COPYING +31 -0
- data/WordNet-3.0/LICENSE +31 -0
- data/WordNet-3.0/README +101 -0
- data/WordNet-3.0/dict/data.adj +18185 -0
- data/WordNet-3.0/dict/data.adv +3650 -0
- data/WordNet-3.0/dict/data.noun +82144 -0
- data/WordNet-3.0/dict/data.verb +13796 -0
- data/WordNet-3.0/dict/index.adj +21508 -0
- data/WordNet-3.0/dict/index.adv +4510 -0
- data/WordNet-3.0/dict/index.noun +117827 -0
- data/WordNet-3.0/dict/index.verb +11558 -0
- data/examples/benchmark.rb +14 -0
- data/examples/dictionary.rb +20 -0
- data/examples/full_hypernym.rb +9 -0
- data/examples/morphy.rb +20 -0
- data/examples/synset_find.rb +8 -0
- data/lib/rwordnet/db.rb +25 -0
- data/lib/rwordnet/lemma.rb +87 -0
- data/lib/rwordnet/pointer.rb +32 -0
- data/lib/rwordnet/pointers.rb +82 -0
- data/lib/rwordnet/synset.rb +286 -0
- data/lib/rwordnet/version.rb +3 -0
- data/lib/rwordnet.rb +5 -0
- data/morphy/exceptions/adj.exc +1490 -0
- data/morphy/exceptions/adv.exc +7 -0
- data/morphy/exceptions/noun.exc +2054 -0
- data/morphy/exceptions/verb.exc +2401 -0
- data/test/test_helper.rb +35 -0
- data/test/unit/db_test.rb +14 -0
- data/test/unit/lemma_test.rb +94 -0
- data/test/unit/pointer_test.rb +26 -0
- data/test/unit/synset_test.rb +83 -0
- metadata +79 -0
data/test/test_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
module SimpleCov::Configuration
|
6
|
+
def clean_filters
|
7
|
+
@filters = []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
SimpleCov.configure do
|
12
|
+
clean_filters
|
13
|
+
load_profile 'test_frameworks'
|
14
|
+
end
|
15
|
+
|
16
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
17
|
+
add_filter "/.rvm/"
|
18
|
+
end
|
19
|
+
|
20
|
+
require "bundler/setup"
|
21
|
+
require "maxitest/autorun"
|
22
|
+
|
23
|
+
$LOAD_PATH.unshift Bundler.root.join("lib")
|
24
|
+
require "rwordnet"
|
25
|
+
|
26
|
+
Minitest::Test.class_eval do
|
27
|
+
def with_db_path(path)
|
28
|
+
begin
|
29
|
+
old, WordNet::DB.path = WordNet::DB.path, path
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
WordNet::DB.path = old
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe WordNet::DB do
|
4
|
+
it 'sets and reads path' do
|
5
|
+
with_db_path("WordNetPath") { WordNet::DB.path.must_equal "WordNetPath" }
|
6
|
+
end
|
7
|
+
|
8
|
+
it "opens a relative path" do
|
9
|
+
result = WordNet::DB.open(File.join("dict", "index.verb")) do |f|
|
10
|
+
f.gets
|
11
|
+
end
|
12
|
+
result.must_equal " 1 This software and database is being provided to you, the LICENSEE, by \n"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe WordNet::Lemma do
|
4
|
+
describe ".find" do
|
5
|
+
it 'finds a lemma by string' do
|
6
|
+
lemma = WordNet::Lemma.find("fruit", :noun)
|
7
|
+
lemma.to_s.must_equal "fruit,n"
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'caches found' do
|
11
|
+
lemma1 = WordNet::Lemma.find("fruit", :noun)
|
12
|
+
lemma2 = with_db_path "does-not-exist" do
|
13
|
+
WordNet::Lemma.find("fruit", :noun)
|
14
|
+
end
|
15
|
+
lemma1.word.must_equal lemma2.word
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'only scans the db once' do
|
19
|
+
lemma1 = WordNet::Lemma.find("fruit", :noun)
|
20
|
+
lemma2 = with_db_path "does-not-exist" do
|
21
|
+
WordNet::Lemma.find("table", :noun)
|
22
|
+
end
|
23
|
+
lemma2.word.must_equal "table"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'can lookup different things' do
|
27
|
+
lemma1 = WordNet::Lemma.find("fruit", :noun)
|
28
|
+
lemma2 = WordNet::Lemma.find("banana", :noun)
|
29
|
+
lemma1.word.must_equal "fruit"
|
30
|
+
lemma2.word.must_equal "banana"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not find word in wrong file' do
|
34
|
+
lemma = WordNet::Lemma.find("elephant", :verb)
|
35
|
+
lemma.must_equal nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'caches unfound' do
|
39
|
+
WordNet::Lemma.find("elephant", :verb)
|
40
|
+
lemma2 = with_db_path "does-not-exist" do
|
41
|
+
WordNet::Lemma.find("elephant", :verb)
|
42
|
+
end
|
43
|
+
lemma2.must_equal nil
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'fails on unknown type' do
|
47
|
+
assert_raises Errno::ENOENT do
|
48
|
+
WordNet::Lemma.find("fruit", :sdjksdfjkdfskjsdfjk)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "does not find by regexp" do
|
53
|
+
WordNet::Lemma.find(".", :verb).must_equal nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe ".find_all" do
|
58
|
+
it "finds all pos" do
|
59
|
+
result = WordNet::Lemma.find_all("fruit")
|
60
|
+
result.size.must_equal 2
|
61
|
+
result.map(&:pos).sort.must_equal ["n", "v"]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns empty array for unfound" do
|
65
|
+
WordNet::Lemma.find_all("sdjkhdfsjfdsjhkfds").must_equal []
|
66
|
+
end
|
67
|
+
|
68
|
+
it "does not produce a circular reference" do
|
69
|
+
l = WordNet::Lemma.find_all("blink")[1]
|
70
|
+
l.synsets[1].expanded_first_hypernyms.wont_be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#synsets" do
|
75
|
+
it 'finds them' do
|
76
|
+
lemma = WordNet::Lemma.find("fruit", :noun)
|
77
|
+
synsets = lemma.synsets
|
78
|
+
synsets.size.must_equal 3
|
79
|
+
synsets[1].to_s.must_equal "(n) yield, fruit (an amount of a product)"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe ".new" do
|
84
|
+
it "builds all fields" do
|
85
|
+
lemma = WordNet::Lemma.new("fruit n 3 3 @ ~ + 3 3 13134947 04612722 07294550", 123)
|
86
|
+
lemma.id.must_equal 123
|
87
|
+
lemma.word.must_equal "fruit"
|
88
|
+
lemma.pos.must_equal "n"
|
89
|
+
lemma.pointer_symbols.must_equal ["@", "~", "+"]
|
90
|
+
lemma.tagsense_count.must_equal 3
|
91
|
+
lemma.synset_offsets.must_equal [13134947, 4612722, 7294550]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe WordNet::Pointer do
|
4
|
+
let(:pointer) { WordNet::Pointer.new(symbol: "s", offset: 123, pos: "v", source: "1234") }
|
5
|
+
|
6
|
+
describe "#initialize" do
|
7
|
+
it "sets all values" do
|
8
|
+
pointer.symbol.must_equal "s"
|
9
|
+
pointer.offset.must_equal 123
|
10
|
+
pointer.pos.must_equal "v"
|
11
|
+
pointer.source.must_equal "12"
|
12
|
+
pointer.target.must_equal "34"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#is_semantic?" do
|
17
|
+
it "is not semantic for non-0" do
|
18
|
+
pointer.is_semantic?.must_equal false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is semantic for all-0" do
|
22
|
+
pointer = WordNet::Pointer.new(symbol: "s", offset: 123, pos: "v", source: "0000")
|
23
|
+
pointer.is_semantic?.must_equal true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
describe WordNet::Synset do
|
4
|
+
def self.synsets
|
5
|
+
@synsets ||= WordNet::Lemma.find("fruit", :noun).synsets
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:synsets) { self.class.synsets }
|
9
|
+
|
10
|
+
it 'get synsets for a lemma' do
|
11
|
+
assert_equal 3, synsets.size
|
12
|
+
assert_equal "(n) fruit (the ripened reproductive body of a seed plant)",synsets[0].to_s
|
13
|
+
assert_equal "an amount of a product",synsets[1].gloss
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'get hypernym for a synset' do
|
17
|
+
hypernym = synsets[0].relation(WordNet::HYPERNYM)
|
18
|
+
hypernym = synsets[0].hypernym
|
19
|
+
assert_equal 1,hypernym.size
|
20
|
+
assert_equal "(n) reproductive structure (the parts of a plant involved in its reproduction)",hypernym.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'test shorthand for get_relation' do
|
24
|
+
hypernym = synsets[0].relation(WordNet::HYPERNYM)
|
25
|
+
hypernym2 = synsets[0].hypernym
|
26
|
+
assert_equal hypernym[0].gloss, hypernym2.gloss
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'get hyponyms for a synset' do
|
30
|
+
hyponym = synsets[0].relation(WordNet::HYPONYM)
|
31
|
+
assert_equal 29,hyponym.size
|
32
|
+
assert_equal "fruit of various buckthorns yielding dyes or pigments",hyponym[26].gloss
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'test expanded hypernym tree' do
|
36
|
+
expanded = synsets[0].expanded_first_hypernyms
|
37
|
+
assert_equal 8, expanded.size
|
38
|
+
assert_equal "entity", expanded[expanded.size-1].words[0]
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'finds a correct antonym' do
|
42
|
+
to_fall = WordNet::Lemma.find("fall", :verb).synsets[1]
|
43
|
+
assert_includes to_fall.antonyms[0].words, "rise"
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'finds hypernyms and hyponyms' do
|
47
|
+
animal = WordNet::Lemma.find("animal", :noun).synsets[0]
|
48
|
+
assert_includes animal.hyponyms[0].words, "pest"
|
49
|
+
assert_includes animal.hypernyms[0].words, "organism"
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'lemmatises with morphy' do
|
53
|
+
assert_includes WordNet::Synset.morphy('animals', 'noun'), "animal"
|
54
|
+
assert_includes WordNet::Synset.morphy_all('animals'), "animal"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns an empty list for unmorphiable words' do
|
58
|
+
assert_equal WordNet::Synset.morphy('not_a_word!#@', 'noun').size, 0
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'finds lemmatised synsets' do
|
62
|
+
take = WordNet::Synset.find_all('take').map { |x| x.words }.flatten
|
63
|
+
assert_includes take, "claim"
|
64
|
+
assert_includes take, "ingest"
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'finds expanded hypernyms' do
|
68
|
+
animal = WordNet::Lemma.find("animal", :noun).synsets[0]
|
69
|
+
assert_includes animal.expanded_hypernyms.map { |x| x.words }.flatten, "entity"
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'finds expanded hypernyms with the right depth' do
|
73
|
+
animal = WordNet::Lemma.find("animal", :noun).synsets[0]
|
74
|
+
assert_equal animal.expanded_hypernyms_depth[1], 6
|
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
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwordnet2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trevor Fountain
|
8
|
+
- Wolfram Sieber
|
9
|
+
- Michael Grosser
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description:
|
16
|
+
email: trevor@texasexpat.net
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- History.txt
|
22
|
+
- README.markdown
|
23
|
+
- WordNet-3.0/AUTHORS
|
24
|
+
- WordNet-3.0/COPYING
|
25
|
+
- WordNet-3.0/LICENSE
|
26
|
+
- WordNet-3.0/README
|
27
|
+
- WordNet-3.0/dict/data.adj
|
28
|
+
- WordNet-3.0/dict/data.adv
|
29
|
+
- WordNet-3.0/dict/data.noun
|
30
|
+
- WordNet-3.0/dict/data.verb
|
31
|
+
- WordNet-3.0/dict/index.adj
|
32
|
+
- WordNet-3.0/dict/index.adv
|
33
|
+
- WordNet-3.0/dict/index.noun
|
34
|
+
- WordNet-3.0/dict/index.verb
|
35
|
+
- examples/benchmark.rb
|
36
|
+
- examples/dictionary.rb
|
37
|
+
- examples/full_hypernym.rb
|
38
|
+
- examples/morphy.rb
|
39
|
+
- examples/synset_find.rb
|
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
|
+
- morphy/exceptions/adj.exc
|
48
|
+
- morphy/exceptions/adv.exc
|
49
|
+
- morphy/exceptions/noun.exc
|
50
|
+
- morphy/exceptions/verb.exc
|
51
|
+
- test/test_helper.rb
|
52
|
+
- test/unit/db_test.rb
|
53
|
+
- test/unit/lemma_test.rb
|
54
|
+
- test/unit/pointer_test.rb
|
55
|
+
- test/unit/synset_test.rb
|
56
|
+
homepage: https://github.com/rahmanme/rwordnet
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.1
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.4.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A pure Ruby interface to the WordNet database
|
79
|
+
test_files: []
|