Class: PROIEL::Div
- Inherits:
-
TreebankObject
- Object
- TreebankObject
- PROIEL::Div
- Extended by:
- Memoist
- Defined in:
- lib/proiel/div.rb
Overview
A div object in a treebank.
Instance Attribute Summary collapse
-
#alignment_id ⇒ nil, String
readonly
ID of the div that this div is aligned to.
-
#id ⇒ Fixnum
readonly
Returns the ID of the div.
-
#presentation_after ⇒ nil, String
readonly
Presentation material after form.
-
#presentation_before ⇒ nil, String
readonly
Presentation material before form.
-
#source ⇒ Source
readonly
Source that the div belongs to.
-
#title ⇒ nil, String
readonly
Title of the div.
Instance Method Summary collapse
-
#alignment(aligned_source) ⇒ Div, NilClass
Returns the aligned div if any.
-
#citation ⇒ String
A complete citation for the div.
-
#citation_part ⇒ String
Computes an appropriate citation component for the div.
-
#inferred_alignment(aligned_source) ⇒ Array<Div>
Returns inferred aligned divs if any.
-
#initialize(parent, id, title, presentation_before, presentation_after, alignment_id, &block) ⇒ Div
constructor
Creates a new div object.
-
#language ⇒ String
Language of the div as an ISO 639-3 language tag.
-
#printable_form(custom_token_formatter: nil) ⇒ String
Returns the printable form of the div with all token forms and any presentation data.
-
#sentences ⇒ Enumerator
Finds all sentences in the div.
-
#tokens ⇒ Enumerator
Finds all tokens in the div.
-
#treebank ⇒ Treebank
Parent treebank object.
Methods inherited from TreebankObject
Constructor Details
#initialize(parent, id, title, presentation_before, presentation_after, alignment_id, &block) ⇒ Div
Creates a new div object.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# 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 |
Instance Attribute Details
#alignment_id ⇒ nil, String (readonly)
Returns ID of the div that this div is aligned to.
32 33 34 |
# File 'lib/proiel/div.rb', line 32 def alignment_id @alignment_id end |
#id ⇒ Fixnum (readonly)
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.
17 18 19 |
# File 'lib/proiel/div.rb', line 17 def id @id end |
#presentation_after ⇒ nil, String (readonly)
Returns presentation material after form.
29 30 31 |
# File 'lib/proiel/div.rb', line 29 def presentation_after @presentation_after end |
#presentation_before ⇒ nil, String (readonly)
Returns presentation material before form.
26 27 28 |
# File 'lib/proiel/div.rb', line 26 def presentation_before @presentation_before end |
#source ⇒ Source (readonly)
Returns source that the div belongs to.
20 21 22 |
# File 'lib/proiel/div.rb', line 20 def source @source end |
#title ⇒ nil, String (readonly)
Returns title of the div.
23 24 25 |
# File 'lib/proiel/div.rb', line 23 def title @title end |
Instance Method Details
#alignment(aligned_source) ⇒ Div, NilClass
Returns the aligned div if any.
145 146 147 |
# File 'lib/proiel/div.rb', line 145 def alignment(aligned_source) alignment_id ? aligned_source.treebank.find_div(alignment_id) : nil end |
#citation ⇒ String
Returns a complete citation for the div.
69 70 71 |
# File 'lib/proiel/div.rb', line 69 def citation [source.citation_part, citation_part].join(' ') end |
#citation_part ⇒ String
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.
81 82 83 84 85 86 87 |
# 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) ⇒ Array<Div>
Returns inferred aligned divs if any.
152 153 154 155 156 |
# 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 ⇒ String
Returns language of the div as an ISO 639-3 language tag.
62 63 64 |
# File 'lib/proiel/div.rb', line 62 def language source.language end |
#printable_form(custom_token_formatter: nil) ⇒ String
Returns the printable form of the div with all token forms and any presentation data.
which is passed the token as its sole argument
96 97 98 99 100 |
# 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 ⇒ Enumerator
Finds all sentences in the div.
115 116 117 |
# File 'lib/proiel/div.rb', line 115 def sentences @children.to_enum end |
#tokens ⇒ Enumerator
Finds all tokens in the div.
132 133 134 135 136 137 138 139 140 |
# 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 ⇒ Treebank
Returns parent treebank object.
57 58 59 |
# File 'lib/proiel/div.rb', line 57 def treebank @source.treebank end |