Class: Lbp::FilePart
- Inherits:
-
Object
- Object
- Lbp::FilePart
- Defined in:
- lib/lbp/file_part.rb
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#partid ⇒ Object
readonly
Returns the value of attribute partid.
Instance Method Summary collapse
- #element_name ⇒ Object
-
#initialize(filepath, transcription_type, confighash, partid) ⇒ FilePart
constructor
A new instance of FilePart.
-
#next ⇒ Object
return part_number end.
- #number_of_zones ⇒ Object
- #previous ⇒ Object
- #transform(xsltfile, xslt_param_array = []) ⇒ Object
-
#transform_plain_text(xslt_param_array = []) ⇒ Object
TODO not working because result of transformation is no longer valid xml document might be easier to pass the part if to the xslt_param_array and then return the result def transform_main_view(xslt_param_array=[]) result = File.new(@filepath, @transcription_type, @confighash).transform_main_view(xslt_param_array) #p = result.xpath(“//#@element”) #hard coding for the moment so it will only really work for paragraphs p = result.xpath(“//div”) return p end.
- #word_array ⇒ Object
- #word_count ⇒ Object
- #word_frequency(sort = 'frequency', order = 'descending') ⇒ Object
- #xml ⇒ Object
Constructor Details
#initialize(filepath, transcription_type, confighash, partid) ⇒ FilePart
Returns a new instance of FilePart.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lbp/file_part.rb', line 9 def initialize(filepath, transcription_type, confighash, partid) @confighash = confighash @partid = partid @filepath = filepath @transcription_type = transcription_type @element = self.element_name end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
8 9 10 |
# File 'lib/lbp/file_part.rb', line 8 def element @element end |
#partid ⇒ Object (readonly)
Returns the value of attribute partid.
8 9 10 |
# File 'lib/lbp/file_part.rb', line 8 def partid @partid end |
Instance Method Details
#element_name ⇒ Object
20 21 22 23 24 |
# File 'lib/lbp/file_part.rb', line 20 def element_name transcr = File.new(@filepath, @transcription_type, @confighash) xmlobject = transcr.nokogiri element_name = xmlobject.xpath("name(//node()[@xml:id='#{@partid}'])", 'tei' => 'http://www.tei-c.org/ns/1.0') end |
#next ⇒ Object
return part_number end
36 37 38 39 40 41 42 43 44 |
# File 'lib/lbp/file_part.rb', line 36 def next xmlobject = File.new(@filepath, @transcription_type, @confighash).nokogiri nextpartid = xmlobject.xpath("//tei:#{@element}[@xml:id='#{@partid}']/following::tei:#{@element}[1]/@xml:id", 'tei' => 'http://www.tei-c.org/ns/1.0') if nextpartid.text == nil return nil else return FilePart.new(@filepath, @transcription_type, @confighash, nextpartid.text) end end |
#number_of_zones ⇒ Object
54 55 56 57 58 59 |
# File 'lib/lbp/file_part.rb', line 54 def number_of_zones xmlobject = File.new(@filepath, @transcription_type, @confighash).nokogiri partid_with_hash = "#" + @partid result = xmlobject.xpath("/tei:TEI/tei:facsimile//tei:surface/tei:zone[@start='#{partid_with_hash}']", 'tei' => 'http://www.tei-c.org/ns/1.0') return result.count end |
#previous ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/lbp/file_part.rb', line 45 def previous xmlobject = File.new(@filepath, @transcription_type, @confighash).nokogiri previouspartid = xmlobject.xpath("//tei:#{@element}[@xml:id='#{@partid}']/preceding::tei:#{@element}[1]/@xml:id", 'tei' => 'http://www.tei-c.org/ns/1.0') if previouspartid.empty? return nil else return FilePart.new(@filepath, @transcription_type, @confighash, previouspartid.text) end end |
#transform(xsltfile, xslt_param_array = []) ⇒ Object
66 67 68 69 70 |
# File 'lib/lbp/file_part.rb', line 66 def transform(xsltfile, xslt_param_array=[]) result = File.new(@filepath, @transcription_type, @confighash).transform(xsltfile, xslt_param_array) p = result.xpath("//#{@element}[@id='#{@partid}']") return p end |
#transform_plain_text(xslt_param_array = []) ⇒ Object
TODO not working because result of transformation is no longer valid xml document might be easier to pass the part if to the xslt_param_array and then return the result def transform_main_view(xslt_param_array=[]) result = File.new(@filepath, @transcription_type, @confighash).transform_main_view(xslt_param_array) #p = result.xpath(“//#@element”) #hard coding for the moment so it will only really work for paragraphs p = result.xpath(“//div”) return p end
81 82 83 84 85 86 87 88 |
# File 'lib/lbp/file_part.rb', line 81 def transform_plain_text(xslt_param_array=[]) # not that it could be slightly confusing that paragraph plain text uses the transform clean, # because we still the basic paragraph elements in order to select the desired paragraph result = File.new(@filepath, @transcription_type, @confighash).transform_clean_nokogiri(xslt_param_array) p = result.xpath("//#{@element}[@id='#{@partid}']") return p end |
#word_array ⇒ Object
94 95 96 97 98 |
# File 'lib/lbp/file_part.rb', line 94 def word_array plaintext = self.transform_plain_text word_array = plaintext.text.split word_array.map!{ |word| word.downcase} end |
#word_count ⇒ Object
90 91 92 93 |
# File 'lib/lbp/file_part.rb', line 90 def word_count plaintext = self.transform_plain_text size = plaintext.text.split.size end |
#word_frequency(sort = 'frequency', order = 'descending') ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/lbp/file_part.rb', line 99 def word_frequency(sort='frequency', order='descending') word_array = self.word_array wf = Hash.new(0) word_array.each { |word| wf[word] += 1 } if sort == "frequency" if order == "descending" # high to low wf = wf.sort_by{|k,v| v}.reverse elsif order == "ascending" # low to high wf = wf.sort_by{|k,v| v} end elsif sort == "word" if order == "descending" # z - a wf = wf.sort_by{|k,v| k}.reverse elsif order == "ascending" #a - z wf = wf.sort_by{|k,v| k} end end return wf.to_h end |