Frame

class
Superclass
Object
Extended With
Loggability

A Frame in FrameNet.

References: - framenet.icsi.berkeley.edu/fndrupal/glossary#frame

Attributes

cDate[RW]

The timestamp of when the node was created

cDate=[RW]

The timestamp of when the node was created

creation_time[RW]

The timestamp of when the node was created

definition[RW]

The definition of the Frame.

elements[RW]

The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.

id[RW]

The Frame's ID

lexical_units[RW]

The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.

name[RW]

The Frame's name as a Symbol

relations[RW]

The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.

Public Class Methods

anchor
document_for( name )

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
anchor
load( name_or_id )

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
anchor
load_by_id( id )

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
anchor
load_by_name( name )

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
anchor
new() { |self| ... }

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

Public Instance Methods

anchor
document()

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
anchor
inherits_from()

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
anchor
inspect()

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
anchor
relations_hash()

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