LexicalUnit

class
Superclass
Object
Extended With
Loggability

A Lexical Unit in FrameNet.

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

Attributes

frame_name[RW]

The name of the associated Frame

id[RW]

The LexicalUnit's id

name[RW]

The unit's name

pos[RW]

The part of speech the unit represents

status[RW]

The unit's status in FrameNet

total_annotated[RW]

The number of annotated sentences in all corpuses for this unit

Public Class Methods

anchor
from_frame_data( doc )

Extract LexicalUnits from the frame data in the specified doc (a LibXML::XML::Document parsed from frame XML) and return them as an Array.

# File lib/frame_net/frame/lexical_unit.rb, line 42
def self::from_frame_data( doc )
        return doc.find( '//fn:lexUnit' ).map do |node|
                id = node['ID']
                self.load( id )
        end
end
anchor
from_lu_document( doc )

Create a LexicalUnit from the data in the given doc (a LibXML::XML::Document parsed from lu XML)

# File lib/frame_net/frame/lexical_unit.rb, line 52
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
anchor
load( id )

Load a LexicalUnit from the XML for the lexical unit with the given id.

# File lib/frame_net/frame/lexical_unit.rb, line 22
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
anchor
load_by_name( name )

Load any LexicalUnits with the given name (in the form <word>.<pos>) and return them as an Array.

# File lib/frame_net/frame/lexical_unit.rb, line 31
def self::load_by_name( name )
        xpath = %Q{//fn:lu[@name="%s"]} % [ name ]
        index = FrameNet.lu_index
        return index.find( xpath ).map do |node|
                self.load( node['ID'] )
        end
end
anchor
new() { |self| ... }

Create a new LexicalUnit and yield it to a block if given.

# File lib/frame_net/frame/lexical_unit.rb, line 66
def initialize
        @id              = nil
        @status          = nil
        @pos             = nil
        @name            = nil
        @total_annotated = 0
        @frame_name      = nil

        @frame           = nil

        yield( self ) if block_given?
end

Public Instance Methods

anchor
frame()

Return the FrameNet::Frame associated with this lexical unit, loading it if necessary.

# File lib/frame_net/frame/lexical_unit.rb, line 112
def frame
        raise "No frame_name has been set for this unit!" unless self.frame_name
        return @frame ||= FrameNet[ self.frame_name ]
end
anchor
frame=( new_frame )

Set the FrameNet::Frame associated with this lexical unit to new_frame.

# File lib/frame_net/frame/lexical_unit.rb, line 119
def frame=( new_frame )
        self.frame_name = new_frame.name.to_sym
end
anchor
inspect()

Return the LexicalUnit as a human-readable string suitable for debugging.

# File lib/frame_net/frame/lexical_unit.rb, line 125
def inspect
        return %Q{#<%p:%#016x %s [%d] → |%s|>} % [
                self.class,
                self.object_id * 2,
                self.name,
                self.id || 0,
                self.frame_name
        ]
end