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
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
-
#document ⇒ Object
Return the XML document that contains the data for the frame (if one exists).
-
#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.
-
#relations_hash ⇒ Object
Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation’s type as a String.
Constructor Details
#initialize {|_self| ... } ⇒ Frame
Create a new Frame with the specified id, name, and modification_date.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/frame_net/frame.rb', line 75 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
102 103 104 |
# File 'lib/frame_net/frame.rb', line 102 def creation_time @creation_time end |
#definition ⇒ Object
The definition of the Frame.
108 109 110 |
# File 'lib/frame_net/frame.rb', line 108 def definition @definition end |
#elements ⇒ Object
The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.
112 113 114 |
# File 'lib/frame_net/frame.rb', line 112 def elements @elements end |
#id ⇒ Object
The Frame’s ID
94 95 96 |
# File 'lib/frame_net/frame.rb', line 94 def id @id end |
#lexical_units ⇒ Object
The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.
120 121 122 |
# File 'lib/frame_net/frame.rb', line 120 def lexical_units @lexical_units end |
#name ⇒ Object
The Frame’s name as a Symbol
98 99 100 |
# File 'lib/frame_net/frame.rb', line 98 def name @name end |
#relations ⇒ Object
The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.
116 117 118 |
# File 'lib/frame_net/frame.rb', line 116 def relations @relations end |
Class Method Details
.document_for(name) ⇒ Object
Return a LibXML::XML::Document for the data for the frame named name.
40 41 42 43 |
# File 'lib/frame_net/frame.rb', line 40 def self::document_for( name ) path = "frame/%s.xml" % [ name.to_s.capitalize ] return FrameNet.load_document( path ) end |
.load(name_or_id) ⇒ Object
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.
66 67 68 69 70 71 |
# File 'lib/frame_net/frame.rb', line 66 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/frame_net/frame.rb', line 47 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
#document ⇒ Object
Return the XML document that contains the data for the frame (if one exists). Returns nil if the document doesn’t exist.
154 155 156 |
# File 'lib/frame_net/frame.rb', line 154 def document return self.class.document_for( self.name ) end |
#inherits_from ⇒ Object
Return Frames the receiver inherits from.
147 148 149 |
# File 'lib/frame_net/frame.rb', line 147 def inherits_from return self.relations_hash[ "Inherits from" ].frames end |
#inspect ⇒ Object
Return the Frame as a human-readable string suitable for debugging.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/frame_net/frame.rb', line 124 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 |
#relations_hash ⇒ Object
Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation’s type as a String.
139 140 141 142 143 |
# File 'lib/frame_net/frame.rb', line 139 def relations_hash return self.relations.each_with_object( {} ) do |rel, hash| hash[ rel.type ] = rel end end |