Class WordNet::Synset::Pointer
In: lib/wordnet/synset.rb  (CVS)
Parent: Object

The "pointer" type that encapsulates relationships between one synset and another.

Methods

==   inspect   new   parse   pos   synset   to_s   type_symbol  

Included Modules

WordNet::Constants CrossCase

Attributes

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::SyntacticCategories.
source_wn  [RW]  The word number in the source synset
subtype  [RW]  The subtype of the pointer, if any. Will be one of the keys of one of the hashes in PointerSubTypes (e.g., :portion).
target_wn  [RW]  The word number in the target synset
type  [RW]  The type of the pointer. Will be one of the keys of WordNet::PointerTypes (e.g., :meronym).

Public Class methods

Create a new synset pointer with the given arguments. The ptrType is the type of the link between synsets, and must be either a key or a value of WordNet::Constants::PointerTypes. 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::SyntacticCategories. 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.

[Source]

# File lib/wordnet/synset.rb, line 94
            def initialize( type, offset, pos=Noun, source_wn=0, target_wn=0 )

                # Allow type = '!', 'antonym', or :antonym. Also handle
                # splitting of compound pointers (e.g., :memberMeronym / '%m')
                # into their correct type/subtype parts.
                @type = @subtype = nil
                if type.to_s.length == 1
                    @type = PointerSymbols[ type[0,1] ]
                    
                elsif type.to_s.length == 2
                    @type = PointerSymbols[ type[0,1] ]
                    raise "No known subtypes for '%s'" % [@type] unless
                        PointerSubTypes.key?( @type )
                    @subtype = PointerSubTypes[ @type ].index( type ) or
                        raise "Unknown subtype '%s' for '%s'" %
                        [ type, @type ]
                        
                else
                    if PointerTypes.key?( type.to_sym )
                        @type = type.to_sym
                    elsif /([a-z]+)([A-Z][a-z]+)/ =~ type.to_s
                        subtype, maintype = $1, $2.downcase
                        @type = maintype.to_sym if
                            PointerTypes.key?( maintype.to_sym )
                        @subtype = subtype.to_sym
                    end
                end

                raise ArgumentError, "No such pointer type %p" % type if
                    @type.nil?

                # Allow pos = 'n', 'noun', or :noun
                @part_of_speech = nil
                if pos.to_s.length == 1
                    @part_of_speech = SyntacticSymbols[ pos ]
                else
                    @part_of_speech = pos.to_sym if
                        SyntacticCategories.key?( pos.to_sym )
                end
                raise ArgumentError, "No such part of speech %p" % pos if
                    @part_of_speech.nil?

                # Other attributes
                @offset     = offset
                @source_wn  = source_wn
                @target_wn  = target_wn
            end

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

  "<pointer_symbol> <synset_offset>%<pos> <source/target>"

[Source]

# File lib/wordnet/synset.rb, line 70
            def self::parse( pointerString )
                type, offsetPos, ptrNums = pointerString.split(/\s+/)
                offset, pos = offsetPos.split( /%/, 2 )
                new( type, offset, pos, ptrNums[0,2], ptrNums[2,2] )
            end

Public Instance methods

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

[Source]

# File lib/wordnet/synset.rb, line 206
            def ==( other )
                return false unless other.is_a?( self.class )
                other.offset == self.offset &&
                    other.type == self.type
            end

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

[Source]

# File lib/wordnet/synset.rb, line 171
            def inspect
                "#<%s:0x%08x %s %s>" % [
                    self.class.name,
                    self.object_id,
                    @subtype ? "#@type(#@subtype)" : @type,
                    self.synset,
                ]
            end

Return the syntactic category symbol for this pointer

[Source]

# File lib/wordnet/synset.rb, line 189
            def pos
                return SyntacticCategories[ @part_of_speech ]
            end

Return the synset key of the target synset (i.e., <offset>%<pos symbol>).

[Source]

# File lib/wordnet/synset.rb, line 183
            def synset
                self.offset + "%" + self.pos
            end

Return the pointer in its stringified form.

[Source]

# File lib/wordnet/synset.rb, line 214
            def to_s
                "%s %d%%%s %02x%02x" % [ 
                    ptr.type_symbol,
                    ptr.offset,
                    ptr.posSymbol,
                    ptr.source_wn,
                    ptr.target_wn,
                ]
            end

Return the pointer type symbol for this pointer

[Source]

# File lib/wordnet/synset.rb, line 195
            def type_symbol
                unless @subtype
                    return PointerTypes[ @type ]
                else
                    return PointerSubTypes[ @type ][ @subtype ]
                end
            end

[Validate]