Parent

Included Modules

Pointer

WordNet synonym-set pointer class — the “pointer” type that encapsulates relationships between one synset and another.

Authors

Copyright © 2002-2008 The FaerieMUD Consortium. All rights reserved.

This module is free software. You may use, modify, and/or redistribute this software under the terms of the Perl Artistic License. (See language.perl.com/misc/Artistic.html)

Much of this code was inspired by/ported from the Lingua::Wordnet Perl module by Dan Brian.

Version

 $Id: synset_pointer.rb 102 2008-09-23 15:02:51Z deveiant $

Attributes

type[RW]

The type of the pointer. Will be one of the keys of WordNet::POINTER_TYPES (e.g., :meronym).

subtype[RW]

The subtype of the pointer, if any. Will be one of the keys of one of the hashes in POINTER_SUBTYPES (e.g., :portion).

offset[RW]

The offset of the target synset

part_of_speech[RW]

The part-of-speech of the target synset. Will be one of the keys of WordNet::SYNTACTIC_CATEGORIES.

source_wn[RW]

The word number in the source synset

target_wn[RW]

The word number in the target synset

Public Class Methods

new( type, offset, pos=Noun, source_wn=0, target_wn=0 ) click to toggle source

Create a new synset pointer with the given arguments. The type is the type of the link between synsets, and must be either a key or a value of WordNet::Constants::POINTER_TYPES. The offset is the unique identifier of the target synset, and pos is its part-of-speech, which must be either a key or value of WordNet::Constants::SYNTACTIC_CATEGORIES. The source_wn and target_wn are numerical values which distinguish lexical and semantic pointers. source_wn indicates the word number in the current (source) synset, and target_wn indicates the word number in the target synset. If both are 0 (the default) it means that the pointer type of the pointer represents a semantic relation between the current (source) synset and the target synset indicated by offset.

    # File lib/wordnet/synset_pointer.rb, line 65
65:     def initialize( type, offset, pos=Noun, source_wn=0, target_wn=0 )
66:         @type = @subtype = nil
67: 
68:         @type, @subtype = self.normalize_type( type )
69:         @part_of_speech = self.normalize_part_of_speech( pos )
70: 
71:         # Other attributes
72:         @offset       = offset
73:         @source_wn    = source_wn
74:         @target_wn    = target_wn
75:     end
parse( pointer_string ) click to toggle source

Make an Array of WordNet::Synset::Pointer objects out of the given pointer_string. The pointer_string is a string of pointers delimited by WordNet::Constants::SUB_DELIM. Pointers are in the form:

  "<pointer_symbol> <synset_offset>%<pos> <source/target>"
    # File lib/wordnet/synset_pointer.rb, line 41
41:     def self::parse( pointer_string )
42:         type, offset_pos, ptr_nums = pointer_string.split(/\s+/)
43:         offset, pos = offset_pos.split( /%/, 2 )
44:         return new( type, offset, pos, ptr_nums[0,2], ptr_nums[2,2] )
45:     end

Public Instance Methods

==( other ) click to toggle source

Comparison operator. Pointer are equivalent if they point at the same synset and are of the same type.

     # File lib/wordnet/synset_pointer.rb, line 141
141:     def ==( other )
142:         return false unless other.is_a?( self.class )
143:         other.offset == self.offset &&
144:         other.type == self.type
145:     end
inspect() click to toggle source

Return the Pointer as a human-readable String suitable for debugging.

     # File lib/wordnet/synset_pointer.rb, line 106
106:     def inspect
107:         "#<%s:0x%08x %s %s>" % [
108:             self.class.name,
109:             self.object_id,
110:             @subtype ? "#@type(#@subtype)" : @type,
111:             self.synset,
112:         ]
113:     end
pos() click to toggle source

Return the syntactic category symbol for this pointer

     # File lib/wordnet/synset_pointer.rb, line 124
124:     def pos
125:         return SYNTACTIC_CATEGORIES[ @part_of_speech ]
126:     end
synset() click to toggle source

Return the synset key of the target synset (i.e., %).

     # File lib/wordnet/synset_pointer.rb, line 118
118:     def synset
119:         self.offset + "%" + self.pos
120:     end
to_s() click to toggle source

Return the pointer in its stringified form.

     # File lib/wordnet/synset_pointer.rb, line 149
149:     def to_s
150:         "%s %d%%%s %02x%02x" % [ 
151:             ptr.type_symbol,
152:             ptr.offset,
153:             ptr.posSymbol,
154:             ptr.source_wn,
155:             ptr.target_wn,
156:         ]
157:     end
type_symbol() click to toggle source

Return the pointer type symbol for this pointer

     # File lib/wordnet/synset_pointer.rb, line 130
130:     def type_symbol
131:         unless @subtype
132:             return POINTER_TYPES[ @type ]
133:         else
134:             return POINTER_SUBTYPES[ @type ][ @subtype ]
135:         end
136:     end

Protected Instance Methods

normalize_part_of_speech( pos ) click to toggle source

Given a part of speech description, normalize it into one of the WordNet parts of speech types.

     # File lib/wordnet/synset_pointer.rb, line 206
206:     def normalize_part_of_speech( pos )
207:         if pos.to_s.length == 1
208:             return SYNTACTIC_SYMBOLS[ pos ]
209:         elsif SYNTACTIC_CATEGORIES.key?( pos.to_sym )
210:             return pos.to_sym
211:         end
212: 
213:         raise ArgumentError, "No such part of speech %p" % [ pos ]
214:     end
normalize_type( typedesc ) click to toggle source

Given a type description, normalize it into one of the WordNet pointer types (and subtype, if applicable)

     # File lib/wordnet/synset_pointer.rb, line 166
166:     def normalize_type( typedesc )
167:         type = subtype = nil
168: 
169:         # Allow type = '!', 'antonym', or :antonym. Also handle
170:         # splitting of compound pointers (e.g., :member_meronym / '%m')
171:         # into their correct type/subtype parts.
172:         case typedesc.to_s.length
173:         when 1
174:             type = POINTER_SYMBOLS[ typedesc.to_s[0,1] ]
175: 
176:         when 2
177:             type = POINTER_SYMBOLS[ typedesc.to_s[0,1] ]
178:             raise "No known subtypes for '%s'" % [@type] unless
179:                 POINTER_SUBTYPES.key?( type )
180: 
181:             subtype = POINTER_SUBTYPES[ type ].index( typedesc ) or
182:                 raise "Unknown subtype '%s' for '%s'" % [ typedesc, @type ]
183: 
184:         else
185:             if POINTER_TYPES.key?( typedesc.to_sym )
186:                 type = typedesc.to_sym
187: 
188:             elsif /([a-z]+)([A-Z][a-z]+)/ =~ typedesc.to_s
189:                 subtype, maintype = $1, $2.downcase
190: 
191:                 type = maintype.to_sym if
192:                     POINTER_TYPES.key?( maintype.to_sym )
193: 
194:                 subtype = subtype.to_sym
195:             end
196:         end
197: 
198:         raise ArgumentError, "No such pointer type %p" % [ typedesc ] if type.nil?
199:             
200:         return type, subtype
201:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.