class PROIEL::Source

A source object in a treebank.

Attributes

alignment_id[R]

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

dialect[R]

@return [String] dialect of the source

export_time[R]

@return [DateTime] export time for the source

id[R]

@return [String] ID of the source

language[R]

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

metadata[R]

@return [Hash{Symbol, String}] metadata fields for the source @see PROIEL::Treebank::METADATA_ELEMENTS

treebank[R]

@return [Treebank] treebank that this source belongs to

Public Class Methods

new(parent, id, export_time, language, dialect, metadata, alignment_id, &block) click to toggle source

Creates a new source object.

# File lib/proiel/source.rb, line 32
def initialize(parent, id, export_time, language, dialect, metadata, alignment_id, &block)
  @treebank = parent
  @id = id.freeze

  raise ArgumentError, 'string or nil expected' unless export_time.nil? or export_time.is_a?(String)
  @export_time = export_time.nil? ? nil : DateTime.parse(export_time).freeze

  @language = language.freeze
  @dialect = dialect ? dialect.freeze : nil
  @metadata = metadata.freeze

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

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

Public Instance Methods

citation() click to toggle source

@return [String] a complete citation for the source

# File lib/proiel/source.rb, line 50
def citation
  citation_part
end
divs() click to toggle source

Finds all divs in the source.

@return [Enumerator] divs in the source

# File lib/proiel/source.rb, line 79
def divs
  @children.to_enum
end
method_missing(method_name, *args, &block) click to toggle source

Accesses metadata fields.

@see PROIEL::Treebank::METADATA_ELEMENTS

Calls superclass method
# File lib/proiel/source.rb, line 68
def method_missing(method_name, *args, &block)
  if @metadata.key?(method_name) and args.empty?
    @metadata[method_name]
  else
    super
  end
end
printable_form(custom_token_formatter: nil) click to toggle source

Returns the printable form of the source 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 source

# File lib/proiel/source.rb, line 61
def printable_form(custom_token_formatter: nil)
  @children.map { |d| d.printable_form(custom_token_formatter: custom_token_formatter) }.compact.join
end
sentences() click to toggle source

Finds all sentences in the source.

@return [Enumerator] sentences in the source

@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/source.rb, line 96
def sentences
  Enumerator.new do |y|
    @children.each do |div|
      div.sentences.each do |sentence|
        y << sentence
      end
    end
  end
end
tokens() click to toggle source

Finds all tokens in the source.

@return [Enumerator] tokens in the source

@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/source.rb, line 119
def tokens
  Enumerator.new do |y|
    @children.each do |div|
      div.sentences.each do |sentence|
        sentence.tokens.each do |token|
          y << token
        end
      end
    end
  end
end