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.2.0'
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']
	gemspec = Gem.loaded_specs['ruby-framenet']
	gem_data_dir = gemspec && gemspec.datadir
	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.



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

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.



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

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>`)



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

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.



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/frame_net.rb', line 83

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.



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

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.



100
101
102
103
104
105
106
107
108
# File 'lib/frame_net.rb', line 100

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