class PROIEL::Div

A div object in a treebank.

Attributes

alignment_id[R]

@return [nil, String] ID of the div that this div is aligned to

id[R]

Returns the ID of the div.

PROIEL XML 2.0 lacks IDs for divs while later versions require them. For PROIEL XML 2.0 unique IDs are generated by PROIEL::Treebank.

@return [Fixnum] ID of the div

presentation_after[R]

@return [nil, String] presentation material after form

presentation_before[R]

@return [nil, String] presentation material before form

source[R]

@return [Source] source that the div belongs to

title[R]

@return [nil, String] title of the div

Public Class Methods

new(parent, id, title, presentation_before, presentation_after, alignment_id, &block) click to toggle source

Creates a new div object.

# File lib/proiel/div.rb, line 35
def initialize(parent, id, title, presentation_before, presentation_after, alignment_id, &block)
  @source = parent

  raise ArgumentError, 'integer expected' unless id.is_a?(Integer)
  @id = id

  raise ArgumentError, 'string or nil expected' unless title.nil? or title.is_a?(String)
  @title = title.freeze

  raise ArgumentError, 'string or nil expected' unless presentation_before.nil? or presentation_before.is_a?(String)
  @presentation_before = presentation_before.freeze

  raise ArgumentError, 'string or nil expected' unless presentation_after.nil? or presentation_after.is_a?(String)
  @presentation_after = presentation_after.freeze

  raise ArgumentError, 'integer or nil expected' unless alignment_id.nil? or alignment_id.is_a?(Integer)
  @alignment_id = alignment_id

  @children = block.call(self) if block_given?
end

Public Instance Methods

alignment(aligned_source) click to toggle source

Returns the aligned div if any.

@return [Div, NilClass] aligned div

# File lib/proiel/div.rb, line 145
def alignment(aligned_source)
  alignment_id ? aligned_source.treebank.find_div(alignment_id) : nil
end
citation() click to toggle source

@return [String] a complete citation for the div

# File lib/proiel/div.rb, line 69
def citation
  [source.citation_part, citation_part].join(' ')
end
citation_part() click to toggle source

Computes an appropriate citation component for the div.

The computed citation component must be concatenated with the citation component provided by the source to produce a complete citation.

@see citation

@return [String] the citation component

# File lib/proiel/div.rb, line 81
def citation_part
  tc = tokens.select(&:has_citation?)
  x = tc.first ? tc.first.citation_part : nil
  y = tc.last ? tc.last.citation_part : nil

  Citations.citation_make_range(x, y)
end
inferred_alignment(aligned_source) click to toggle source

Returns inferred aligned divs if any.

@return [Array<Div>] inferred aligned divs

# File lib/proiel/div.rb, line 152
def inferred_alignment(aligned_source)
  sentences.map do |sentence|
    sentence.inferred_alignment(aligned_source)
  end.flatten.compact.map(&:div).uniq
end
language() click to toggle source

@return [String] language of the div as an ISO 639-3 language tag

# File lib/proiel/div.rb, line 62
def language
  source.language
end
printable_form(custom_token_formatter: nil) click to toggle source

Returns the printable form of the div with all token forms and any presentation data.

@param custom_token_formatter [Lambda] formatting function for tokens which is passed the token as its sole argument

@return [String] the printable form of the div

# File lib/proiel/div.rb, line 96
def printable_form(custom_token_formatter: nil)
  [presentation_before,
   @children.map { |s| s.printable_form(custom_token_formatter: custom_token_formatter) },
   presentation_after].compact.join
end
sentences() click to toggle source

Finds all sentences in the div.

@return [Enumerator] sentences in the div

@example Iterating sentences

sentences.each { |s| puts s.id }

@example Create an array with only reviewed sentences

sentences.select(&:reviewed?)

@example Counting sentences

sentences.count #=> 200
# File lib/proiel/div.rb, line 115
def sentences
  @children.to_enum
end
tokens() click to toggle source

Finds all tokens in the div.

@return [Enumerator] tokens in the div

@example Iterating tokens

tokens.each { |t| puts t.id }

@example Create an array with only empty tokens

tokens.select(&:is_empty?)

@example Counting tokens

puts tokens.count #=> 200
# File lib/proiel/div.rb, line 132
def tokens
  Enumerator.new do |y|
    @children.each do |sentence|
      sentence.tokens.each do |token|
        y << token
      end
    end
  end
end
treebank() click to toggle source

@return [Treebank] parent treebank object

# File lib/proiel/div.rb, line 57
def treebank
  @source.treebank
end