wordnet 1.0.0.pre.139 → 1.0.0.pre.140

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data.tar.gz.sig +0 -0
  2. data/lib/wordnet/synset.rb +74 -5
  3. metadata +2 -2
  4. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
@@ -144,9 +144,23 @@ class WordNet::Synset < WordNet::Model( :synsets )
144
144
  #
145
145
  # :section: Dataset Methods
146
146
  # This is a set of methods that return a Sequel::Dataset for Synsets pre-filtered
147
- # by a certain criteria. They can be used to do stuff like:
147
+ # by a certain criteria. They can be used to do low-level queries against the
148
+ # WordNetSQL database; stuff like:
148
149
  #
149
- # lexicon[ :language ].synsets_dataset.nouns
150
+ # lexicon = WordNet::Lexicon.new # connect to the DB
151
+ # WordNet::Synset.nouns.filter { :definition.like('%vocal%') }.limit( 5 ).all
152
+ # # => [#<WordNet::Synset:0x7fdf04e33f88 {100545344} 'vocal music' (noun): [noun.act] music
153
+ # # that is vocalized (as contrasted with instrumental music)>,
154
+ # # #<WordNet::Synset:0x7fdf04e33e70 {100545501} 'singing, vocalizing' (noun): [noun.act]
155
+ # # the act of singing vocal music>,
156
+ # # #<WordNet::Synset:0x7fdf04e33d58 {101525720} 'oscine, oscine bird' (noun):
157
+ # # [noun.animal] passerine bird having specialized vocal apparatus>,
158
+ # # #<WordNet::Synset:0x7fdf04e33c18 {101547143} 'clamatores, suborder clamatores'
159
+ # # (noun): [noun.animal] used in some classification systems; a suborder or
160
+ # # superfamily nearly coextensive with suborder Tyranni; Passeriformes having
161
+ # # relatively simple vocal organs and little power of song; clamatorial birds>,
162
+ # # #<WordNet::Synset:0x7fdf04e33ab0 {102511633} 'syrinx' (noun): [noun.animal] the vocal
163
+ # # organ of a bird>]
150
164
  #
151
165
 
152
166
  ##
@@ -438,6 +452,28 @@ class WordNet::Synset < WordNet::Model( :synsets )
438
452
 
439
453
  #
440
454
  # :section: Traversal Methods
455
+ # These are methods for doing recursive iteration over a particular lexical
456
+ # link. For example, if you're interested in not only the hypernyms of the
457
+ # receiving synset, but its hypernyms' hypernyms as well, and so on up the
458
+ # tree, you can make a traversal enumerator for it:
459
+ #
460
+ # ss = $lex[:fencing]
461
+ # # => #<WordNet::Synset:0x7fb582c24400 {101171644} 'fencing' (noun): [noun.act] the art or
462
+ # sport of fighting with swords (especially the use of foils or epees or sabres to score
463
+ # points under a set of rules)>
464
+ #
465
+ # e = ss.traverse( :hypernyms )
466
+ # # => #<Enumerator: ...>
467
+ #
468
+ # e.to_a
469
+ # # => [#<WordNet::Synset:0x7fb582cd2848 {100041468} 'play, swordplay' (noun): [noun.act] the
470
+ # act using a sword (or other weapon) vigorously and skillfully>,
471
+ # #<WordNet::Synset:0x7fb582ccf738 {100037396} 'action' (noun): [noun.act] something
472
+ # done (usually as opposed to something said)>,
473
+ # ... ]
474
+ #
475
+ # e.with_index.each {|ss,i| puts "%02d: %s" % [i, ss] }
476
+ # # etc.
441
477
  #
442
478
 
443
479
  ### Union: Return the least general synset that the receiver and
@@ -469,8 +505,21 @@ class WordNet::Synset < WordNet::Model( :synsets )
469
505
  ### If no block is given, return an Enumerator that will do the same thing instead.
470
506
  ###
471
507
  ### # Print all the parts of a boot
472
- ### puts lexicon[:boot].traverse( :member_meronyms ).all
508
+ ### puts lexicon[:boot].traverse( :member_meronyms ).to_a
473
509
  ###
510
+ ### You can also traverse with an addiitional argument that indicates the depth of
511
+ ### recursion by calling #with_depth on the Enumerator:
512
+ ###
513
+ ### $lex[:fencing].traverse( :hypernyms ).with_depth.each {|ss,d| puts "%02d: %s" % [d,ss] }
514
+ ### # (outputs:)
515
+ ###
516
+ ### 01: play, swordplay (noun): [noun.act] the act using a sword (or other weapon) vigorously
517
+ ### and skillfully (hypernym: 1, hyponym: 1)
518
+ ### 02: action (noun): [noun.act] something done (usually as opposed to something said)
519
+ ### (hypernym: 1, hyponym: 33)
520
+ ### 03: act, deed, human action, human activity (noun): [noun.tops] something that people do
521
+ ### or cause to happen (hypernym: 1, hyponym: 40)
522
+ ### ...
474
523
  ###
475
524
  def traverse( type, &block )
476
525
  enum = Enumerator.new do |yielder|
@@ -486,7 +535,13 @@ class WordNet::Synset < WordNet::Model( :synsets )
486
535
  begin
487
536
  self.log.debug " %d traversal/s left" % [ traversals.length ]
488
537
  syn = traversals.last.next
489
- yielder.yield( syn )
538
+
539
+ if enum.with_depth?
540
+ yielder.yield( syn, traversals.length )
541
+ else
542
+ yielder.yield( syn )
543
+ end
544
+
490
545
  traversals << syn.semanticlink_enum( type ) if recurses
491
546
  rescue StopIteration
492
547
  traversals.pop
@@ -495,6 +550,16 @@ class WordNet::Synset < WordNet::Model( :synsets )
495
550
  end
496
551
  end
497
552
 
553
+ def enum.with_depth?
554
+ @with_depth = false if !defined?( @with_depth )
555
+ return @with_depth
556
+ end
557
+
558
+ def enum.with_depth
559
+ @with_depth = true
560
+ self
561
+ end
562
+
498
563
  return enum.each( &block ) if block
499
564
  return enum
500
565
  end
@@ -504,11 +569,15 @@ class WordNet::Synset < WordNet::Model( :synsets )
504
569
  ### the receiver, returning the depth it was found at if it's found, or nil if it
505
570
  ### wasn't found.
506
571
  def search( type, synset )
507
- found, depth = self.traverse( type ).find {|ss,depth| synset == ss }
572
+ found, depth = self.traverse( type ).with_depth.find {|ss,depth| synset == ss }
508
573
  return depth
509
574
  end
510
575
 
511
576
 
577
+ #
578
+ # :section:
579
+ #
580
+
512
581
  ### Return a human-readable representation of the objects, suitable for debugging.
513
582
  def inspect
514
583
  return "#<%p:%0#x {%d} '%s' (%s): [%s] %s>" % [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.139
4
+ version: 1.0.0.pre.140
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,7 +36,7 @@ cert_chain:
36
36
  YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
37
37
  Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
38
38
  cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
- date: 2012-09-05 00:00:00.000000000 Z
39
+ date: 2012-09-06 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sequel
metadata.gz.sig CHANGED
Binary file