Class: LinkParser::Word

Inherits:
Object show all
Defined in:
lib/linkparser/word.rb

Constant Summary collapse

Subject =

Word use constants.

"subject"
Object =
"object"
Determiner =
"determiner"
Verb =
"verb"
Unknown =
"unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sentence, index, left = [], right = [], suffix = '') ⇒ Word

Fill in word name and connect connections correctly.



35
36
37
38
39
40
41
42
# File 'lib/linkparser/word.rb', line 35

def initialize( sentence, index, left=[], right=[], suffix='' )
	@definition = sentence.definitions[index]
	@name = sentence.names[index]
	@position = index
	@left = left
	@right = right
	@suffix = suffix
end

Instance Attribute Details

#definitionObject (readonly)

the LinkParser::Definition object that this is related to



45
46
47
# File 'lib/linkparser/word.rb', line 45

def definition
  @definition
end

#leftObject

the LinkParser::Linkage::Link objects that connect to the left of this word



55
56
57
# File 'lib/linkparser/word.rb', line 55

def left
  @left
end

#nameObject (readonly)

the english language word represented by this object



48
49
50
# File 'lib/linkparser/word.rb', line 48

def name
  @name
end

#positionObject (readonly)

the position of the word within the sentence



51
52
53
# File 'lib/linkparser/word.rb', line 51

def position
  @position
end

#rightObject

the LinkParser::Linkage::Link objects that connect to the right of this word



59
60
61
# File 'lib/linkparser/word.rb', line 59

def right
  @right
end

#suffixObject (readonly)

the suffix or suffixes that this word has limited its usage to



62
63
64
# File 'lib/linkparser/word.rb', line 62

def suffix
  @suffix
end

Instance Method Details

#==(other) ⇒ Object

Simple equality test.



77
78
79
# File 'lib/linkparser/word.rb', line 77

def ==(other)
	@name == other.to_s if other.respond_to?(:to_s)
end

#combine!(other) ⇒ Object

Merges the other word into this word.



70
71
72
73
74
# File 'lib/linkparser/word.rb', line 70

def combine!(other)
	@right += other.right
	@left += other.left
	self
end

#to_sObject

Simple stringy version



65
66
67
# File 'lib/linkparser/word.rb', line 65

def to_s 
	@name.to_s
end

#useObject

Returns the way this word is being used in the sentence.



82
83
84
85
86
87
88
89
# File 'lib/linkparser/word.rb', line 82

def use 
	return Object if @left.find {|c| c.name.match /^O/}
	return Subject if @right.find {|c| c.name.match /^S/}
	return Verb if @left.find {|c| c.name.match /^S/} or
		@right.find {|c| c.name.match /^O/}
	return Determiner if @right.find {|c| c.name.match /^D/}
	return Unknown
end