class PROIEL::Source
A source object in a treebank.
Attributes
@return [nil, String] ID of the source that this source is aligned to
@return [String] dialect of the source
@return [DateTime] export time for the source
@return [String] ID of the source
@return [String] language of the source as an ISO 639-3 language tag
@return [Hash{Symbol, String}] metadata fields for the source @see PROIEL::Treebank::METADATA_ELEMENTS
@return [Treebank] treebank that this source belongs to
Public Class Methods
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
@return [String] a complete citation for the source
# File lib/proiel/source.rb, line 50 def citation citation_part end
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
Accesses metadata fields.
@see PROIEL::Treebank::METADATA_ELEMENTS
# 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
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
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
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