Class: Opener::KAF::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/kaf/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/opener/kaf/document.rb', line 7

def document
  @document
end

#lexiconsObject (readonly)

Returns the value of attribute lexicons.



8
9
10
# File 'lib/opener/kaf/document.rb', line 8

def lexicons
  @lexicons
end

#mapObject

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 timestamp then Time.now.iso8601 else '*' end,
    version:   version,
    name:      name,
  )
  lp
end

#languageObject



20
21
22
# File 'lib/opener/kaf/document.rb', line 20

def language
  @language ||= @document.at_xpath('KAF').attr 'xml:lang'
end

#termsObject



24
25
26
# File 'lib/opener/kaf/document.rb', line 24

def terms
  @terms ||= collection 'KAF/terms/term', Term
end

#to_xmlObject



41
42
43
# File 'lib/opener/kaf/document.rb', line 41

def to_xml
  @document.to_xml indent: 2
end