Class: PROIEL::Source
- Inherits:
-
TreebankObject
- Object
- TreebankObject
- PROIEL::Source
- Defined in:
- lib/proiel/source.rb
Overview
A source object in a treebank.
Instance Attribute Summary collapse
-
#alignment_id ⇒ nil, String
readonly
ID of the source that this source is aligned to.
-
#dialect ⇒ String
readonly
Dialect of the source.
-
#export_time ⇒ DateTime
readonly
Export time for the source.
-
#id ⇒ String
readonly
ID of the source.
-
#language ⇒ String
readonly
Language of the source as an ISO 639-3 language tag.
-
#metadata ⇒ Hash{Symbol, String}
readonly
Metadata fields for the source.
-
#treebank ⇒ Treebank
readonly
Treebank that this source belongs to.
Instance Method Summary collapse
-
#citation ⇒ String
A complete citation for the source.
-
#divs ⇒ Enumerator
Finds all divs in the source.
-
#initialize(parent, id, export_time, language, dialect, metadata, alignment_id, &block) ⇒ Source
constructor
Creates a new source object.
-
#method_missing(method_name, *args, &block) ⇒ Object
Accesses metadata fields.
-
#printable_form(custom_token_formatter: nil) ⇒ String
Returns the printable form of the source with all token forms and any presentation data.
-
#sentences ⇒ Enumerator
Finds all sentences in the source.
-
#tokens ⇒ Enumerator
Finds all tokens in the source.
Methods inherited from TreebankObject
Constructor Details
#initialize(parent, id, export_time, language, dialect, metadata, alignment_id, &block) ⇒ Source
Creates a new source object.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/proiel/source.rb', line 32 def initialize(parent, id, export_time, language, dialect, , 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 = .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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Accesses metadata fields.
68 69 70 71 72 73 74 |
# 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 |
Instance Attribute Details
#alignment_id ⇒ nil, String (readonly)
Returns ID of the source that this source is aligned to.
29 30 31 |
# File 'lib/proiel/source.rb', line 29 def alignment_id @alignment_id end |
#dialect ⇒ String (readonly)
Returns dialect of the source.
19 20 21 |
# File 'lib/proiel/source.rb', line 19 def dialect @dialect end |
#export_time ⇒ DateTime (readonly)
Returns export time for the source.
22 23 24 |
# File 'lib/proiel/source.rb', line 22 def export_time @export_time end |
#id ⇒ String (readonly)
Returns ID of the source.
10 11 12 |
# File 'lib/proiel/source.rb', line 10 def id @id end |
#language ⇒ String (readonly)
Returns language of the source as an ISO 639-3 language tag.
16 17 18 |
# File 'lib/proiel/source.rb', line 16 def language @language end |
#metadata ⇒ Hash{Symbol, String} (readonly)
Returns metadata fields for the source.
26 27 28 |
# File 'lib/proiel/source.rb', line 26 def @metadata end |
#treebank ⇒ Treebank (readonly)
Returns treebank that this source belongs to.
13 14 15 |
# File 'lib/proiel/source.rb', line 13 def treebank @treebank end |
Instance Method Details
#citation ⇒ String
Returns a complete citation for the source.
50 51 52 |
# File 'lib/proiel/source.rb', line 50 def citation citation_part end |
#divs ⇒ Enumerator
Finds all divs in the source.
79 80 81 |
# File 'lib/proiel/source.rb', line 79 def divs @children.to_enum end |
#printable_form(custom_token_formatter: nil) ⇒ String
Returns the printable form of the source with all token forms and any presentation data.
which is passed the token as its sole argument
61 62 63 |
# 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 ⇒ Enumerator
Finds all sentences in the source.
96 97 98 99 100 101 102 103 104 |
# 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 ⇒ Enumerator
Finds all tokens in the source.
119 120 121 122 123 124 125 126 127 128 129 |
# 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 |