Linguistics 1.0.3 → 1.0.5

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.
@@ -81,20 +81,19 @@
81
81
  # $Id: wordnet.rb,v 1.3 2003/09/14 11:28:02 deveiant Exp $
82
82
  #
83
83
 
84
- module Linguistics
85
- module EN
84
+ module Linguistics::EN
86
85
 
87
- @hasWordnet = false
88
- @wnError = nil
89
- @wnLexicon = nil
86
+ @has_wordnet = false
87
+ @wn_error = nil
88
+ @wn_lexicon = nil
90
89
 
91
90
  # Load WordNet and open the lexicon if possible, saving the error that
92
91
  # occurs if anything goes wrong.
93
92
  begin
94
93
  require 'wordnet'
95
- @hasWordnet = true
94
+ @has_wordnet = true
96
95
  rescue LoadError => err
97
- @wnError = err
96
+ @wn_error = err
98
97
  end
99
98
 
100
99
 
@@ -104,22 +103,22 @@ module EN
104
103
  class << self
105
104
 
106
105
  ### Returns +true+ if WordNet was loaded okay
107
- def hasWordnet? ; @hasWordnet; end
106
+ def has_wordnet? ; @has_wordnet; end
108
107
 
109
108
  ### If #haveWordnet? returns +false+, this can be called to fetch the
110
109
  ### exception which was raised when WordNet was loaded.
111
- def wnError ; @wnError; end
110
+ def wn_error ; @wn_error; end
112
111
 
113
112
  ### The instance of the WordNet::Lexicon used for all Linguistics WordNet
114
113
  ### functions.
115
- def wnLexicon
116
- if @wnError
114
+ def wn_lexicon
115
+ if @wn_error
117
116
  raise NotImplementedError,
118
117
  "WordNet functions are not loaded: %s" %
119
- @wnError.message
118
+ @wn_error.message
120
119
  end
121
120
 
122
- @wnLexicon ||= WordNet::Lexicon::new
121
+ @wn_lexicon ||= WordNet::Lexicon::new
123
122
  end
124
123
 
125
124
  ### Make a function that calls the method +meth+ on the synset of an input
@@ -152,17 +151,17 @@ module EN
152
151
  ### Look up the synset associated with the given word or collocation in the
153
152
  ### WordNet lexicon and return a WordNet::Synset object.
154
153
  def synset( word, pos=nil, sense=1 )
155
- lex = Linguistics::EN::wnLexicon
156
- if pos.is_a?( Fixnum)
154
+ lex = Linguistics::EN::wn_lexicon
155
+ if pos.is_a?( Fixnum )
157
156
  sense = pos
158
157
  pos = nil
159
158
  end
160
159
  postries = pos ? [pos] : [:noun, :verb, :adjective, :adverb, :other]
161
160
  syn = nil
162
161
 
163
- postries.each {|pos|
162
+ postries.each do |pos|
164
163
  break if syn = lex.lookupSynsets( word.to_s, pos, sense )
165
- }
164
+ end
166
165
 
167
166
  return syn
168
167
  end
@@ -172,7 +171,7 @@ module EN
172
171
  ### the WordNet lexicon and return an Array of WordNet::Synset objects. If
173
172
  ### +pos+ is +nil+, return synsets for all parts of speech.
174
173
  def synsets( word, pos=nil )
175
- lex = Linguistics::EN::wnLexicon
174
+ lex = Linguistics::EN::wn_lexicon
176
175
  postries = pos ? [pos] : [:noun, :verb, :adjective, :adverb, :other]
177
176
  syns = []
178
177
 
@@ -199,16 +198,27 @@ module EN
199
198
 
200
199
  # Returns the name of the lexicographer file that contains the raw data for
201
200
  # the receiver.
202
- def_synset_function :lexInfo
201
+ def_synset_function :lex_info
203
202
 
204
203
  # :TODO: Finish these comments, and figure out how the hell to get the
205
204
  # methods to show up in RDoc.
206
205
  def_synset_function :frames
207
206
 
