Class: Opener::KAF::Document
- Inherits:
-
Object
- Object
- Opener::KAF::Document
- Defined in:
- lib/opener/kaf/document.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#lexicons ⇒ Object
readonly
Returns the value of attribute lexicons.
-
#map ⇒ Object
Returns the value of attribute map.
Class Method Summary collapse
Instance Method Summary collapse
- #add_linguistic_processor(name, version, layer, timestamp: false) ⇒ Object
-
#initialize(xml) ⇒ Document
constructor
A new instance of Document.
- #language ⇒ Object
- #terms ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(xml) ⇒ Document
Returns a new instance of Document.
12 13 14 |
# File 'lib/opener/kaf/document.rb', line 12 def initialize xml @document = xml end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
7 8 9 |
# File 'lib/opener/kaf/document.rb', line 7 def document @document end |
#lexicons ⇒ Object (readonly)
Returns the value of attribute lexicons.
8 9 10 |
# File 'lib/opener/kaf/document.rb', line 8 def lexicons @lexicons end |
#map ⇒ Object
Returns the value of attribute map.
10 11 12 |
# File 'lib/opener/kaf/document.rb', line 10 def map @map end |
Class Method Details
.from_xml(xml) ⇒ Object
16 17 18 |
# File 'lib/opener/kaf/document.rb', line 16 def self.from_xml xml new Nokogiri::XML xml end |
Instance Method Details
#add_linguistic_processor(name, version, layer, timestamp: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opener/kaf/document.rb', line 28 def add_linguistic_processor name, version, layer, timestamp: false header = @document.at('kafHeader') || @document.root.add_child('<kafHeader/>').first procs = header.css('linguisticProcessors').find{ |l| l.attr(:layer) == layer } procs ||= header.add_child("<linguisticProcessors layer='#{layer}'/>").first lp = procs.add_child('<lp/>') lp.attr( timestamp: if then Time.now.iso8601 else '*' end, version: version, name: name, ) lp end |
#language ⇒ Object
20 21 22 |
# File 'lib/opener/kaf/document.rb', line 20 def language @language ||= @document.at_xpath('KAF').attr 'xml:lang' end |
#terms ⇒ Object
24 25 26 |
# File 'lib/opener/kaf/document.rb', line 24 def terms @terms ||= collection 'KAF/terms/term', Term end |
#to_xml ⇒ Object
41 42 43 |
# File 'lib/opener/kaf/document.rb', line 41 def to_xml @document.to_xml indent: 2 end |