Module: SimpleBioC

Defined in:
lib/simple_bioc.rb,
lib/simple_bioc/node.rb,
lib/simple_bioc/passage.rb,
lib/simple_bioc/version.rb,
lib/simple_bioc/document.rb,
lib/simple_bioc/location.rb,
lib/simple_bioc/relation.rb,
lib/simple_bioc/sentence.rb,
lib/simple_bioc/node_base.rb,
lib/simple_bioc/annotation.rb,
lib/simple_bioc/collection.rb

Overview

SimpleBioC main library

Defined Under Namespace

Classes: Annotation, Collection, Document, Location, Node, NodeBase, Passage, Relation, Sentence

Constant Summary collapse

VERSION =
"0.0.24"

Class Method Summary collapse

Class Method Details

.from_xml(file_path, options = {}) ⇒ Object

parse a BioC XML file in the given path and convert it into a collection instance

Arguments

  • file_path - file path for parse

  • options - (optional) additional options

Options

  • documents - specify IDs of documents to parse. The result will include only the specified documents

Examples

collection = SimpleBioC.from_xml("./xml/everything.xml")
collection = SimpleBioC.from_xml("./xml/lemma.xml", {documents:[21785578, 21488974]})


23
24
25
26
# File 'lib/simple_bioc.rb', line 23

def from_xml(file_path, options = {})
  options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
  BioCReader.read(file_path, options)
end

.from_xml_file(file, options = {}) ⇒ Object

parse a BioC XML file and convert it into a collection instance

Arguments

  • file_path - file object for parse

  • options - (optional) additional options

Options

  • documents - specify IDs of documents to parse. The result will include only the specified documents

Examples

file = File.open(path)
collection = SimpleBioC.from_xml(file)
collection = SimpleBioC.from_xml(file, {documents:[21785578, 21488974]})


41
42
43
44
# File 'lib/simple_bioc.rb', line 41

def from_xml_file(file, options = {})
  options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
  BioCReader.read_from_file_or_string(file, options)
end

.from_xml_string(string, options = {}) ⇒ Object

parse a BioC XML string and convert it into a collection instance

Arguments

  • string - xml string (text) for parse

  • options - (optional) additional options

Options

  • documents - specify IDs of documents to parse. The result will include only the specified documents

Examples

content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ..."
collection = SimpleBioC.from_xml(content)
collection = SimpleBioC.from_xml(content, {documents:[21785578, 21488974]})


59
60
61
62
# File 'lib/simple_bioc.rb', line 59

def from_xml_string(string, options = {})
  options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
  BioCReader.read_from_file_or_string(string, options)
end

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



85
86
87
# File 'lib/simple_bioc.rb', line 85

def to_pubann(collection, options = {})
  PubAnnWriter.write(collection, options)
end

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

convert a collection instance to a BioC XML text. Output will return as string

Arguments

  • collection - Collection instance to process

  • options - (optional) additional options

Options

  • save_with - SaveOption for Nokorigi. If you set this 0, output has no format (no indentation, no whitespace)

Examples

output = SimpleBioC.to_xml(collection)
output = SimpleBioC.to_xml(collection, {save_with: 0})


81
82
83
# File 'lib/simple_bioc.rb', line 81

def to_xml(collection, options = {})
  BioCWriter.write(collection, options)
end