207
+
208
+ # Returns the synsets for the receiver's antonyms, if any. Ex:
209
+ # 'opaque'.en.synset.antonyms
210
+ # ==> [#<WordNet::Synset:0x010ca614/454927 clear (adjective): "free
211
+ # from cloudiness; allowing light to pass through; "clear water";
212
+ # "clear plastic bags"; "clear glass"; "the air is clear and clean""
213
+ # (similarTos: 6, attributes: 1, derivations: 2, antonyms: 1,
214
+ # seeAlsos: 1)>]
208
215
  def_synset_function :antonyms
216
+
209
217
  def_synset_function :hypernyms
218
+ def_synset_function :instanceHypernyms
210
219
  def_synset_function :entailment
211
220
  def_synset_function :hyponyms
221
+ def_synset_function :instanceHyponyms
212
222
  def_synset_function :causes
213
223
  def_synset_function :verbgroups
214
224
  def_synset_function :similarTo
@@ -248,6 +258,5 @@ module EN
248
258
  def_synset_function :usageMembers
249
259
 
250
260
 
251
- end # module EN
252
- end # module Linguistics
261
+ end # module Linguistics::EN
253
262
 
data/test.rb CHANGED
@@ -37,12 +37,12 @@ ARGV.options {|oparser|
37
37
 
38
38
  oparser.on( "--debug", "-d", TrueClass, "Turn debugging on" ) {
39
39
  $DEBUG = true
40
- debugMsg "Turned debugging on."
40
+ debug_msg "Turned debugging on."
41
41
  }
42
42
 
43
43
  oparser.on( "--verbose", "-v", TrueClass, "Make progress verbose" ) {
44
44
  $VERBOSE = true
45
- debugMsg "Turned verbose on."
45
+ debug_msg "Turned verbose on."
46
46
  }
47
47
 
48
48
  # Handle the 'help' option
@@ -68,9 +68,9 @@ Find.find( File::join($basedir,"tests") ) {|file|
68
68
  Find.prune unless patterns.find {|pat| pat =~ file}
69
69
  end
70
70
 
71
- debugMsg "Considering '%s': " % file
71
+ debug_msg "Considering '%s': " % file
72
72
  next unless file =~ /\.tests.rb$/
73
- debugMsg "Requiring '%s'..." % file
73
+ debug_msg "Requiring '%s'..." % file
74
74
  require "#{file}"
75
75
  requires << file
76
76
  }
@@ -3,7 +3,7 @@
3
3
  # Unit test for English conjunctions
4
4
  # $Id: conjunction.tests.rb,v 1.2 2003/09/11 05:03:12 deveiant Exp $
5
5
  #
6
- # Copyright (c) 2003 The FaerieMUD Consortium.
6
+ # Copyright (c) 2003, 2005 The FaerieMUD Consortium.
7
7
  #
8
8
 
9
9
  unless defined? Linguistics::TestCase
@@ -18,7 +18,7 @@ end
18
18
  ### parses in which the actual parser-generator's behaviour is defined.
19
19
  class EnglishConjunctionsTestCase < Linguistics::TestCase
20
20
 
21
- Linguistics::use( :en )
21
+ Linguistics::use( :en, :installProxy => true )
22
22
  include Linguistics::EN
23
23
 
24
24
  Tests = {
@@ -108,7 +108,93 @@ class EnglishConjunctionsTestCase < Linguistics::TestCase
108
108
  ### T E S T S
109
109
  #################################################################
110
110
 
111
+ Items = %w{cow chicken blancmange cyclist}
111
112
 
113
+ # Test for defect #6
114
+ def test_conjunction_should_use_supplied_block_for_object_transform_on_first_invocation
115
+ rval = nil
116
+
117
+ # Create a new class, as we need to guarantee that this will be the
118
+ # first #conjunction call to it.
119
+ collection = Class::new {
120
+ include Enumerable, Linguistics
121
+ def initialize( *ary )
122
+ @ary = ary.flatten
123
+ end
124
+
125
+ # Delegate #each to the contained Array
126
+ def each( &block )
127
+ @ary.each( &block )
128
+ end
129
+ }
130
+
131
+ obj = collection.new( 'foo', 'bar', 'baz' )
132
+
133
+ assert_nothing_raised do
134
+ rval = obj.en.conjunction {|word| "%d-letter word" % word.length }
135
+ end
136
+ end
137
+
138
+
139
+ def test_conjunction_should_use_supplied_block_for_object_transform
140
+ rval = nil
141
+
142
+ assert_nothing_raised do
143
+ rval = Items.en.conjunction {|word| "%s-word" % word[0,1]}
144
+ end
145
+
146
+ assert_equal "three c-words and a b-word", rval
147
+ end
148
+
149
+
150
+ def test_conjunction_should_use_supplied_block_for_object_transform_through_autoproxy
151
+ rval = nil
152
+
153
+ assert_nothing_raised do
154
+ rval = Items.conjunction {|word| "%s-word" % word[0,1]}
155
+ end
156
+
157
+ assert_equal "three c-words and a b-word", rval
158
+ end
159
+
160
+ def test_conjunction_with_penultimate_separator_turned_off_should_not_use_one
161
+ rval = nil
162
+
163
+ assert_nothing_raised do
164
+ rval = Items.en.conjunction( :penultimate => false )
165
+ end
166
+
167
+ assert_equal "a cow, a chicken, a blancmange and a cyclist", rval
168
+ end
169
+
170
+ def test_three_item_conjunction_should_honor_penultimate_setting
171
+ rval = nil
172
+
173
+ assert_nothing_raised do
174
+ rval = %w{duck cow dog}.en.conjunction( :penultimate => false )
175
+ end
176
+
177
+ assert_equal "a duck, a cow and a dog", rval
178
+ end
179
+
180
+ def test_conjunction_uses_alt_separator_if_phrases_include_the_primary_one
181
+ rval = nil
182
+ scene_items = [
183
+ "desk with stamps, paper, and envelopes on it",
184
+ "basket containing milk, eggs, and broccoli",
185
+ "chair",
186
+ "wooden chest",
187
+ "hat rack",
188
+ ]
189
+
190
+ assert_nothing_raised do
191
+ rval = scene_items.conjunction
192
+ end
193
+
194
+ assert_equal "a desk with stamps, paper, and envelopes on it; " +
195
+ "a basket containing milk, eggs, and broccoli; " +
196
+ "a chair; a wooden chest; and a hat rack", rval
197
+ end
112
198
 
113
199
  end
114
200
 
@@ -3,7 +3,7 @@
3
3
  # Unit test for English inflection
4
4
  # $Id: inflect.tests.rb,v 1.2 2003/09/11 05:04:04 deveiant Exp $
5
5
  #
6
- # Copyright (c) 2003 The FaerieMUD Consortium.
6
+ # Copyright (c) 2003, 2005 The FaerieMUD Consortium.
7
7
  #
8
8
  # Much of this test was adapted from the test script for Lingua::EN::Inflect by
9
9
  # Damien Conway:
@@ -265,7 +265,7 @@ class EnglishInflectionTestCase < Linguistics::TestCase
265
265
  begin
266
266
  inDataSection = false
267
267
  methodCounter = 100
268
- File::readlines( __FILE__ ).find_all {|line|
268
+ File::readlines( __FILE__ ).find_all do |line|
269
269
  case line
270
270
  when /^__END_DATA__$/
271
271
  inDataSection = false
@@ -278,7 +278,7 @@ class EnglishInflectionTestCase < Linguistics::TestCase
278
278
  else
279
279
  inDataSection
280
280
  end
281
- }.each {|line|
281
+ end.each do |line|
282
282
  case line
283
283
  when PluralDataLine
284
284
  singular, plural, altplural, comment = $~.to_a[1,4]
@@ -301,9 +301,9 @@ class EnglishInflectionTestCase < Linguistics::TestCase
301
301
 
302
302
  methodCounter += 1
303
303
  else
304
- debugMsg "Skipped test data line '#{line.chomp}'"
304
+ debug_msg "Skipped test data line '#{line.chomp}'"
305
305
  end
306
- }
306
+ end
307
307
  end
308
308
 
309
309
  ### Overridden initializer: auto-generated test methods have an arity of 1
@@ -363,6 +363,17 @@ class EnglishInflectionTestCase < Linguistics::TestCase
363
363
  end
364
364
 
365
365
 
366
+ def test_numwords_with_an_symboland_should_use_it_to_join_words
367
+ rval = nil
368
+
369
+ assert_nothing_raised do
370
+ rval = 2006.en.numwords( :and => ' ' )
371
+ end
372
+
373
+ assert_equal "two thousand six", rval
374
+ end
375
+
376
+
366
377
  def test_0040_ordinalNumbers
367
378
  printTestHeader "English: Numbers to ordinals"
368
379
  rval = nil
@@ -33,7 +33,7 @@
33
33
  #
34
34
  # == Rcsid
35
35
  #
36
- # $Id: lingtestcase.rb 78 2005-07-13 19:58:43Z ged $
36
+ # $Id: lingtestcase.rb 95 2007-06-13 05:25:38Z deveiant $
37
37
  #
38
38
  # == Authors
39
39
  #
@@ -89,7 +89,7 @@ module Linguistics
89
89
 
90
90
  ### Output the specified <tt>msgs</tt> joined together to
91
91
  ### <tt>STDERR</tt> if <tt>$DEBUG</tt> is set.
92
- def self::debugMsg( *msgs )
92
+ def self::debug_msg( *msgs )
93
93
  return unless $DEBUG
94
94
  self.message "DEBUG>>> %s" % msgs.join('')
95
95
  end
@@ -132,7 +132,7 @@ module Linguistics
132
132
  ### Forward-compatibility method for namechange in Test::Unit
133
133
  def setup( *args )
134
134
  self.class.setupBlocks.each {|sblock|
135
- debugMsg "Calling setup block method #{sblock}"
135
+ debug_msg "Calling setup block method #{sblock}"
136
136
  self.send( sblock )
137
137
  }
138
138
  super( *args )
@@ -144,7 +144,7 @@ module Linguistics
144
144
  def teardown( *args )
145
145
  super( *args )
146
146
  self.class.teardownBlocks.each {|tblock|
147
- debugMsg "Calling teardown block method #{tblock}"
147
+ debug_msg "Calling teardown block method #{tblock}"
148
148
  self.send( tblock )
149
149
  }
150
150
  end
@@ -158,8 +158,8 @@ module Linguistics
158
158
 
159
159
 
160
160
  ### Instance alias for the like-named class method
161
- def debugMsg( *msgs )
162
- self.class.debugMsg( *msgs )
161
+ def debug_msg( *msgs )
162
+ self.class.debug_msg( *msgs )
163
163
  end
164
164
 
165
165
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Unit test for the 'use' function of the Linguistics module.
4
- # $Id: use.tests.rb 78 2005-07-13 19:58:43Z ged $
4
+ # $Id: use.tests.rb 95 2007-06-13 05:25:38Z deveiant $
5
5
  #
6
6
  # Copyright (c) 2003 The FaerieMUD Consortium.
7
7
  #
@@ -63,7 +63,7 @@ class UseTestCase < Linguistics::TestCase
63
63
  Linguistics::use( :en )
64
64
 
65
65
  [ TestArray, TestString, TestNumber ].each do |obj|
66
- debugMsg "obj.class.instance_variables = %s" %
66
+ debug_msg "obj.class.instance_variables = %s" %
67
67
  obj.class.instance_variables.inspect
68
68
 
69
69
  assert_respond_to obj, :en
data/utils.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Install/distribution utility functions
3
- # $Id: utils.rb 8 2005-07-13 12:35:15Z ged $
3
+ # $Id: utils.rb 10 2005-08-07 03:28:54Z ged $
4
4
  #
5
5
  # Copyright (c) 2001-2005, The FaerieMUD Consortium.
6
6
  #
@@ -168,7 +168,7 @@ module UtilityFunctions
168
168
 
169
169
  ### Output the specified <tt>msg</tt> as an ANSI-colored debugging message
170
170
  ### (yellow on blue).
171
- def debugMsg( msg )
171
+ def debug_msg( msg )
172
172
  return unless $DEBUG
173
173
  msg.chomp!
174
174
  $stderr.puts ansiCode( 'bold', 'yellow', 'on_blue' ) + ">>> #{msg}" + ansiCode( 'reset' )
@@ -372,7 +372,7 @@ module UtilityFunctions
372
372
 
373
373
  Dir::chdir( directory ) do
374
374
  output = %x{svn info}
375
- debugMsg( "Using info: %p" % output )
375
+ debug_msg( "Using info: %p" % output )
376
376
 
377
377
  if /^URL: \s* ( .* )/xi.match( output )
378
378
  uri = URI::parse( $1 )
@@ -527,7 +527,7 @@ module UtilityFunctions
527
527
  if File::exists? catalogFile
528
528
  verboseMsg "Extracting '#{keyword}' from CATALOG file (%s).\n" % catalogFile
529
529
  File::foreach( catalogFile ) {|line|
530
- debugMsg( "Examining line #{line.inspect}..." )
530
+ debug_msg( "Examining line #{line.inspect}..." )
531
531
  val = $1.strip and break if /^#\s*#{keyword}:\s*(.*)$/i =~ line
532
532
  }
533
533
  end
@@ -623,12 +623,12 @@ module UtilityFunctions
623
623
 
624
624
 
625
625
  ### Try the specified code block, printing the given
626
- def try( msg, bind=nil )
626
+ def try( msg, bind=TOPLEVEL_BINDING )
627
627
  result = ''
628
628
  if msg =~ /^to\s/
629
- message = "Trying #{msg}..."
629
+ message "Trying #{msg}...\n"
630
630
  else
631
- message = msg
631
+ message msg + "\n"
632
632
  end
633
633
 
634
634
  begin
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.8
2
+ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: Linguistics
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.3
7
- date: 2005-07-14
8
- summary: "A generic, language-neutral framework for extending Ruby objects with linguistic
9
- methods."
6
+ version: 1.0.5
7
+ date: 2007-06-12 00:00:00 -07:00
8
+ summary: A generic, language-neutral framework for extending Ruby objects with linguistic methods.
10
9
  require_paths:
11
- - lib
12
- email: "ged@FaerieMUD.org, stillflame@FaerieMUD.org"
10
+ - lib
11
+ email: ged@FaerieMUD.org, stillflame@FaerieMUD.org
13
12
  homepage: http://www.deveiate.org/projects/Linguistics/
14
13
  rubyforge_project:
15
14
  description:
@@ -19,40 +18,49 @@ bindir: bin
19
18
  has_rdoc: false
20
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
21
20
  requirements:
22
- -
23
- - ">"
24
- - !ruby/object:Gem::Version
25
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
26
24
  version:
27
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
28
29
  authors:
29
- - "Michael Granger, Martin Chase"
30
+ - Michael Granger, Martin Chase
30
31
  files:
31
- - Artistic
32
- - experiments/randobjlist.rb
33
- - install.rb
34
- - lib/linguistics/en.rb
35
- - lib/linguistics/iso639.rb
36
- - lib/linguistics.rb
37
- - lib/linguistics/en/infinitive.rb
38
- - lib/linguistics/en/linkparser.rb
39
- - lib/linguistics/en/wordnet.rb
40
- - MANIFEST
41
- - README
42
- - README.english
43
- - redist/crosscase.rb
44
- - test.rb
45
- - tests/en/conjunction.tests.rb
46
- - tests/en/inflect.tests.rb
47
- - tests/lingtestcase.rb
48
- - tests/use.tests.rb
49
- - TODO
50
- - utils.rb
51
- - ChangeLog
32
+ - Artistic
33
+ - experiments/randobjlist.rb
34
+ - install.rb
35
+ - lib/linguistics/en.rb
36
+ - lib/linguistics/iso639.rb
37
+ - lib/linguistics.rb
38
+ - lib/linguistics/en/infinitive.rb
39
+ - lib/linguistics/en/linkparser.rb
40
+ - lib/linguistics/en/wordnet.rb
41
+ - MANIFEST
42
+ - README
43
+ - README.english
44
+ - redist/crosscase.rb
45
+ - test.rb
46
+ - tests/en/conjunction.tests.rb
47
+ - tests/en/inflect.tests.rb
48
+ - tests/lingtestcase.rb
49
+ - tests/use.tests.rb
50
+ - TODO
51
+ - utils.rb
52
+ - ChangeLog
52
53
  test_files: []
54
+
53
55
  rdoc_options: []
56
+
54
57
  extra_rdoc_files: []
58
+
55
59
  executables: []
60
+
56
61
  extensions: []
62
+
57
63
  requirements: []
58
- dependencies: []
64
+
65
+ dependencies: []
66
+