Class: LexM::Sublemma
- Inherits:
-
Object
- Object
- LexM::Sublemma
- Defined in:
- lib/lexm/sublemma.rb
Overview
Represents a sublemma, which can be either a textual sublemma or a redirection
Instance Attribute Summary collapse
-
#parent ⇒ Object
Reference to parent lemma.
-
#redirect ⇒ Object
Returns the value of attribute redirect.
-
#source_column ⇒ Object
Source location information.
-
#source_file ⇒ Object
Source location information.
-
#source_line ⇒ Object
Source location information.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text = nil, redirect = nil, parent = nil, source_file = nil, source_line = nil, source_column = nil) ⇒ Sublemma
constructor
Initialize a new sublemma.
-
#redirected? ⇒ Boolean
Is this a pure redirection sublemma?.
-
#shortcut(placeholder = "~") ⇒ String?
Returns a shortened version of the sublemma text, replacing the lemma part with a placeholder For example, if the lemma is “work” and sublemma is “work out”, this returns “~ out”.
-
#to_s ⇒ String
Convert to string representation.
Constructor Details
#initialize(text = nil, redirect = nil, parent = nil, source_file = nil, source_line = nil, source_column = nil) ⇒ Sublemma
Initialize a new sublemma
27 28 29 30 31 32 33 34 |
# File 'lib/lexm/sublemma.rb', line 27 def initialize(text = nil, redirect = nil, parent = nil, source_file = nil, source_line = nil, source_column = nil) @text = text @redirect = redirect @parent = parent @source_file = source_file @source_line = source_line @source_column = source_column end |
Instance Attribute Details
#parent ⇒ Object
Reference to parent lemma
18 19 20 |
# File 'lib/lexm/sublemma.rb', line 18 def parent @parent end |
#redirect ⇒ Object
Returns the value of attribute redirect.
14 15 16 |
# File 'lib/lexm/sublemma.rb', line 14 def redirect @redirect end |
#source_column ⇒ Object
Source location information
16 17 18 |
# File 'lib/lexm/sublemma.rb', line 16 def source_column @source_column end |
#source_file ⇒ Object
Source location information
16 17 18 |
# File 'lib/lexm/sublemma.rb', line 16 def source_file @source_file end |
#source_line ⇒ Object
Source location information
16 17 18 |
# File 'lib/lexm/sublemma.rb', line 16 def source_line @source_line end |
#text ⇒ Object
Returns the value of attribute text.
14 15 16 |
# File 'lib/lexm/sublemma.rb', line 14 def text @text end |
Instance Method Details
#redirected? ⇒ Boolean
Is this a pure redirection sublemma?
38 39 40 |
# File 'lib/lexm/sublemma.rb', line 38 def redirected? @text.nil? && !@redirect.nil? end |
#shortcut(placeholder = "~") ⇒ String?
Returns a shortened version of the sublemma text, replacing the lemma part with a placeholder For example, if the lemma is “work” and sublemma is “work out”, this returns “~ out”
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lexm/sublemma.rb', line 46 def shortcut(placeholder = "~") return nil if redirected? || @text.nil? || @parent.nil? || @parent.text.nil? parent_text = @parent.text # Check if the sublemma starts with the parent lemma if @text.start_with?(parent_text) # Replace the parent lemma with the placeholder remainder = @text[parent_text.length..-1] # If the remainder starts with a space, keep it if remainder.start_with?(" ") return "#{placeholder}#{remainder}" elsif remainder.empty? # For exact matches, just return the placeholder return placeholder else # For cases where the lemma is a prefix but not a whole word # (e.g., lemma "over", sublemma "overdo") - don't create a shortcut return @text end else # If the sublemma doesn't start with the parent lemma, return the full text return @text end end |
#to_s ⇒ String
Convert to string representation
75 76 77 78 79 80 81 |
# File 'lib/lexm/sublemma.rb', line 75 def to_s if redirected? @redirect.to_s else @text end end |