Class: FrameNet::Frame::LexicalUnit

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

Overview

A Lexical Unit in FrameNet.

References:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new LexicalUnit and yield it to a block if given.

Yields:

  • (_self)

Yield Parameters:



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/frame_net/frame/lexical_unit.rb', line 66

def initialize
	@id              = nil
	@status          = nil
	@pos             = nil
	@name            = nil
	@total_annotated = 0
	@frame_name      = nil

	@frame           = nil

	yield( self ) if block_given?
end

Instance Attribute Details

#frame_nameObject

The name of the associated Frame



106
107
108
# File 'lib/frame_net/frame/lexical_unit.rb', line 106

def frame_name
  @frame_name
end

#idObject

The LexicalUnit’s id



86
87
88
# File 'lib/frame_net/frame/lexical_unit.rb', line 86

def id
  @id
end

#nameObject

The unit’s name



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

def name
  @name
end

#posObject

The part of speech the unit represents



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

def pos
  @pos
end

#statusObject

The unit’s status in FrameNet



90
91
92
# File 'lib/frame_net/frame/lexical_unit.rb', line 90

def status
  @status
end

#total_annotatedObject

The number of annotated sentences in all corpuses for this unit



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

def total_annotated
  @total_annotated
end

Class Method Details

.from_frame_data(doc) ⇒ Object

Extract LexicalUnits from the frame data in the specified doc (a LibXML::XML::Document parsed from frame XML) and return them as an Array.



42
43
44
45
46
47
# File 'lib/frame_net/frame/lexical_unit.rb', line 42

def self::from_frame_data( doc )
	return doc.find( '//fn:lexUnit' ).map do |node|
		id = node['ID']
		self.load( id )
	end
end

.from_lu_document(doc) ⇒ Object

Create a LexicalUnit from the data in the given doc (a LibXML::XML::Document parsed from lu XML)



52
53
54
55
56
57
58
59
60
61
# File 'lib/frame_net/frame/lexical_unit.rb', line 52

def self::from_lu_document( doc )
	return new do |lu|
		lu.id = doc.root['ID'].to_i
		lu.status = doc.root['Status']
		lu.pos = doc.root['POS']
		lu.name = doc.root['name']
		lu.total_annotated = doc.root['totalAnnotated'].to_i
		lu.frame_name = doc.root['frame'].to_sym
	end
end

.load(id) ⇒ Object

Load a LexicalUnit from the XML for the lexical unit with the given id.



22
23
24
25
26
# File 'lib/frame_net/frame/lexical_unit.rb', line 22

def self::load( id )
	path = "lu/lu%d.xml" % [ id.to_i ]
	doc = FrameNet.load_document( path ) or return nil
	return self.from_lu_document( doc )
end

.load_by_name(name) ⇒ Object

Load any LexicalUnits with the given name (in the form <word>.<pos>) and return them as an Array.



31
32
33
34
35
36
37
# File 'lib/frame_net/frame/lexical_unit.rb', line 31

def self::load_by_name( name )
	xpath = %{//fn:lu[@name="%s"]} % [ name ]
	index = FrameNet.lu_index
	return index.find( xpath ).map do |node|
		self.load( node['ID'] )
	end
end

Instance Method Details

#frameObject

Return the FrameNet::Frame associated with this lexical unit, loading it if necessary.



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

def frame
	raise "No frame_name has been set for this unit!" unless self.frame_name
	return @frame ||= FrameNet[ self.frame_name ]
end

#frame=(new_frame) ⇒ Object

Set the FrameNet::Frame associated with this lexical unit to new_frame.



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

def frame=( new_frame )
	self.frame_name = new_frame.name.to_sym
end

#inspectObject

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



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

def inspect
	return %{#<%p:%#016x %s [%d] → |%s|>} % [
		self.class,
		self.object_id * 2,
		self.name,
		self.id || 0,
		self.frame_name
	]
end