Class: Dphil::Lemma
- Inherits:
-
Object
- Object
- Dphil::Lemma
- Defined in:
- lib/dphil/lemma.rb
Overview
Public: A storage object for words and groups of words from TEI XML data. Also contains information about the source/location of the words. Immutable.
Instance Attribute Summary collapse
-
#facs ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
-
#index ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
-
#line ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
-
#page ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
-
#source ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
-
#text ⇒ Object
readonly
Public: Returns the raw source data for the lemma.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(source = "", index = nil) ⇒ Lemma
constructor
Public: Initialize a lemma object.
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(source = "", index = nil) ⇒ Lemma
Public: Initialize a lemma object.
source - XML data to initialize the lemma from
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dphil/lemma.rb', line 15 def initialize(source = "", index = nil) @source = source.strip @index = index xml = Nokogiri::XML("<lemma>#{source}</lemma>") { |config| config.strict.noent } xml.encoding = "UTF-8" @text = xml.text.strip.gsub(/\-+\s*\-*/, "") @page = xml.css("pb").map { |el| el.attr("n") }.join(",") @facs = xml.css("pb").map { |el| el.attr("facs") }.join(",") @line = xml.css("lb").map { |el| el.attr("n") }.join(",") rescue Nokogiri::XML::SyntaxError => e $stderr.puts "Error in Lemma.new(`#{source}`, ...): #{e}" abort end |
Instance Attribute Details
#facs ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def facs @facs end |
#index ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def index @index end |
#line ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def line @line end |
#page ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def page @page end |
#source ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def source @source end |
#text ⇒ Object (readonly)
Public: Returns the raw source data for the lemma.
10 11 12 |
# File 'lib/dphil/lemma.rb', line 10 def text @text end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 42 |
# File 'lib/dphil/lemma.rb', line 39 def ==(other) return false unless other.is_a?(Dphil::Lemma) source == other.source end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/dphil/lemma.rb', line 31 def to_s "(#{index}|#{page}:#{line}) #{text}" end |
#to_sym ⇒ Object
35 36 37 |
# File 'lib/dphil/lemma.rb', line 35 def to_sym "<Lemma>#{self}".to_sym end |