Class: FrameNet::Frame::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/frame_net/frame/element.rb

Overview

Frame elements of a FrameNet::Frame

References:

Constant Summary collapse

XPATH =

The xpath of the FEs of a frame

'//fn:frame/fn:FE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Create a new frame Element. If a block is given, yield the new object to it so its attributes can be set.

Yields:

  • (_self)

Yield Parameters:



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

def initialize # :yields: self
	@id               = id
	@name             = name
	@core_type        = core_type

	@abbrev           = nil
	@creation_time    = nil
	@foreground_color = nil
	@background_color = nil

	@definition       = nil
	@semantic_type    = nil

	yield( self ) if block_given?
end

Instance Attribute Details

#abbrevObject

The Element’s abbreviation



80
81
82
# File 'lib/frame_net/frame/element.rb', line 80

def abbrev
  @abbrev
end

#background_colorObject Also known as: bgColor

The Element’s background color when displayed in a visual medium



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

def background_color
  @background_color
end

#core_typeObject Also known as: coreType

The Element’s core type



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

def core_type
  @core_type
end

#creation_timeObject Also known as: cDate

The Element’s creation time as a Time object



84
85
86
# File 'lib/frame_net/frame/element.rb', line 84

def creation_time
  @creation_time
end

#definitionObject

The FrameNet::Definition associated with this Element (if one exists)



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

def definition
  @definition
end

#foreground_colorObject Also known as: fgColor

The Element’s foreground color when displayed in a visual medium



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

def foreground_color
  @foreground_color
end

#idObject

The Element’s id



72
73
74
# File 'lib/frame_net/frame/element.rb', line 72

def id
  @id
end

#nameObject

The Element’s name



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

def name
  @name
end

#semantic_typeObject

The FrameNet::SemanticType associated with this Element (if one exists)



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

def semantic_type
  @semantic_type
end

Class Method Details

.from_fe_node(node) ⇒ Object

Construct an Element from the given node (a LibXML::XML::Node).



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/frame_net/frame/element.rb', line 26

def self::from_fe_node( node )
	return new do |elem|
		elem.id               = Integer( node['ID'] )
		elem.name             = node['name'].to_sym
		elem.core_type        = node['coreType']
		elem.abbrev           = node['abbrev']
		elem.creation_time    = FrameNet.parse_time( node['cDate'] )
		elem.foreground_color = node['fgColor']
		elem.background_color = node['bgColor']

		if def_node = node.find_first( './fn:definition' )
			elem.definition = FrameNet::Definition.from_node( def_node )
		end

		if st_node = node.find_first( './fn:semType' )
			elem.semantic_type = FrameNet::SemanticType.from_node( st_node )
		end
	end
end

.from_frame_data(doc) ⇒ Object

Construct one or more Elements from the FEs of the specified doc (a LibXML::XML::Document parsed from the XML for a frame)



20
21
22
# File 'lib/frame_net/frame/element.rb', line 20

def self::from_frame_data( doc )
	return doc.find( XPATH ).map {|node| self.from_fe_node(node) }
end

Instance Method Details

#inspectObject

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



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/frame_net/frame/element.rb', line 115

def inspect
	return %{#<%p:%#016x %s%s(%s) [%d] "%s">} % [
		self.class,
		self.object_id * 2,
		self.name || "(Unnamed)",
		self.semantic_type ? ":#{self.semantic_type.name}" : '',
		self.core_type,
		self.id || 0,
		self.definition ? self.definition.stripped_content : '',
	]
end