FrameNet

module
Extended With
Loggability

A Ruby interface to FrameNet

Constants

DATA_DIR

The Pathname for the library's data directory, taken from the FRAME_NET_DATA_DIR env variable first, then the datadir for the ruby-framenet gem if it is available, then falling back to a local path

REVISION

Version control revision

TIME_FORMAT

The strptime format of times used in FrameNet data

VERSION

Package version

Public Class Methods

anchor
[]( name_or_id )

Look up a frame by name_or_id and return it as a FrameNet::Frame.

# File lib/frame_net.rb, line 55
def self::[]( name_or_id )
        return FrameNet::Frame.load( name_or_id )
end
anchor
frame_index()

Return the FrameNet frameIndex data as an LibXML::XML::Document.

# File lib/frame_net.rb, line 68
def self::frame_index
        return @frame_index ||= self.load_document( 'frameIndex.xml' )
end
anchor
lexical_unit( name )

Return an Array of FrameNet::Frame::LexicalUnits for the given name (which is of the form: <morph>.<pos>)

# File lib/frame_net.rb, line 62
def self::lexical_unit( name )
        return FrameNet::Frame::LexicalUnit.load_by_name( name )
end
anchor
load_document( path )

Load the document with the specified path as an LibXML::XML::Document. If the path is relative, assume it's relative to the current DATA_DIR.

# File lib/frame_net.rb, line 81
def self::load_document( path )
        path = Pathname( path )
        path = DATA_DIR + path if path.relative?

        self.log.debug "Load document: %s" % [ path ]
        return nil unless path.readable?

        doc = LibXML::XML::Document.file( path.to_path )
        doc.root.namespaces.default_prefix = 'fn'

        return doc
end
anchor
lu_index()

Return the FrameNet lexical unit index data as an LibXML::XML::Document.

# File lib/frame_net.rb, line 74
def self::lu_index
        return @lu_index ||= self.load_document( 'luIndex.xml' )
end
anchor
parse_time( string_time )

Attempt to parse the given string_time to a Time, using the format of times in FrameNet data first, then falling back to Time.parse if that fails. If Time.parse fails, its exception is not rescued.

# File lib/frame_net.rb, line 98
def self::parse_time( string_time )
        begin
                return Time.strptime( string_time, FrameNet::TIME_FORMAT )
        rescue ArgumentError
        end

        # Let the ArgumentError bubble up
        return Time.parse( string_time )
end