Class: FrameNet::Frame::LexicalUnit
- Inherits:
-
Object
- Object
- FrameNet::Frame::LexicalUnit
- Extended by:
- Loggability
- Defined in:
- lib/frame_net/frame/lexical_unit.rb
Overview
Instance Attribute Summary collapse
-
#frame_name ⇒ Object
The name of the associated Frame.
-
#id ⇒ Object
The LexicalUnit’s id.
-
#name ⇒ Object
The unit’s name.
-
#pos ⇒ Object
The part of speech the unit represents.
-
#status ⇒ Object
The unit’s status in FrameNet.
-
#total_annotated ⇒ Object
The number of annotated sentences in all corpuses for this unit.
Class Method Summary collapse
-
.from_frame_data(doc) ⇒ Object
Extract LexicalUnits from the frame data in the specified
doc(a LibXML::XML::Document parsed from frame XML) and return them as an Array. -
.from_lu_document(doc) ⇒ Object
Create a LexicalUnit from the data in the given
doc(a LibXML::XML::Document parsed from lu XML). -
.load(id) ⇒ Object
Load a LexicalUnit from the XML for the lexical unit with the given
id. -
.load_by_name(name) ⇒ Object
Load any LexicalUnits with the given
name(in the form <word>.<pos>) and return them as an Array.
Instance Method Summary collapse
-
#frame ⇒ Object
Return the FrameNet::Frame associated with this lexical unit, loading it if necessary.
-
#frame=(new_frame) ⇒ Object
Set the FrameNet::Frame associated with this lexical unit to
new_frame. -
#initialize {|_self| ... } ⇒ LexicalUnit
constructor
Create a new LexicalUnit and yield it to a block if given.
-
#inspect ⇒ Object
Return the LexicalUnit as a human-readable string suitable for debugging.
Constructor Details
#initialize {|_self| ... } ⇒ LexicalUnit
Create a new LexicalUnit and yield it to a block if given.
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 67 def initialize @id = nil @status = nil @pos = nil @name = nil @total_annotated = 0 @frame_name = nil @frame = nil yield( self ) if block_given? end |
Instance Attribute Details
#frame_name ⇒ Object
The name of the associated Frame
107 108 109 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 107 def frame_name @frame_name end |
#id ⇒ Object
The LexicalUnit’s id
87 88 89 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 87 def id @id end |
#name ⇒ Object
The unit’s name
99 100 101 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 99 def name @name end |
#pos ⇒ Object
The part of speech the unit represents
95 96 97 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 95 def pos @pos end |
#status ⇒ Object
The unit’s status in FrameNet
91 92 93 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 91 def status @status end |
#total_annotated ⇒ Object
The number of annotated sentences in all corpuses for this unit
103 104 105 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 103 def total_annotated @total_annotated end |
Class Method Details
.from_frame_data(doc) ⇒ Object
Extract LexicalUnits from the frame data in the specified doc (a LibXML::XML::Document parsed from frame XML) and return them as an Array.
43 44 45 46 47 48 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 43 def self::from_frame_data( doc ) return doc.find( '//fn:lexUnit' ).map do |node| id = node['ID'] self.load( id ) end end |
.from_lu_document(doc) ⇒ Object
Create a LexicalUnit from the data in the given doc (a LibXML::XML::Document parsed from lu XML)
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 53 def self::from_lu_document( doc ) return new do |lu| lu.id = doc.root['ID'].to_i lu.status = doc.root['Status'] lu.pos = doc.root['POS'] lu.name = doc.root['name'] lu.total_annotated = doc.root['totalAnnotated'].to_i lu.frame_name = doc.root['frame'].to_sym end end |
.load(id) ⇒ Object
Load a LexicalUnit from the XML for the lexical unit with the given id.
23 24 25 26 27 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 23 def self::load( id ) path = "lu/lu%d.xml" % [ id.to_i ] doc = FrameNet.load_document( path ) or return nil return self.from_lu_document( doc ) end |
.load_by_name(name) ⇒ Object
Load any LexicalUnits with the given name (in the form <word>.<pos>) and return them as an Array.
32 33 34 35 36 37 38 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 32 def self::load_by_name( name ) xpath = %{//fn:lu[@name="%s"]} % [ name ] index = FrameNet.lu_index return index.find( xpath ).map do |node| self.load( node['ID'] ) end end |
Instance Method Details
#frame ⇒ Object
Return the FrameNet::Frame associated with this lexical unit, loading it if necessary.
113 114 115 116 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 113 def frame raise "No frame_name has been set for this unit!" unless self.frame_name return @frame ||= FrameNet[ self.frame_name ] end |
#frame=(new_frame) ⇒ Object
Set the FrameNet::Frame associated with this lexical unit to new_frame.
120 121 122 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 120 def frame=( new_frame ) self.frame_name = new_frame.name.to_sym end |
#inspect ⇒ Object
Return the LexicalUnit as a human-readable string suitable for debugging.
126 127 128 129 130 131 132 133 134 |
# File 'lib/frame_net/frame/lexical_unit.rb', line 126 def inspect return %{#<%p:%#016x %s [%d] → |%s|>} % [ self.class, self.object_id * 2, self.name, self.id || 0, self.frame_name ] end |