Module: PubAnnWriter

Defined in:
lib/simple_bioc/pub_ann_writer.rb

Class Method Summary collapse

Class Method Details

.write(collection, options = {}) ⇒ Object



7
8
9
10
11
# File 'lib/simple_bioc/pub_ann_writer.rb', line 7

def write(collection, options = {})
  Jbuilder.new do |json|
    write_collection(json, collection, options)
  end.target!
end

.write_collection(json, collection, options) ⇒ Object



13
14
15
16
17
# File 'lib/simple_bioc/pub_ann_writer.rb', line 13

def write_collection(json, collection, options)
  json.array! collection.documents do |d|
    write_document(json, d, options)
  end
end

.write_document(json, document, options) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/simple_bioc/pub_ann_writer.rb', line 19

def write_document(json, document, options)
  json.sourceid document.id
  json.sourcedb options[:sourcedb] || ""
  json.project options[:project] || ""
  json.target options[:target] || ""
  json.text document.all_texts
  json.denotations document.all_annotations do |a|
    a.locations.each do |l|
      json.span do 
        json.begin l.offset.to_i
        json.end l.offset.to_i + l.length.to_i
      end
      json.obj a.infons.map{|k,v| v}.join(",")
      json.id a.id unless a.id.nil?
    end
  end
  json.relations document.all_relations do |r|
    json.pred r.infons.map{|k,v| v}.join(",")
    first = true
    r.nodes.each do |n|
      if first 
        json.obj n.refid
        first = false
      else
        json.subj n.refid
      end
    end
    json.id r.id unless r.id.nil?
  end
end