rwordnet 1.1.0 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af20be262ff83829299dfcaab7bdaf6daca77d9e
4
- data.tar.gz: 5fdf6de52538acc9e2e6c6cd59af7f8055aa1361
3
+ metadata.gz: 9518288f71b4a82f57e48e62f1adb0842c799857
4
+ data.tar.gz: f56b54be645baaaff6b855745cbc122ef8e4a035
5
5
  SHA512:
6
- metadata.gz: 9f232d93029c8f200e6ba54af4461df6a4430e7ecc1189510cee59447303a350bb47f6deab13ad9b3cb7d6730b52d514b73377f673f1d81c03b4997d2a6ababe
7
- data.tar.gz: d374907bacd015be0274bb8f8219d1803bc884b9c852f99c83441ca303e7fe2ac4687be7341462e6bb5fb54657f09c91d4cf64edc746ee27c8577ce2286a2942
6
+ metadata.gz: c6c0e42b463a29d85a1ece1a3eb68d1c9924dd011e1bc1c9f4058478d1e330fc78219bc5ed76ea68313a1b4944862905aa6809dace2d77b843c6295056e5e69b
7
+ data.tar.gz: c04cbcc3ead95d96d4c98c4427e3b7bdfaaa2c8f1c799877475009977bd8ebb5f54e2104f1642d9144b369476b48276d7abb20c7e8d14c9457b58a2e5036acd4
@@ -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 'wordnet'
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 'wordnet'
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
  ```
@@ -1,5 +1,5 @@
1
1
  require 'benchmark'
2
- require 'wordnet'
2
+ require 'rwordnet'
3
3
 
4
4
  initial = Benchmark.realtime do
5
5
  WordNet::Lemma.find(ARGV[0] || raise("Usage: ruby benchmark.rb noun"), :noun)
@@ -1,5 +1,5 @@
1
1
  # Use WordNet as a command-line dictionary.
2
- require 'wordnet'
2
+ require 'rwordnet'
3
3
 
4
4
  if ARGV.size != 1
5
5
  puts "Usage: ruby dictionary.rb word"
@@ -1,4 +1,4 @@
1
- require 'wordnet'
1
+ require 'rwordnet'
2
2
 
3
3
  # Find the word 'dog'
4
4
  lemma = WordNet::Lemma.find("dog", :noun)
@@ -1,4 +1,4 @@
1
- require 'wordnet'
1
+ require 'rwordnet'
2
2
 
3
3
  puts 'dogs'
4
4
  puts '--------------'
@@ -1,4 +1,4 @@
1
- require 'wordnet'
1
+ require 'rwordnet'
2
2
 
3
3
  puts 'hiking'
4
4
  WordNet::Synset.find_all('hiking').each{|d| puts d}
@@ -0,0 +1,5 @@
1
+ require 'rwordnet/pointer'
2
+ require 'rwordnet/db'
3
+ require 'rwordnet/lemma'
4
+ require 'rwordnet/pointers'
5
+ require 'rwordnet/synset'
@@ -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 = @morphological_substitutions[pos]
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 Synset of this sense's antonym
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
@@ -0,0 +1,3 @@
1
+ module WordNet
2
+ VERSION = "2.0.0"
3
+ end
@@ -21,7 +21,7 @@ require "bundler/setup"
21
21
  require "maxitest/autorun"
22
22
 
23
23
  $LOAD_PATH.unshift Bundler.root.join("lib")
24
- require "wordnet"
24
+ require "rwordnet"
25
25
 
26
26
  Minitest::Test.class_eval do
27
27
  def with_db_path(path)
@@ -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: 1.1.0
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: 2015-11-18 00:00:00.000000000 Z
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/wordnet.rb
41
- - lib/wordnet/db.rb
42
- - lib/wordnet/lemma.rb
43
- - lib/wordnet/pointer.rb
44
- - lib/wordnet/pointers.rb
45
- - lib/wordnet/synset.rb
46
- - lib/wordnet/version.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
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.4.7
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
@@ -1,5 +0,0 @@
1
- require 'wordnet/pointer'
2
- require 'wordnet/db'
3
- require 'wordnet/lemma'
4
- require 'wordnet/pointers'
5
- require 'wordnet/synset'
@@ -1,3 +0,0 @@
1
- module WordNet
2
- VERSION = "1.1.0"
3
- end