simple_bioc 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/simple_bioc/bioc_reader.rb +17 -9
- data/lib/simple_bioc/bioc_writer.rb +2 -0
- data/lib/simple_bioc/version.rb +1 -1
- data/lib/simple_bioc.rb +41 -0
- data/simple_bioc.gemspec +1 -0
- data/spec/simple_bioc_spec.rb +17 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f41d51c5fdefb00b99d4fc0dfcd79e3f2f7738b
|
4
|
+
data.tar.gz: 6ca95848028aa0b04b2b44fb3563111218cd5c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb18148c22f361d66ca12413e1f0c34cbfcc1d03cc65ede1e6f08a44978e0406455ddbadf727b8802b4bde9d6360f1dce2a42d45e7cedae44db5818ea847b939
|
7
|
+
data.tar.gz: cb892612b41da3f73e9edc58836f290ff04a348e86869a487e92af577274e058f51b6b1eedcddab194926e7fcf3bc3f10634a01510baa33a7d3da62b83e926af
|
@@ -7,20 +7,28 @@ module BioCReader
|
|
7
7
|
def read(path, options)
|
8
8
|
collection = nil
|
9
9
|
File.open(path) do |file|
|
10
|
-
|
11
|
-
config.noent.strict.noblanks
|
12
|
-
end
|
13
|
-
xml = xml_doc.at_xpath("//collection")
|
14
|
-
if xml.nil?
|
15
|
-
fail 'Wrong format'
|
16
|
-
end
|
17
|
-
collection = SimpleBioC::Collection.new
|
18
|
-
read_collection(xml, collection, options)
|
10
|
+
collection = read_from_file_or_string(file, options)
|
19
11
|
end
|
20
12
|
|
21
13
|
collection
|
22
14
|
end
|
23
15
|
|
16
|
+
def read_from_file_or_string(file_or_string, options)
|
17
|
+
collection = nil
|
18
|
+
|
19
|
+
xml_doc = Nokogiri::XML(file_or_string) do |config|
|
20
|
+
config.noent.strict.noblanks
|
21
|
+
end
|
22
|
+
xml = xml_doc.at_xpath("//collection")
|
23
|
+
if xml.nil?
|
24
|
+
fail 'Wrong format'
|
25
|
+
end
|
26
|
+
collection = SimpleBioC::Collection.new
|
27
|
+
read_collection(xml, collection, options)
|
28
|
+
|
29
|
+
collection
|
30
|
+
end
|
31
|
+
|
24
32
|
def read_text(xml, name)
|
25
33
|
node = xml.at_xpath(name)
|
26
34
|
node && node.content
|
data/lib/simple_bioc/version.rb
CHANGED
data/lib/simple_bioc.rb
CHANGED
@@ -24,6 +24,47 @@ module SimpleBioC
|
|
24
24
|
BioCReader.read(file_path, options)
|
25
25
|
end
|
26
26
|
|
27
|
+
# parse a BioC XML file and convert it into a collection instance
|
28
|
+
#
|
29
|
+
# ==== Arguments
|
30
|
+
# * +file_path+ - file object for parse
|
31
|
+
# * +options+ - (optional) additional options
|
32
|
+
#
|
33
|
+
# ==== Options
|
34
|
+
# * +documents+ - specify IDs of documents to parse. The result will include only the specified documents
|
35
|
+
#
|
36
|
+
# ==== Examples
|
37
|
+
# file = File.open(path)
|
38
|
+
# collection = SimpleBioC.from_xml(file)
|
39
|
+
# collection = SimpleBioC.from_xml(file, {documents:[21785578, 21488974]})
|
40
|
+
def from_xml_file(file, options = {})
|
41
|
+
options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
|
42
|
+
BioCReader.read_from_file_or_string(file, options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# parse a BioC XML string and convert it into a collection instance
|
46
|
+
#
|
47
|
+
# ==== Arguments
|
48
|
+
# * +string+ - xml string (text) for parse
|
49
|
+
# * +options+ - (optional) additional options
|
50
|
+
#
|
51
|
+
# ==== Options
|
52
|
+
# * +documents+ - specify IDs of documents to parse. The result will include only the specified documents
|
53
|
+
#
|
54
|
+
# ==== Examples
|
55
|
+
# content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ..."
|
56
|
+
# collection = SimpleBioC.from_xml(content)
|
57
|
+
# collection = SimpleBioC.from_xml(content, {documents:[21785578, 21488974]})
|
58
|
+
def from_xml_string(string, options = {})
|
59
|
+
options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
|
60
|
+
BioCReader.read_from_file_or_string(string, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def from_json(json, options = {})
|
64
|
+
options[:documents] = options[:documents].map{|e| e.to_s} if options[:documents].kind_of?(Array)
|
65
|
+
BioCReader.read_from_json(json, options)
|
66
|
+
end
|
67
|
+
|
27
68
|
# convert a collection instance to a BioC XML text. Output will return as string
|
28
69
|
#
|
29
70
|
# ==== Arguments
|
data/simple_bioc.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency "nokogiri", "~> 1.6"
|
22
|
+
spec.add_dependency "json_builder", "~> 3.1"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
spec.add_development_dependency "rake", "~> 10.3"
|
data/spec/simple_bioc_spec.rb
CHANGED
@@ -28,4 +28,21 @@ describe "Simple function" do
|
|
28
28
|
output = SimpleBioC.to_xml(collection, {save_with: 0})
|
29
29
|
expect(output).to include('<location offset="1" length="2"/><text>annotation text</text>')
|
30
30
|
end
|
31
|
+
|
32
|
+
it "should read bioc from file" do
|
33
|
+
f = File.open("./xml/everything.xml")
|
34
|
+
collection = SimpleBioC.from_xml_file(f)
|
35
|
+
f.close
|
36
|
+
output = SimpleBioC.to_xml(collection)
|
37
|
+
expect(output).to include('<!DOCTYPE collection SYSTEM "BioC.dtd">')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should read bioc from string" do
|
41
|
+
f = File.open("./xml/everything.xml")
|
42
|
+
contents = f.read
|
43
|
+
collection = SimpleBioC.from_xml_file(contents)
|
44
|
+
f.close
|
45
|
+
output = SimpleBioC.to_xml(collection)
|
46
|
+
expect(output).to include('<!DOCTYPE collection SYSTEM "BioC.dtd">')
|
47
|
+
end
|
31
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_bioc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dongseop Kwon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json_builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|