Module: PubAnnWriter
- Defined in:
- lib/simple_bioc/pub_ann_writer.rb
Class Method Summary collapse
- .write(collection, options = {}) ⇒ Object
- .write_collection(json, collection, options) ⇒ Object
- .write_document(json, document, options) ⇒ Object
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, = {}) Jbuilder.new do |json| write_collection(json, collection, ) 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, ) json.array! collection.documents do |d| write_document(json, d, ) 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, ) json.sourceid document.id json.sourcedb [:sourcedb] || "" json.project [:project] || "" json.target [: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 json.end l.offset + l.length 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 |