Module: FrameNet

Extended by:
Loggability
Defined in:
lib/frame_net.rb

Overview

A Ruby interface to FrameNet

Defined Under Namespace

Classes: Definition, Frame, SemanticType

Constant Summary collapse

VERSION =

Package version

'0.0.2'
REVISION =

Version control revision

%q$Revision: ecb01eee279b $
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

begin
	env_data_dir = ENV['FRAME_NET_DATA_DIR']
	gem_data_dir = Gem.datadir('ruby-framenet')
	local_data_dir = Pathname( __FILE__ ).dirname.parent + 'data/ruby-framenet'

	if env_data_dir && File.directory?( env_data_dir )
		Pathname( env_data_dir )
	elsif gem_data_dir && File.directory?( gem_data_dir )
		Pathname( gem_data_dir )
	else
		local_data_dir
	end
end
TIME_FORMAT =

The strptime format of times used in FrameNet data

'%m/%d/%Y %H:%M:%S %Z %a'

Class Method Summary collapse

Class Method Details

.[](name_or_id) ⇒ Object

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



56
57
58
# File 'lib/frame_net.rb', line 56

def self::[]( name_or_id )
	return FrameNet::Frame.load( name_or_id )
end

.frame_indexObject

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



69
70
71
# File 'lib/frame_net.rb', line 69

def self::frame_index
	return @frame_index ||= self.load_document( 'frameIndex.xml' )
end

.lexical_unit(name) ⇒ Object

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



63
64
65
# File 'lib/frame_net.rb', line 63

def self::lexical_unit( name )
	return FrameNet::Frame::LexicalUnit.load_by_name( name )
end

.load_document(path) ⇒ Object

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.



82
83
84
85
86
87
88
89
90
91
92
93
# 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

.lu_indexObject

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



75
76
77
# File 'lib/frame_net.rb', line 75

def self::lu_index
	return @lu_index ||= self.load_document( 'luIndex.xml' )
end

.parse_time(string_time) ⇒ Object

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.



99
100
101
102
103
104
105
106
107
# 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