simple_bioc 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_bioc/annotation.rb +1 -1
- data/lib/simple_bioc/bioc_reader.rb +6 -2
- data/lib/simple_bioc/bioc_writer.rb +11 -10
- data/lib/simple_bioc/document.rb +5 -5
- data/lib/simple_bioc/location_adjuster.rb +3 -1
- data/lib/simple_bioc/node.rb +2 -2
- data/lib/simple_bioc/node_base.rb +1 -1
- data/lib/simple_bioc/passage.rb +5 -5
- data/lib/simple_bioc/relation.rb +1 -1
- data/lib/simple_bioc/sentence.rb +3 -3
- data/lib/simple_bioc/version.rb +1 -1
- data/xml/merge/output.xml +974 -974
- data/xml/merge/output_10330397.xml +317 -317
- data/xml/merge/output_10366597.xml +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 898191c87e6e9a0a46e7b7c6638370cffc0a5d25
|
4
|
+
data.tar.gz: 1bf48d3b2bdee74d55beefe4769a7376d066b8ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742f7bcc0521d1f4e92d1fd2027e613c9d959a272da3376660746edcd9fce4013ef43978859846e63616702d65ce87e46fb1f5c9e3c8de7ac312a072972ec22b
|
7
|
+
data.tar.gz: 52447cdb3c44fb1e13cafe44b45ad72139cde34322e920bdd039babc420c4f68fdf985a29154bb1fbfda078bf1f6d9a35879fb72776f0772d27f6dccd76d7961
|
@@ -40,12 +40,16 @@ module BioCReader
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def read_infon(xml, obj)
|
43
|
-
xml.xpath("infon")
|
43
|
+
ret = xml.xpath("infon")
|
44
|
+
return if ret.nil?
|
45
|
+
ret.each{ |i| obj.infons[i["key"]] = i.content}
|
44
46
|
end
|
45
47
|
|
46
48
|
def read_recursive(xml, obj, name, options = {})
|
47
49
|
target_class = SimpleBioC.const_get(name.capitalize)
|
48
|
-
xml.xpath(name)
|
50
|
+
ret = xml.xpath(name)
|
51
|
+
return if ret.nil?
|
52
|
+
ret.each do |node|
|
49
53
|
instance = target_class.new(obj)
|
50
54
|
ret = send(:"read_#{name}", node, instance, options)
|
51
55
|
obj.instance_variable_get(:"@#{name}s") << instance if ret
|
@@ -15,6 +15,7 @@ module BioCWriter
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def write_infon(xml, obj)
|
18
|
+
return if obj.infons.nil?
|
18
19
|
obj.infons.each do |k, v|
|
19
20
|
xml.infon(:key => k) {
|
20
21
|
xml.text v
|
@@ -28,7 +29,7 @@ module BioCWriter
|
|
28
29
|
xml.date collection.date
|
29
30
|
xml.key collection.key
|
30
31
|
write_infon(xml, collection)
|
31
|
-
collection.documents.each{|d| write_document(xml, d)}
|
32
|
+
collection.documents.each{|d| write_document(xml, d)} unless collection.documents.nil?
|
32
33
|
}
|
33
34
|
end
|
34
35
|
|
@@ -36,8 +37,8 @@ module BioCWriter
|
|
36
37
|
xml.document {
|
37
38
|
xml.id_ document.id
|
38
39
|
write_infon(xml, document)
|
39
|
-
document.passages.each{|p| write_passage(xml, p)}
|
40
|
-
document.relations.each{|r| write_relation(xml, r)}
|
40
|
+
document.passages.each{|p| write_passage(xml, p)} unless document.passages.nil?
|
41
|
+
document.relations.each{|r| write_relation(xml, r)} unless document.relations.nil?
|
41
42
|
}
|
42
43
|
end
|
43
44
|
|
@@ -46,9 +47,9 @@ module BioCWriter
|
|
46
47
|
write_infon(xml, passage)
|
47
48
|
xml.offset passage.offset
|
48
49
|
xml.text_ passage.text unless passage.text.nil?
|
49
|
-
passage.annotations.each{|a| write_annotation(xml, a)}
|
50
|
-
passage.sentences.each{|s| write_sentence(xml, s)}
|
51
|
-
passage.relations.each{|r| write_relation(xml, r)}
|
50
|
+
passage.annotations.each{|a| write_annotation(xml, a)} unless passage.annotations.nil?
|
51
|
+
passage.sentences.each{|s| write_sentence(xml, s)} unless passage.sentences.nil?
|
52
|
+
passage.relations.each{|r| write_relation(xml, r)} unless passage.relations.nil?
|
52
53
|
}
|
53
54
|
end
|
54
55
|
|
@@ -57,8 +58,8 @@ module BioCWriter
|
|
57
58
|
write_infon(xml, sentence)
|
58
59
|
xml.offset sentence.offset
|
59
60
|
xml.text_ sentence.text unless sentence.text.nil?
|
60
|
-
sentence.annotations.each{|a| write_annotation(xml, a)}
|
61
|
-
sentence.relations.each{|r| write_relation(xml, r)}
|
61
|
+
sentence.annotations.each{|a| write_annotation(xml, a)} unless sentence.annotations.nil?
|
62
|
+
sentence.relations.each{|r| write_relation(xml, r)} unless sentence.relations.nil?
|
62
63
|
}
|
63
64
|
end
|
64
65
|
|
@@ -70,7 +71,7 @@ module BioCWriter
|
|
70
71
|
end
|
71
72
|
xml.annotation(attribute) {
|
72
73
|
write_infon(xml, annotation)
|
73
|
-
annotation.locations.each{|l| write_location(xml, l)}
|
74
|
+
annotation.locations.each{|l| write_location(xml, l)} unless annotation.locations.nil?
|
74
75
|
xml.text_ annotation.text
|
75
76
|
}
|
76
77
|
end
|
@@ -83,7 +84,7 @@ module BioCWriter
|
|
83
84
|
end
|
84
85
|
xml.relation(attribute) {
|
85
86
|
write_infon(xml, relation)
|
86
|
-
relation.nodes.each{|n| write_node(xml, n)}
|
87
|
+
relation.nodes.each{|n| write_node(xml, n)} unless relation.nodes.nil?
|
87
88
|
}
|
88
89
|
end
|
89
90
|
|
data/lib/simple_bioc/document.rb
CHANGED
@@ -14,8 +14,8 @@ module SimpleBioC
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def find_node(id)
|
17
|
-
relations.each{|r| return r if r.id == id}
|
18
|
-
passages.each do |p|
|
17
|
+
@relations.each{|r| return r if r.id == id}
|
18
|
+
@passages.each do |p|
|
19
19
|
ret = p.find_node(id)
|
20
20
|
return ret unless ret.nil?
|
21
21
|
end
|
@@ -27,12 +27,12 @@ module SimpleBioC
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def each_relation
|
30
|
-
relations.each{|r| yield r}
|
31
|
-
passages.each{|p| p.each_relation{|r| yield r}}
|
30
|
+
@relations.each{|r| yield r}
|
31
|
+
@passages.each{|p| p.each_relation{|r| yield r}}
|
32
32
|
end
|
33
33
|
|
34
34
|
def to_s
|
35
|
-
"Document:#{id}"
|
35
|
+
"Document:#{@id}"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -2,9 +2,10 @@ module SimpleBioC
|
|
2
2
|
module LocationAdjuster
|
3
3
|
def adjust_annotation_offsets
|
4
4
|
obj = self
|
5
|
-
return if obj.nil?
|
5
|
+
return if obj.nil? || obj.annotations.nil?
|
6
6
|
obj.annotations.each do |a|
|
7
7
|
positions = find_all_locations(obj, a.text)
|
8
|
+
next a.locations.nil?
|
8
9
|
a.locations.each do |l|
|
9
10
|
l.original_offset = l.offset.to_i if l.original_offset.nil?
|
10
11
|
l.offset = choose_offset_candidate(l.offset, positions)
|
@@ -26,6 +27,7 @@ module SimpleBioC
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def choose_offset_candidate(offset, positions)
|
30
|
+
return offset if positions.nil?
|
29
31
|
min_diff = 99999
|
30
32
|
offset = offset.to_i
|
31
33
|
ret = offset
|
data/lib/simple_bioc/node.rb
CHANGED
@@ -6,10 +6,10 @@ module SimpleBioC
|
|
6
6
|
|
7
7
|
def initialize(parent)
|
8
8
|
@infons = {}
|
9
|
+
@id = nil
|
9
10
|
@document = parent if parent.is_a? Document
|
10
11
|
@passage = parent if parent.is_a? Passage
|
11
12
|
@sentence = parent if parent.is_a? Sentence
|
12
|
-
|
13
13
|
@passage = @sentence.passage unless @sentence.nil?
|
14
14
|
@document = @passage.document unless @passage.nil?
|
15
15
|
end
|
data/lib/simple_bioc/passage.rb
CHANGED
@@ -15,12 +15,12 @@ module SimpleBioC
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def to_s
|
18
|
-
"Passage @#{offset}: #{text}"
|
18
|
+
"Passage @#{@offset}: #{@text}"
|
19
19
|
end
|
20
20
|
|
21
21
|
def find_node(id)
|
22
|
-
(relations
|
23
|
-
sentences.each do |s|
|
22
|
+
(@relations+@annotations).each{|n| return n if n.id == id}
|
23
|
+
@sentences.each do |s|
|
24
24
|
ret = s.find_node(id)
|
25
25
|
return ret unless ret.nil?
|
26
26
|
end
|
@@ -28,8 +28,8 @@ module SimpleBioC
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def each_relation
|
31
|
-
relations.each{|r| yield r}
|
32
|
-
sentences.each{|s| s.each_relation{|r| yield r}}
|
31
|
+
@relations.each{|r| yield r}
|
32
|
+
@sentences.each{|s| s.each_relation{|r| yield r}}
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/simple_bioc/relation.rb
CHANGED
data/lib/simple_bioc/sentence.rb
CHANGED
@@ -14,16 +14,16 @@ module SimpleBioC
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def find_node(id)
|
17
|
-
(relations
|
17
|
+
(@relations+@annotations).each{|n| return n if n.id == id}
|
18
18
|
nil
|
19
19
|
end
|
20
20
|
|
21
21
|
def each_relation
|
22
|
-
relations.each{|r| yield r}
|
22
|
+
@relations.each{|r| yield r}
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_c
|
26
|
-
"Sentence @#{offset}: #{text}"
|
26
|
+
"Sentence @#{@offset}: #{@text}"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/simple_bioc/version.rb
CHANGED