| Class | WordNet::Synset::Pointer |
| In: |
lib/wordnet/synset.rb
(CVS)
|
| Parent: | Object |
The "pointer" type that encapsulates relationships between one synset and another.
| 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). |
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.
# 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>"
# 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
Return the syntactic category symbol for this pointer
# File lib/wordnet/synset.rb, line 189 def pos return SyntacticCategories[ @part_of_speech ] end
Return the pointer in its stringified form.
# 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