Object
The "pointer" type that encapsulates relationships between one synset and another.
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::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.rb, line 94
94: def initialize( type, offset, pos=Noun, source_wn=0, target_wn=0 )
95:
96: # Allow type = '!', 'antonym', or :antonym. Also handle
97: # splitting of compound pointers (e.g., :memberMeronym / '%m')
98: # into their correct type/subtype parts.
99: @type = @subtype = nil
100: if type.to_s.length == 1
101: @type = POINTER_SYMBOLS[ type[0,1] ]
102:
103: elsif type.to_s.length == 2
104: @type = POINTER_SYMBOLS[ type[0,1] ]
105: raise "No known subtypes for '%s'" % [@type] unless
106: POINTER_SUBTYPES.key?( @type )
107: @subtype = POINTER_SUBTYPES[ @type ].index( type ) or
108: raise "Unknown subtype '%s' for '%s'" %
109: [ type, @type ]
110:
111: else
112: if POINTER_TYPES.key?( type.to_sym )
113: @type = type.to_sym
114: elsif /([a-z]+)([A-Z][a-z]+)/ =~ type.to_s
115: subtype, maintype = $1, $2.downcase
116: @type = maintype.to_sym if
117: POINTER_TYPES.key?( maintype.to_sym )
118: @subtype = subtype.to_sym
119: end
120: end
121:
122: raise ArgumentError, "No such pointer type %p" % type if
123: @type.nil?
124:
125: # Allow pos = 'n', 'noun', or :noun
126: @part_of_speech = nil
127: if pos.to_s.length == 1
128: @part_of_speech = SYNTACTIC_SYMBOLS[ pos ]
129: else
130: @part_of_speech = pos.to_sym if
131: SYNTACTIC_CATEGORIES.key?( pos.to_sym )
132: end
133: raise ArgumentError, "No such part of speech %p" % pos if
134: @part_of_speech.nil?
135:
136: # Other attributes
137: @offset = offset
138: @source_wn = source_wn
139: @target_wn = target_wn
140: end
Make an Array of WordNet::Synset::Pointer objects out of the given pointerList. The pointerlist is a string of pointers delimited by Constants::SUB_DELIM. Pointers are in the form:
"<pointer_symbol> <synset_offset>%<pos> <source/target>"
# File lib/wordnet/synset.rb, line 70
70: def self::parse( pointerString )
71: type, offsetPos, ptrNums = pointerString.split(/\s+/)
72: offset, pos = offsetPos.split( /%/, 2 )
73: new( type, offset, pos, ptrNums[0,2], ptrNums[2,2] )
74: end
Comparison operator. Pointer are equivalent if they point at the same synset and are of the same type.
# File lib/wordnet/synset.rb, line 206
206: def ==( other )
207: return false unless other.is_a?( self.class )
208: other.offset == self.offset &&
209: other.type == self.type
210: end
Return the Pointer as a human-readable String suitable for debugging.
# File lib/wordnet/synset.rb, line 171
171: def inspect
172: "#<%s:0x%08x %s %s>" % [
173: self.class.name,
174: self.object_id,
175: @subtype ? "#@type(#@subtype)" : @type,
176: self.synset,
177: ]
178: end
Return the syntactic category symbol for this pointer
# File lib/wordnet/synset.rb, line 189
189: def pos
190: return SYNTACTIC_CATEGORIES[ @part_of_speech ]
191: end
Return the synset key of the target synset (i.e.,
# File lib/wordnet/synset.rb, line 183
183: def synset
184: self.offset + "%" + self.pos
185: end
--- SEC00012
--- ""
---
- name: offset
rw: RW
a_desc: |+
The offset of the target synset
- name: part_of_speech
rw: RW
a_desc: |+
The part-of-speech of the target synset. Will be one of the keys of
WordNet::SYNTACTIC_CATEGORIES.
- name: source_wn
rw: RW
a_desc: |+
The word number in the source synset
- name: subtype
rw: RW
a_desc: |+
The subtype of the pointer, if any. Will be one of the keys of one of the
hashes in POINTER_SUBTYPES (e.g., :portion).
- name: target_wn
rw: RW
a_desc: |+
The word number in the target synset
- name: type
rw: RW
a_desc: |+
The type of the pointer. Will be one of the keys of WordNet::POINTER_TYPES
(e.g., :meronym).
---
- methods:
- visibility: public
aref: M000052
name: new
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 94</span>\n 94: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-identifier\">offset</span>, <span class=\"ruby-identifier\">pos</span>=<span class=\"ruby-constant\">Noun</span>, <span class=\"ruby-identifier\">source_wn</span>=<span class=\"ruby-value\">0</span>, <span class=\"ruby-identifier\">target_wn</span>=<span class=\"ruby-value\">0</span> )\n 95: \n 96: <span class=\"ruby-comment cmt\"># Allow type = '!', 'antonym', or :antonym. Also handle</span>\n 97: <span class=\"ruby-comment cmt\"># splitting of compound pointers (e.g., :memberMeronym / '%m')</span>\n 98: <span class=\"ruby-comment cmt\"># into their correct type/subtype parts.</span>\n 99: <span class=\"ruby-ivar\">@type</span> = <span class=\"ruby-ivar\">@subtype</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
100: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">type</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">length</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">1</span>\n\
101: <span class=\"ruby-ivar\">@type</span> = <span class=\"ruby-constant\">POINTER_SYMBOLS</span>[ <span class=\"ruby-identifier\">type</span>[<span class=\"ruby-value\">0</span>,<span class=\"ruby-value\">1</span>] ]\n\
102: \n\
103: <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-identifier\">type</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">length</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">2</span>\n\
104: <span class=\"ruby-ivar\">@type</span> = <span class=\"ruby-constant\">POINTER_SYMBOLS</span>[ <span class=\"ruby-identifier\">type</span>[<span class=\"ruby-value\">0</span>,<span class=\"ruby-value\">1</span>] ]\n\
105: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-value str\">"No known subtypes for '%s'"</span> <span class=\"ruby-operator\">%</span> [<span class=\"ruby-ivar\">@type</span>] <span class=\"ruby-keyword kw\">unless</span>\n\
106: <span class=\"ruby-constant\">POINTER_SUBTYPES</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-ivar\">@type</span> )\n\
107: <span class=\"ruby-ivar\">@subtype</span> = <span class=\"ruby-constant\">POINTER_SUBTYPES</span>[ <span class=\"ruby-ivar\">@type</span> ].<span class=\"ruby-identifier\">index</span>( <span class=\"ruby-identifier\">type</span> ) <span class=\"ruby-keyword kw\">or</span>\n\
108: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-value str\">"Unknown subtype '%s' for '%s'"</span> <span class=\"ruby-operator\">%</span>\n\
109: [ <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-ivar\">@type</span> ]\n\
110: \n\
111: <span class=\"ruby-keyword kw\">else</span>\n\
112: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">POINTER_TYPES</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">type</span>.<span class=\"ruby-identifier\">to_sym</span> )\n\
113: <span class=\"ruby-ivar\">@type</span> = <span class=\"ruby-identifier\">type</span>.<span class=\"ruby-identifier\">to_sym</span>\n\
114: <span class=\"ruby-keyword kw\">elsif</span> <span class=\"ruby-regexp re\">/([a-z]+)([A-Z][a-z]+)/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">type</span>.<span class=\"ruby-identifier\">to_s</span>\n\
115: <span class=\"ruby-identifier\">subtype</span>, <span class=\"ruby-identifier\">maintype</span> = <span class=\"ruby-identifier\">$1</span>, <span class=\"ruby-identifier\">$2</span>.<span class=\"ruby-identifier\">downcase</span>\n\
116: <span class=\"ruby-ivar\">@type</span> = <span class=\"ruby-identifier\">maintype</span>.<span class=\"ruby-identifier\">to_sym</span> <span class=\"ruby-keyword kw\">if</span>\n\
117: <span class=\"ruby-constant\">POINTER_TYPES</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">maintype</span>.<span class=\"ruby-identifier\">to_sym</span> )\n\
118: <span class=\"ruby-ivar\">@subtype</span> = <span class=\"ruby-identifier\">subtype</span>.<span class=\"ruby-identifier\">to_sym</span>\n\
119: <span class=\"ruby-keyword kw\">end</span>\n\
120: <span class=\"ruby-keyword kw\">end</span>\n\
121: \n\
122: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">"No such pointer type %p"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">type</span> <span class=\"ruby-keyword kw\">if</span>\n\
123: <span class=\"ruby-ivar\">@type</span>.<span class=\"ruby-identifier\">nil?</span>\n\
124: \n\
125: <span class=\"ruby-comment cmt\"># Allow pos = 'n', 'noun', or :noun</span>\n\
126: <span class=\"ruby-ivar\">@part_of_speech</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
127: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">pos</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">length</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">1</span>\n\
128: <span class=\"ruby-ivar\">@part_of_speech</span> = <span class=\"ruby-constant\">SYNTACTIC_SYMBOLS</span>[ <span class=\"ruby-identifier\">pos</span> ]\n\
129: <span class=\"ruby-keyword kw\">else</span>\n\
130: <span class=\"ruby-ivar\">@part_of_speech</span> = <span class=\"ruby-identifier\">pos</span>.<span class=\"ruby-identifier\">to_sym</span> <span class=\"ruby-keyword kw\">if</span>\n\
131: <span class=\"ruby-constant\">SYNTACTIC_CATEGORIES</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">pos</span>.<span class=\"ruby-identifier\">to_sym</span> )\n\
132: <span class=\"ruby-keyword kw\">end</span>\n\
133: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">ArgumentError</span>, <span class=\"ruby-value str\">"No such part of speech %p"</span> <span class=\"ruby-operator\">%</span> <span class=\"ruby-identifier\">pos</span> <span class=\"ruby-keyword kw\">if</span>\n\
134: <span class=\"ruby-ivar\">@part_of_speech</span>.<span class=\"ruby-identifier\">nil?</span>\n\
135: \n\
136: <span class=\"ruby-comment cmt\"># Other attributes</span>\n\
137: <span class=\"ruby-ivar\">@offset</span> = <span class=\"ruby-identifier\">offset</span>\n\
138: <span class=\"ruby-ivar\">@source_wn</span> = <span class=\"ruby-identifier\">source_wn</span>\n\
139: <span class=\"ruby-ivar\">@target_wn</span> = <span class=\"ruby-identifier\">target_wn</span>\n\
140: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Create a new synset pointer with the given arguments. The <tt>ptrType</tt>
is the type of the link between synsets, and must be either a key or a
value of WordNet::Constants::POINTER_TYPES. The <tt>offset</tt> is the
unique identifier of the target synset, and <tt>pos</tt> is its
part-of-speech, which must be either a key or value of
WordNet::Constants::SYNTACTIC_CATEGORIES. The <tt>source_wn</tt> and
<tt>target_wn</tt> are numerical values which distinguish lexical and
semantic pointers. <tt>source_wn</tt> indicates the word number in the
current (source) synset, and <tt>target_wn</tt> 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 <tt>offset</tt>.
</p>
params: ( type, offset, pos=Noun, source_wn=0, target_wn=0 )
- visibility: public
aref: M000051
name: parse
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 70</span>\n\
70: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-keyword kw\">self</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">parse</span>( <span class=\"ruby-identifier\">pointerString</span> )\n\
71: <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-identifier\">offsetPos</span>, <span class=\"ruby-identifier\">ptrNums</span> = <span class=\"ruby-identifier\">pointerString</span>.<span class=\"ruby-identifier\">split</span>(<span class=\"ruby-regexp re\">/\\s+/</span>)\n\
72: <span class=\"ruby-identifier\">offset</span>, <span class=\"ruby-identifier\">pos</span> = <span class=\"ruby-identifier\">offsetPos</span>.<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-regexp re\">/%/</span>, <span class=\"ruby-value\">2</span> )\n\
73: <span class=\"ruby-identifier\">new</span>( <span class=\"ruby-identifier\">type</span>, <span class=\"ruby-identifier\">offset</span>, <span class=\"ruby-identifier\">pos</span>, <span class=\"ruby-identifier\">ptrNums</span>[<span class=\"ruby-value\">0</span>,<span class=\"ruby-value\">2</span>], <span class=\"ruby-identifier\">ptrNums</span>[<span class=\"ruby-value\">2</span>,<span class=\"ruby-value\">2</span>] )\n\
74: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Make an Array of <a href="Pointer.html">WordNet::Synset::Pointer</a>
objects out of the given <tt>pointerList</tt>. The pointerlist is a string
of pointers delimited by Constants::SUB_DELIM. Pointers are in the form:
</p>
<pre>
"<pointer_symbol> <synset_offset>%<pos> <source/target>"
</pre>
params: ( pointerString )
category: Class
type: Public
- methods:
- visibility: public
aref: M000057
name: ==
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 206</span>\n\
206: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-operator\">==</span>( <span class=\"ruby-identifier\">other</span> )\n\
207: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">false</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">is_a?</span>( <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span> )\n\
208: <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">&&</span>\n\
209: <span class=\"ruby-identifier\">other</span>.<span class=\"ruby-identifier\">type</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">type</span>\n\
210: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Comparison operator. <a href="Pointer.html">Pointer</a> are equivalent if
they point at the same synset and are of the same type.
</p>
params: ( other )
- visibility: public
aref: M000053
name: inspect
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 171</span>\n\
171: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">inspect</span>\n\
172: <span class=\"ruby-value str\">"#<%s:0x%08x %s %s>"</span> <span class=\"ruby-operator\">%</span> [\n\
173: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">class</span>.<span class=\"ruby-identifier\">name</span>,\n\
174: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">object_id</span>,\n\
175: <span class=\"ruby-ivar\">@subtype</span> <span class=\"ruby-operator\">?</span> <span class=\"ruby-value str\">"#@type(#@subtype)"</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-ivar\">@type</span>,\n\
176: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">synset</span>,\n\
177: ]\n\
178: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the <a href="Pointer.html">Pointer</a> as a human-readable String
suitable for debugging.
</p>
params: ()
- visibility: public
aref: M000055
name: pos
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 189</span>\n\
189: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">pos</span>\n\
190: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">SYNTACTIC_CATEGORIES</span>[ <span class=\"ruby-ivar\">@part_of_speech</span> ]\n\
191: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the syntactic category symbol for this pointer
</p>
params: ()
- visibility: public
aref: M000054
name: synset
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 183</span>\n\
183: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">synset</span>\n\
184: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">"%"</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">pos</span>\n\
185: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the synset key of the target synset (i.e., <offset>%<pos symbol>).
</p>
params: ()
- visibility: public
aref: M000058
name: to_s
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 214</span>\n\
214: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">to_s</span>\n\
215: <span class=\"ruby-value str\">"%s %d%%%s %02x%02x"</span> <span class=\"ruby-operator\">%</span> [ \n\
216: <span class=\"ruby-identifier\">ptr</span>.<span class=\"ruby-identifier\">type_symbol</span>,\n\
217: <span class=\"ruby-identifier\">ptr</span>.<span class=\"ruby-identifier\">offset</span>,\n\
218: <span class=\"ruby-identifier\">ptr</span>.<span class=\"ruby-identifier\">posSymbol</span>,\n\
219: <span class=\"ruby-identifier\">ptr</span>.<span class=\"ruby-identifier\">source_wn</span>,\n\
220: <span class=\"ruby-identifier\">ptr</span>.<span class=\"ruby-identifier\">target_wn</span>,\n\
221: ]\n\
222: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the pointer in its stringified form.
</p>
params: ()
- visibility: public
aref: M000056
name: type_symbol
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/synset.rb, line 195</span>\n\
195: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">type_symbol</span>\n\
196: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@subtype</span>\n\
197: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">POINTER_TYPES</span>[ <span class=\"ruby-ivar\">@type</span> ]\n\
198: <span class=\"ruby-keyword kw\">else</span>\n\
199: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">POINTER_SUBTYPES</span>[ <span class=\"ruby-ivar\">@type</span> ][ <span class=\"ruby-ivar\">@subtype</span> ]\n\
200: <span class=\"ruby-keyword kw\">end</span>\n\
201: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return the pointer type symbol for this pointer
</p>
params: ()
category: Instance
type: Public
---
Generated with the Darkfish Rdoc Generator.