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:



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/frame_net/frame.rb', line 80

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

  yield( self ) if block_given?
end

Instance Attribute Details

#core_element_set_idsObject

The sets of FE IDs that make up the Frame’ FEcoreSets.



130
131
132
# File 'lib/frame_net/frame.rb', line 130

def core_element_set_ids
  @core_element_set_ids
end

#creation_timeObject Also known as: cDate, cDate=

The timestamp of when the node was created



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

def creation_time
  @creation_time
end

#definitionObject

The definition of the Frame.



114
115
116
# File 'lib/frame_net/frame.rb', line 114

def definition
  @definition
end

#elementsObject

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



118
119
120
# File 'lib/frame_net/frame.rb', line 118

def elements
  @elements
end

#idObject

The Frame’s ID



100
101
102
# File 'lib/frame_net/frame.rb', line 100

def id
  @id
end

#lexical_unitsObject

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



126
127
128
# File 'lib/frame_net/frame.rb', line 126

def lexical_units
  @lexical_units
end

#nameObject

The Frame’s name as a Symbol



104
105
106
# File 'lib/frame_net/frame.rb', line 104

def name
  @name
end

#relationsObject

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



122
123
124
# File 'lib/frame_net/frame.rb', line 122

def relations
  @relations
end

Class Method Details

.document_for(name) ⇒ Object

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



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

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

.load(name_or_id) ⇒ Object Also known as: []

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.



71
72
73
74
75
76
# File 'lib/frame_net/frame.rb', line 71

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.



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

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 )

    frame.core_element_set_ids = doc.find( '//fn:frame/fn:FEcoreSet' ).map do |set_el|
      set_el.find( './fn:memberFE' ).map {|el| el['ID'].to_i }
    end
  end
end

Instance Method Details

#==(other_frame) ⇒ Object Also known as: eql?

Object equality – returns true if the receiver repressents the same FrameNet frame as other_frame.



135
136
137
# File 'lib/frame_net/frame.rb', line 135

def ==( other_frame )
  return other_frame.is_a?( self.class ) && self.id == other_frame.id
end

#core_element_setsObject

Return the Frame’s core element sets (FEcoreSets) as an Array of FrameNet::Frame::Elements.



175
176
177
178
179
180
# File 'lib/frame_net/frame.rb', line 175

def core_element_sets
  elements = self.elements_by_id
  return self.core_element_set_ids.map do |id_set|
    id_set.map {|id| elements[id] }
  end
end

#documentObject

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



286
287
288
# File 'lib/frame_net/frame.rb', line 286

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

#elements_by_core_typeObject

Return a Hash of this Frame’s FEs grouped by core type.



168
169
170
# File 'lib/frame_net/frame.rb', line 168

def elements_by_core_type
  return self.elements.group_by( &:core_type )
end

#elements_by_idObject

Return the Hash of this Frame’s FEs keyed by numeric ID.



160
161
162
163
164
# File 'lib/frame_net/frame.rb', line 160

def elements_by_id
  return self.elements.each_with_object( {} ) do |el, hash|
    hash[ el.id ] = el
  end
end

#has_subframesObject Also known as: has_subframe

Return Frames which are a subframe of the receiver.



240
241
242
# File 'lib/frame_net/frame.rb', line 240

def has_subframes
  return self.relations_hash[ "Has Subframe(s)" ].frames
end

#inherits_fromObject

Return Frames the receiver inherits from.



197
198
199
# File 'lib/frame_net/frame.rb', line 197

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

#inspectObject

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



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/frame_net/frame.rb', line 142

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

#is_causative_ofObject

Return Frames in which the receiving frame is a causative subframe.



267
268
269
# File 'lib/frame_net/frame.rb', line 267

def is_causative_of
  return self.relations_hash[ "Is Causative of" ].frames
end

#is_inchoative_ofObject

Return Frames in which the receiving frame is an inchoative subframe.



261
262
263
# File 'lib/frame_net/frame.rb', line 261

def is_inchoative_of
  return self.relations_hash[ "Is Inchoative of" ].frames
end

#is_inherited_byObject

Return Frames the receiver is inherited by.



203
204
205
# File 'lib/frame_net/frame.rb', line 203

def is_inherited_by
  return self.relations_hash[ "Is Inherited by" ].frames
end

#is_perspectivized_inObject

Return Frames which represent different states of affairs of the receiving Frame.



216
217
218
# File 'lib/frame_net/frame.rb', line 216

def is_perspectivized_in
  return self.relations_hash[ "Is Perspectivized in" ].frames
end

#is_preceded_byObject

Return Frames the receiver comes after in a series of subframes of another Frame.



255
256
257
# File 'lib/frame_net/frame.rb', line 255

def is_preceded_by
  return self.relations_hash[ "Is Preceded by" ].frames
end

#is_used_byObject

Return Frames the receiver is used by.



228
229
230
# File 'lib/frame_net/frame.rb', line 228

def is_used_by
  return self.relations_hash[ "Is Used by" ].frames
end

#perspective_onObject

Return Frames in which the receiver is one of several perspectives.



209
210
211
# File 'lib/frame_net/frame.rb', line 209

def perspective_on
  return self.relations_hash[ "Perspective on" ].frames
end

#precedesObject

Return Frames the receiver comes before in a series of subframes of another Frame.



248
249
250
# File 'lib/frame_net/frame.rb', line 248

def precedes
  return self.relations_hash[ "Precedes" ].frames
end

#relations_hashObject

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



189
190
191
192
193
# File 'lib/frame_net/frame.rb', line 189

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

#see_alsoObject

Return the other members of a group of Frames which should be compared to the receiving Frame.



274
275
276
# File 'lib/frame_net/frame.rb', line 274

def see_also
  return self.relations_hash[ "See also" ].frames
end

#subframe_ofObject

Return Frames the receiver is a subframe of.



234
235
236
# File 'lib/frame_net/frame.rb', line 234

def subframe_of
  return self.relations_hash[ "Subframe of" ].frames
end

#usesObject

Return Frames the receiver uses in some capacity.



222
223
224
# File 'lib/frame_net/frame.rb', line 222

def uses
  return self.relations_hash[ "Uses" ].frames
end