Class: FrameNet::Frame
- Inherits:
-
Object
- Object
- FrameNet::Frame
- Extended by:
- Loggability
- Defined in:
- lib/frame_net/frame.rb
Overview
Defined Under Namespace
Classes: Element, LexicalUnit, Relation
Instance Attribute Summary collapse
-
#creation_time ⇒ Object
(also: #cDate, #cDate=)
The timestamp of when the node was created.
-
#definition ⇒ Object
The definition of the Frame.
-
#elements ⇒ Object
The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.
-
#id ⇒ Object
The Frame’s ID.
-
#lexical_units ⇒ Object
The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.
-
#name ⇒ Object
The Frame’s name as a Symbol.
-
#relations ⇒ Object
The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.
Class Method Summary collapse
-
.document_for(name) ⇒ Object
Return a LibXML::XML::Document for the data for the frame named
name. -
.load(name_or_id) ⇒ Object
(also: [])
Load the frame by
name_or_id. -
.load_by_id(id) ⇒ Object
Look up a Frame by its Integer
id. -
.load_by_name(name) ⇒ Object
Load a Frame from the frame XML for the given
name.
Instance Method Summary collapse
-
#==(other_frame) ⇒ Object
(also: #eql?)
Object equality – returns
trueif the receiver repressents the same FrameNet frame asother_frame. -
#document ⇒ Object
Return the XML document that contains the data for the frame (if one exists).
-
#elements_by_core_type ⇒ Object
Return a Hash of this Frame’s FEs grouped by core type.
-
#elements_by_id ⇒ Object
Return the Hash of this Frame’s FEs keyed by numeric ID.
-
#has_subframes ⇒ Object
(also: #has_subframe)
Return Frames which are a subframe of the receiver.
-
#inherits_from ⇒ Object
Return Frames the receiver inherits from.
-
#initialize {|_self| ... } ⇒ Frame
constructor
Create a new Frame with the specified
id,name, andmodification_date. -
#inspect ⇒ Object
Return the Frame as a human-readable string suitable for debugging.
-
#is_causative_of ⇒ Object
Return Frames in which the receiving frame is a causative subframe.
-
#is_inchoative_of ⇒ Object
Return Frames in which the receiving frame is an inchoative subframe.
-
#is_inherited_by ⇒ Object
Return Frames the receiver is inherited by.
-
#is_perspectivized_in ⇒ Object
Return Frames which represent different states of affairs of the receiving Frame.
-
#is_preceded_by ⇒ Object
Return Frames the receiver comes after in a series of subframes of another Frame.
-
#is_used_by ⇒ Object
Return Frames the receiver is used by.
-
#perspective_on ⇒ Object
Return Frames in which the receiver is one of several perspectives.
-
#precedes ⇒ Object
Return Frames the receiver comes before in a series of subframes of another Frame.
-
#relations_hash ⇒ Object
Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation’s type as a String.
-
#see_also ⇒ Object
Return the other members of a group of Frames which should be compared to the receiving Frame.
-
#subframe_of ⇒ Object
Return Frames the receiver is a subframe of.
-
#uses ⇒ Object
Return Frames the receiver uses in some capacity.
Constructor Details
#initialize {|_self| ... } ⇒ Frame
Create a new Frame with the specified id, name, and modification_date.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/frame_net/frame.rb', line 76 def initialize @id = nil @name = nil @creation_time = Time.now @definition = nil @elements = [] @relations = [] @lexical_units = [] yield( self ) if block_given? end |
Instance Attribute Details
#creation_time ⇒ Object Also known as: cDate, cDate=
The timestamp of when the node was created
103 104 105 |
# File 'lib/frame_net/frame.rb', line 103 def creation_time @creation_time end |
#definition ⇒ Object
The definition of the Frame.
109 110 111 |
# File 'lib/frame_net/frame.rb', line 109 def definition @definition end |
#elements ⇒ Object
The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.
113 114 115 |
# File 'lib/frame_net/frame.rb', line 113 def elements @elements end |
#id ⇒ Object
The Frame’s ID
95 96 97 |
# File 'lib/frame_net/frame.rb', line 95 def id @id end |
#lexical_units ⇒ Object
The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.
121 122 123 |
# File 'lib/frame_net/frame.rb', line 121 def lexical_units @lexical_units end |
#name ⇒ Object
The Frame’s name as a Symbol
99 100 101 |
# File 'lib/frame_net/frame.rb', line 99 def name @name end |
#relations ⇒ Object
The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.
117 118 119 |
# File 'lib/frame_net/frame.rb', line 117 def relations @relations end |
Class Method Details
.document_for(name) ⇒ Object
Return a LibXML::XML::Document for the data for the frame named name.
41 42 43 44 |
# File 'lib/frame_net/frame.rb', line 41 def self::document_for( name ) path = "frame/%s.xml" % [ name.to_s.capitalize ] return FrameNet.load_document( path ) end |
.load(name_or_id) ⇒ Object Also known as: []
Load the frame by name_or_id.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/frame_net/frame.rb', line 27 def self::load( name_or_id ) case name_or_id when Numeric return FrameNet::Frame.load_by_id( name_or_id ) when Symbol, String return FrameNet::Frame.load_by_name( name_or_id ) else raise ArgumentError, "don't know how to load a frame from a %p" % [ name_or_id.class ] end end |
.load_by_id(id) ⇒ Object
Look up a Frame by its Integer id.
67 68 69 70 71 72 |
# File 'lib/frame_net/frame.rb', line 67 def self::load_by_id( id ) self.log.debug "Loading frame for ID=%p" % [ id ] xpath = %{//fn:frame[@ID=%d]} % [ id ] node = FrameNet.frame_index.find_first( xpath ) or return nil return self.load_by_name( node['name'] ) end |
.load_by_name(name) ⇒ Object
Load a Frame from the frame XML for the given name.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/frame_net/frame.rb', line 48 def self::load_by_name( name ) self.log.debug "Loading frame named %p" % [ name ] doc = self.document_for( name ) or raise ArgumentError, "No such frame %p!" % [ name ] return new do |frame| frame.id = Integer( doc.root['ID'] ) frame.name = doc.root['name'].to_sym frame.creation_time = FrameNet.parse_time( doc.root['cDate'] ) frame.definition = FrameNet::Definition.from_frame_data( doc ) frame.elements = FrameNet::Frame::Element.from_frame_data( doc ) frame.relations = FrameNet::Frame::Relation.from_frame_data( doc ) frame.lexical_units = FrameNet::Frame::LexicalUnit.from_frame_data( doc ) end end |
Instance Method Details
#==(other_frame) ⇒ Object Also known as: eql?
Object equality – returns true if the receiver repressents the same FrameNet frame as other_frame.
126 127 128 |
# File 'lib/frame_net/frame.rb', line 126 def ==( other_frame ) return other_frame.is_a?( self.class ) && self.id == other_frame.id end |
#document ⇒ Object
Return the XML document that contains the data for the frame (if one exists). Returns nil if the document doesn’t exist.
267 268 269 |
# File 'lib/frame_net/frame.rb', line 267 def document return self.class.document_for( self.name ) end |
#elements_by_core_type ⇒ Object
Return a Hash of this Frame’s FEs grouped by core type.
159 160 161 |
# File 'lib/frame_net/frame.rb', line 159 def elements_by_core_type return self.elements.group_by( &:core_type ) end |
#elements_by_id ⇒ Object
Return the Hash of this Frame’s FEs keyed by numeric ID.
151 152 153 154 155 |
# File 'lib/frame_net/frame.rb', line 151 def elements_by_id return self.elements.each_with_object( {} ) do |el, hash| hash[ el.id ] = el end end |
#has_subframes ⇒ Object Also known as: has_subframe
Return Frames which are a subframe of the receiver.
221 222 223 |
# File 'lib/frame_net/frame.rb', line 221 def has_subframes return self.relations_hash[ "Has Subframe(s)" ].frames end |
#inherits_from ⇒ Object
Return Frames the receiver inherits from.
178 179 180 |
# File 'lib/frame_net/frame.rb', line 178 def inherits_from return self.relations_hash[ "Inherits from" ].frames end |
#inspect ⇒ Object
Return the Frame as a human-readable string suitable for debugging.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/frame_net/frame.rb', line 133 def inspect return %{#<%p:%#016x "%s" [%d] %d elements, %d relations, %d lexical units>} % [ self.class, self.object_id * 2, self.name || "(Unnamed)", self.id || 0, self.elements.length, self.relations.count {|rel| !rel.empty? }, self.lexical_units.length, ] end |
#is_causative_of ⇒ Object
Return Frames in which the receiving frame is a causative subframe.
248 249 250 |
# File 'lib/frame_net/frame.rb', line 248 def is_causative_of return self.relations_hash[ "Is Causative of" ].frames end |
#is_inchoative_of ⇒ Object
Return Frames in which the receiving frame is an inchoative subframe.
242 243 244 |
# File 'lib/frame_net/frame.rb', line 242 def is_inchoative_of return self.relations_hash[ "Is Inchoative of" ].frames end |
#is_inherited_by ⇒ Object
Return Frames the receiver is inherited by.
184 185 186 |
# File 'lib/frame_net/frame.rb', line 184 def is_inherited_by return self.relations_hash[ "Is Inherited by" ].frames end |
#is_perspectivized_in ⇒ Object
Return Frames which represent different states of affairs of the receiving Frame.
197 198 199 |
# File 'lib/frame_net/frame.rb', line 197 def is_perspectivized_in return self.relations_hash[ "Is Perspectivized in" ].frames end |
#is_preceded_by ⇒ Object
Return Frames the receiver comes after in a series of subframes of another Frame.
236 237 238 |
# File 'lib/frame_net/frame.rb', line 236 def is_preceded_by return self.relations_hash[ "Is Preceded by" ].frames end |
#is_used_by ⇒ Object
Return Frames the receiver is used by.
209 210 211 |
# File 'lib/frame_net/frame.rb', line 209 def is_used_by return self.relations_hash[ "Is Used by" ].frames end |
#perspective_on ⇒ Object
Return Frames in which the receiver is one of several perspectives.
190 191 192 |
# File 'lib/frame_net/frame.rb', line 190 def perspective_on return self.relations_hash[ "Perspective on" ].frames end |
#precedes ⇒ Object
Return Frames the receiver comes before in a series of subframes of another Frame.
229 230 231 |
# File 'lib/frame_net/frame.rb', line 229 def precedes return self.relations_hash[ "Precedes" ].frames end |
#relations_hash ⇒ Object
Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation’s type as a String.
170 171 172 173 174 |
# File 'lib/frame_net/frame.rb', line 170 def relations_hash return self.relations.each_with_object( {} ) do |rel, hash| hash[ rel.type ] = rel end end |
#see_also ⇒ Object
Return the other members of a group of Frames which should be compared to the receiving Frame.
255 256 257 |
# File 'lib/frame_net/frame.rb', line 255 def see_also return self.relations_hash[ "See also" ].frames end |
#subframe_of ⇒ Object
Return Frames the receiver is a subframe of.
215 216 217 |
# File 'lib/frame_net/frame.rb', line 215 def subframe_of return self.relations_hash[ "Subframe of" ].frames end |
#uses ⇒ Object
Return Frames the receiver uses in some capacity.
203 204 205 |
# File 'lib/frame_net/frame.rb', line 203 def uses return self.relations_hash[ "Uses" ].frames end |