References: - framenet.icsi.berkeley.edu/fndrupal/glossary#frame
The timestamp of when the node was created
The timestamp of when the node was created
The timestamp of when the node was created
The definition of the Frame.
The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.
The Frame's ID
The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.
The Frame's name as a Symbol
The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.
Return a LibXML::XML::Document
for the data for the frame named name
.
# File lib/frame_net/frame.rb, line 39
def self::document_for( name )
path = "frame/%s.xml" % [ name.to_s.capitalize ]
return FrameNet.load_document( path )
end
Load the frame by name_or_id
.
# File lib/frame_net/frame.rb, line 26
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
Look up a Frame by its Integer id
.
# File lib/frame_net/frame.rb, line 65
def self::load_by_id( id )
self.log.debug "Loading frame for ID=%p" % [ id ]
xpath = %Q{//fn:frame[@ID=%d]} % [ id ]
node = FrameNet.frame_index.find_first( xpath ) or return nil
return self.load_by_name( node['name'] )
end
Load a Frame from the frame XML for the given
name
.
# File lib/frame_net/frame.rb, line 46
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
Create a new Frame with the specified
id
, name
, and modification_date
.
# File lib/frame_net/frame.rb, line 74
def initialize
@id = nil
@name = nil
@creation_time = Time.now
@definition = nil
@elements = []
@relations = []
@lexical_units = []
yield( self ) if block_given?
end
Return the XML document that contains the data for the frame (if one
exists). Returns nil
if the document doesn't exist.
# File lib/frame_net/frame.rb, line 153
def document
return self.class.document_for( self.name )
end
Return Frames the receiver inherits from.
# File lib/frame_net/frame.rb, line 146
def inherits_from
return self.relations_hash[ "Inherits from" ].frames
end
Return the Frame as a human-readable string suitable for debugging.
# File lib/frame_net/frame.rb, line 123
def inspect
return %Q{#<%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
Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation's type as a String.
# File lib/frame_net/frame.rb, line 138
def relations_hash
return self.relations.each_with_object( {} ) do |rel, hash|
hash[ rel.type ] = rel
end
end