module FrameNet
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
Look up a frame by name_or_id
and return it as a FrameNet::Frame
.
# File lib/frame_net.rb, line 56 def self::[]( name_or_id ) return FrameNet::Frame.load( name_or_id ) end
Return the FrameNet
frameIndex data as an LibXML::XML::Document
.
# File lib/frame_net.rb, line 69 def self::frame_index return @frame_index ||= self.load_document( 'frameIndex.xml' ) end
Return an Array of FrameNet::Frame::LexicalUnits for the given name
(which is of the form: `<morph>.<pos>`)
# File lib/frame_net.rb, line 63 def self::lexical_unit( name ) return FrameNet::Frame::LexicalUnit.load_by_name( name ) end
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 82 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
Return the FrameNet
lexical unit index data as an LibXML::XML::Document
.
# File lib/frame_net.rb, line 75 def self::lu_index return @lu_index ||= self.load_document( 'luIndex.xml' ) end
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 99 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