Class: FrameNet::Frame

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Defined in:
lib/frame_net/frame.rb

Overview

A Frame in FrameNet.

References:

Defined Under Namespace

Classes: Element, LexicalUnit, Relation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Frame

Create a new Frame with the specified id, name, and modification_date.

Yields:

  • (_self)

Yield Parameters:



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/frame_net/frame.rb', line 75

def initialize
	@id            = nil
	@name          = nil
	@creation_time = Time.now
	@definition    = nil
	@elements      = []
	@relations     = []
	@lexical_units = []

	yield( self ) if block_given?
end

Instance Attribute Details

#creation_timeObject Also known as: cDate, cDate=

The timestamp of when the node was created



102
103
104
# File 'lib/frame_net/frame.rb', line 102

def creation_time
  @creation_time
end

#definitionObject

The definition of the Frame.



108
109
110
# File 'lib/frame_net/frame.rb', line 108

def definition
  @definition
end

#elementsObject

The frame elements associated with the Frame, as an Array of FrameNet::Frame::Elements.



112
113
114
# File 'lib/frame_net/frame.rb', line 112

def elements
  @elements
end

#idObject

The Frame’s ID



94
95
96
# File 'lib/frame_net/frame.rb', line 94

def id
  @id
end

#lexical_unitsObject

The “lexical units” associated with the frame, as an Array of FrameNet::LexUnits.



120
121
122
# File 'lib/frame_net/frame.rb', line 120

def lexical_units
  @lexical_units
end

#nameObject

The Frame’s name as a Symbol



98
99
100
# File 'lib/frame_net/frame.rb', line 98

def name
  @name
end

#relationsObject

The frame relations associated with the Frame, as an Array of FrameNet::Frame::Relations.



116
117
118
# File 'lib/frame_net/frame.rb', line 116

def relations
  @relations
end

Class Method Details

.document_for(name) ⇒ Object

Return a LibXML::XML::Document for the data for the frame named name.



40
41
42
43
# File 'lib/frame_net/frame.rb', line 40

def self::document_for( name )
	path = "frame/%s.xml" % [ name.to_s.capitalize ]
	return FrameNet.load_document( path )
end

.load(name_or_id) ⇒ Object

Load the frame by name_or_id.



27
28
29
30
31
32
33
34
35
36
# File 'lib/frame_net/frame.rb', line 27

def self::load( name_or_id )
	case name_or_id
	when Numeric
		return FrameNet::Frame.load_by_id( name_or_id )
	when Symbol, String
		return FrameNet::Frame.load_by_name( name_or_id )
	else
		raise ArgumentError, "don't know how to load a frame from a %p" % [ name_or_id.class ]
	end
end

.load_by_id(id) ⇒ Object

Look up a Frame by its Integer id.



66
67
68
69
70
71
# File 'lib/frame_net/frame.rb', line 66

def self::load_by_id( id )
	self.log.debug "Loading frame for ID=%p" % [ id ]
	xpath = %{//fn:frame[@ID=%d]} % [ id ]
	node = FrameNet.frame_index.find_first( xpath ) or return nil
	return self.load_by_name( node['name'] )
end

.load_by_name(name) ⇒ Object

Load a Frame from the frame XML for the given name.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/frame_net/frame.rb', line 47

def self::load_by_name( name )
	self.log.debug "Loading frame named %p" % [ name ]

	doc = self.document_for( name ) or
		raise ArgumentError, "No such frame %p!" % [ name ]

	return new do |frame|
		frame.id = Integer( doc.root['ID'] )
		frame.name = doc.root['name'].to_sym
		frame.creation_time = FrameNet.parse_time( doc.root['cDate'] )
		frame.definition = FrameNet::Definition.from_frame_data( doc )
		frame.elements = FrameNet::Frame::Element.from_frame_data( doc )
		frame.relations = FrameNet::Frame::Relation.from_frame_data( doc )
		frame.lexical_units = FrameNet::Frame::LexicalUnit.from_frame_data( doc )
	end
end

Instance Method Details

#documentObject

Return the XML document that contains the data for the frame (if one exists). Returns nil if the document doesn’t exist.



154
155
156
# File 'lib/frame_net/frame.rb', line 154

def document
	return self.class.document_for( self.name )
end

#inherits_fromObject

Return Frames the receiver inherits from.



147
148
149
# File 'lib/frame_net/frame.rb', line 147

def inherits_from
	return self.relations_hash[ "Inherits from" ].frames
end

#inspectObject

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



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/frame_net/frame.rb', line 124

def inspect
	return %{#<%p:%#016x "%s" [%d] %d elements, %d relations, %d lexical units>} % [
		self.class,
		self.object_id * 2,
		self.name || "(Unnamed)",
		self.id || 0,
		self.elements.length,
		self.relations.count {|rel| !rel.empty? },
		self.lexical_units.length,
	]
end

#relations_hashObject

Return the FrameNet::Frame::Relations this Frame has as a Hash keyed by the Relation’s type as a String.



139
140
141
142
143
# File 'lib/frame_net/frame.rb', line 139

def relations_hash
	return self.relations.each_with_object( {} ) do |rel, hash|
		hash[ rel.type ] = rel
	end
end