Class: LinkParser::Word
Constant Summary collapse
- Subject =
Word use constants.
"subject"
- Object =
"object"
- Determiner =
"determiner"
- Verb =
"verb"
- Unknown =
"unknown"
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
the LinkParser::Definition object that this is related to.
-
#left ⇒ Object
the LinkParser::Linkage::Link objects that connect to the left of this word.
-
#name ⇒ Object
readonly
the english language word represented by this object.
-
#position ⇒ Object
readonly
the position of the word within the sentence.
-
#right ⇒ Object
the LinkParser::Linkage::Link objects that connect to the right of this word.
-
#suffix ⇒ Object
readonly
the suffix or suffixes that this word has limited its usage to.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Simple equality test.
-
#combine!(other) ⇒ Object
Merges the other word into this word.
-
#initialize(sentence, index, left = [], right = [], suffix = '') ⇒ Word
constructor
Fill in word name and connect connections correctly.
-
#to_s ⇒ Object
Simple stringy version.
-
#use ⇒ Object
Returns the way this word is being used in the sentence.
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
#definition ⇒ Object (readonly)
the LinkParser::Definition object that this is related to
45 46 47 |
# File 'lib/linkparser/word.rb', line 45 def definition @definition end |
#left ⇒ Object
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 |
#name ⇒ Object (readonly)
the english language word represented by this object
48 49 50 |
# File 'lib/linkparser/word.rb', line 48 def name @name end |
#position ⇒ Object (readonly)
the position of the word within the sentence
51 52 53 |
# File 'lib/linkparser/word.rb', line 51 def position @position end |
#right ⇒ Object
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 |
#suffix ⇒ Object (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_s ⇒ Object
Simple stringy version
65 66 67 |
# File 'lib/linkparser/word.rb', line 65 def to_s @name.to_s end |
#use ⇒ Object
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 |