rbbt-text 1.3.4 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,30 +2,55 @@ require 'rbbt/segment'
2
2
  require 'rbbt/document'
3
3
  require 'rbbt/segment/annotation'
4
4
  require 'rbbt/util/python'
5
+ require 'rbbt/network/paths'
5
6
 
6
7
  module SpaCy
7
8
 
8
- PROPERTIES = %w(lemma_ is_punct is_space shape_ pos_ tag_)
9
+ TOKEN_PROPERTIES = %w(lemma_ is_punct is_space shape_ pos_ tag_)
10
+ CHUNK_PROPERTIES = %w(lemma_)
9
11
 
10
- def self.tokens(text, lang = 'en')
12
+ def self.nlp(lang = 'en_core_web_md')
13
+ @@nlp ||= {}
14
+ @@nlp[lang] ||= RbbtPython.run :spacy do
15
+ spacy.load(lang)
16
+ end
17
+ end
18
+
19
+ def self.tokens(text, lang = 'en_core_web_sm')
11
20
 
12
21
  tokens = []
13
- RbbtPython.run 'spacy' do
14
- nlp = spacy.load(lang)
15
- doc = nlp.call(text)
16
- doc.__len__.times do |i|
17
- tokens << doc.__getitem__(i)
18
- end
22
+
23
+ nlp = nlp(lang)
24
+ doc = nlp.call(text)
25
+
26
+ doc.__len__.times do |i|
27
+ tokens << doc.__getitem__(i)
28
+ end
29
+
30
+ tokens
31
+ end
32
+
33
+ def self.chunks(text, lang = 'en_core_web_sm')
34
+
35
+ tokens = []
36
+ nlp = nlp(lang)
37
+
38
+ doc = nlp.call(text)
39
+ chunks = doc.noun_chunks.__iter__
40
+
41
+ RbbtPython.iterate chunks do |item|
42
+ tokens << item
19
43
  end
44
+
20
45
  tokens
21
46
  end
22
47
 
23
- def self.segments(text, lang = 'en')
24
- docid = text.docid if Document === text
48
+ def self.segments(text, lang = 'en_core_web_sm')
49
+ docid = text.docid if Document === text
25
50
  corpus = text.corpus if Document === text
26
51
  tokens = self.tokens(text, lang).collect do |token|
27
52
  info = {}
28
- PROPERTIES.each do |p|
53
+ TOKEN_PROPERTIES.each do |p|
29
54
  info[p] = token.instance_eval(p.to_s)
30
55
  end
31
56
  info[:type] = "SpaCy"
@@ -35,7 +60,120 @@ module SpaCy
35
60
  info[:corpus] = corpus if corpus
36
61
  SpaCyToken.setup(token.text, info)
37
62
  end
38
- SpaCyToken.setup(tokens, :corpus => corpus)
63
+
64
+ tokens
65
+ end
66
+
67
+ def self.chunk_segments(text, lang = 'en_core_web_sm')
68
+ docid = text.docid if Document === text
69
+ corpus = text.corpus if Document === text
70
+ chunks = self.chunks(text, lang).collect do |chunk|
71
+ info = {}
72
+ CHUNK_PROPERTIES.each do |p|
73
+ info[p] = chunk.instance_eval(p.to_s)
74
+ end
75
+ start = eend = nil
76
+ deps = []
77
+ RbbtPython.iterate chunk.__iter__ do |token|
78
+ start = token.idx if start.nil?
79
+ eend = start + chunk.text.length if eend.nil?
80
+ deps << token.idx.to_s + ":" + token.dep_ + "->" + token.head.idx.to_s if token.head.idx < start || token.head.idx > eend
81
+ end
82
+ info[:type] = "SpaCy"
83
+ info[:offset] = chunk.__iter__.__next__.idx
84
+ info[:dep] = deps * ";"
85
+ info[:docid] = docid if docid
86
+ info[:corpus] = corpus if corpus
87
+ SpaCySpan.setup(chunk.text, info)
88
+ end
89
+
90
+ chunks
91
+ end
92
+
93
+ def self.dep_graph(text, reverse = false, lang = 'en_core_web_md')
94
+ tokens = self.segments(text, lang)
95
+ index = Segment.index(tokens)
96
+ associations = {}
97
+ tokens.each do |token|
98
+ type, target_pos = token.dep.split("->")
99
+ target_tokens = index[target_pos.to_i]
100
+ associations[token.segid] = target_tokens
101
+ end
102
+
103
+ if reverse
104
+ old = associations.dup
105
+ old.each do |s,ts|
106
+ ts.each do |t|
107
+ associations[t] ||= []
108
+ associations[t] += [s] unless associations[t].include?(s)
109
+ end
110
+ end
111
+ end
112
+
113
+ associations
114
+ end
115
+
116
+ def self.chunk_dep_graph(text, reverse = false, lang = 'en_core_web_md')
117
+ associations = dep_graph(text, false, lang)
118
+
119
+ chunks = self.chunk_segments(text, lang)
120
+ tokens = self.segments(text, lang)
121
+ index = Segment.index(tokens + chunks)
122
+
123
+ chunks.each do |chunk|
124
+ target_token_ids = chunk.dep.split(";").collect do|dep|
125
+ type, target_pos = dep.split("->")
126
+ index[target_pos.to_i]
127
+ end.flatten
128
+
129
+ target_tokens = target_token_ids.collect do |target_token_id|
130
+ range = Range.new(*target_token_id.split(":").last.split("..").map(&:to_i))
131
+ range.collect do |pos|
132
+ index[pos]
133
+ end.uniq
134
+ end.flatten
135
+ associations[chunk.segid] = target_tokens
136
+ end
137
+
138
+ if reverse
139
+ old = associations.dup
140
+ old.each do |s,ts|
141
+ ts.each do |t|
142
+ associations[t] ||= []
143
+ associations[t] += [s] unless associations[t].include?(s)
144
+ end
145
+ end
146
+ end
147
+
148
+ associations
149
+ end
150
+
151
+ def self.paths(text, source, target, reverse = true, lang = 'en_core_web_md')
152
+ graph = SpaCy.chunk_dep_graph(text, reverse, lang)
153
+
154
+ chunk_index = Segment.index(SpaCy.chunk_segments(text, lang))
155
+
156
+ source_id = chunk_index[source.offset].first || source.segid
157
+ target_id = chunk_index[target.offset].first || target.segid
158
+
159
+ path = Paths.dijkstra(graph, source_id, [target_id])
160
+
161
+ return nil if path.nil?
162
+
163
+ path.reverse
164
+ end
165
+
166
+ def self.config(base, target = nil)
167
+ TmpFile.with_file(base) do |baseconfig|
168
+ if target
169
+ CMD.cmd(:spacy, "init fill-config #{baseconfig} #{target}")
170
+ else
171
+ TmpFile.with_file do |tmptarget|
172
+ CMD.cmd(:spacy, "init fill-config #{baseconfig} #{tmptarget}")
173
+ Open.read(targetconfig)
174
+ end
175
+ end
176
+ end
39
177
  end
40
178
  end
41
179
 
@@ -43,10 +181,15 @@ module SpaCyToken
43
181
  extend Entity
44
182
  include SegmentAnnotation
45
183
 
46
- self.annotation *SpaCy::PROPERTIES
184
+ self.annotation *SpaCy::TOKEN_PROPERTIES
47
185
  self.annotation :dep
48
186
  end
49
187
 
50
- if __FILE__ == $0
51
- ppp Annotated.tsv(SpaCy.segments("I tell a story"), :all)
188
+ module SpaCySpan
189
+ extend Entity
190
+ include SegmentAnnotation
191
+
192
+ self.annotation *SpaCy::CHUNK_PROPERTIES
193
+ self.annotation :dep
52
194
  end
195
+
@@ -0,0 +1,24 @@
1
+ require 'rbbt/segment'
2
+
3
+ module Relationship
4
+ extend Annotation
5
+ self.annotation :segment
6
+ self.annotation :terms
7
+ self.annotation :type
8
+
9
+ def text
10
+ if segment
11
+ segment
12
+ else
13
+ type + ": " + terms * ", "
14
+ end
15
+ end
16
+
17
+ def html
18
+ text = <<-EOF
19
+ <span class='Relationship'\
20
+ >#{ self.text }</span>
21
+ EOF
22
+ text.chomp
23
+ end
24
+ end
@@ -8,6 +8,10 @@ module NamedEntity
8
8
 
9
9
  self.annotation :entity_type, :code, :score
10
10
 
11
+ def entity_type
12
+ annotation_values[:entity_type] || annotation_values[:type]
13
+ end
14
+
11
15
  def report
12
16
  <<-EOF
13
17
  String: #{ self }
@@ -6,7 +6,7 @@ module Segment::RangeIndex
6
6
  SegID.setup(res, :corpus => corpus)
7
7
  end
8
8
 
9
- def self.index(segments, corpus, persist_file = :memory)
9
+ def self.index(segments, corpus = nil, persist_file = :memory)
10
10
  segments = segments.values.flatten if Hash === segments
11
11
 
12
12
  annotation_index =
@@ -70,7 +70,15 @@ module Transformed
70
70
  orig_length = self.length
71
71
 
72
72
  offset = self.respond_to?(:offset) ? self.offset.to_i : 0
73
- segments = segments.select{|s| s.offset.to_i >= offset && s.offset.to_i <= offset + self.length - 1 }
73
+
74
+ segments = segments.select do |s|
75
+ shift = shift s.range
76
+ s_offset = s.offset.to_i
77
+ s_offset += shift.first if shift
78
+
79
+ s_offset >= offset &&
80
+ s_offset <= offset + self.length - 1
81
+ end
74
82
 
75
83
  Segment.clean_sort(segments).each do |segment|
76
84
  next if segment.offset.nil?
data/lib/rbbt/segment.rb CHANGED
@@ -49,10 +49,13 @@ module Segment
49
49
  length
50
50
  end
51
51
 
52
+
52
53
  def eend
53
54
  offset.to_i + length - 1
54
55
  end
55
56
 
57
+ alias end eend
58
+
56
59
  def range
57
60
  (offset.to_i..eend)
58
61
  end
@@ -1,12 +1,7 @@
1
1
  #!/bin/bash
2
2
 
3
3
  name='OpenNLP'
4
- url="http://apache.rediris.es/opennlp/opennlp-1.9.2/apache-opennlp-1.9.2-bin.tar.gz"
4
+ url="http://apache.rediris.es/opennlp/opennlp-1.9.4/apache-opennlp-1.9.4-bin.tar.gz"
5
5
 
6
- get_src "$name" "$url"
7
- move_opt "$name"
8
-
9
-
10
- ln -sf "$OPT_DIR/$name/lib/"*.jar "$OPT_JAR_DIR/"
11
-
12
- clean_build
6
+ install_src $name $url
7
+ (cd $OPT_DIR/jars; ln -s $OPT_DIR/$name/lib/*.jar .)
@@ -0,0 +1,51 @@
1
+ isLetters /^[A-Z]+$/i
2
+ isUpper /^[A-Z]+$/
3
+ isLower /^[a-z]+$/
4
+ isDigits /^[0-9]+$/i
5
+ isRoman /^[IVX]+$/
6
+ isGreek /^(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)$/i
7
+ isPunctuation /^[,.;]$/
8
+ isDelim /^[\/()\[\]{}\-]$/
9
+ isNonWord /^[^\w]+$/
10
+ isConjunction /^and|or|&|,$/
11
+
12
+ hasLetters /[A-Z]/i
13
+ hasUpper /.[A-Z]/
14
+ hasLower /[a-z]/
15
+ hasDigits /[0-9]/i
16
+ hasGreek /(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)/i
17
+ hasPunctuation /[,.;]/
18
+ hasDelim /[\/()\[\]{}\-]/
19
+ hasNonWord /[^\w]/
20
+ caspMix /[a-z].[A-Z]/
21
+ keywords /(?:protein|gene|domain|ase)s?$/
22
+ hasSuffix /[a-z][A-Z0-9]$/
23
+
24
+ numLetters do |w| w.scan(/[A-Z]/i).length end
25
+ numDigits do |w| w.scan(/[0-9]/).length end
26
+ #
27
+ prefix_3 /^(...)/
28
+ prefix_4 /^(....)/
29
+ suffix_3 /(...)$/
30
+ suffix_4 /(....)$/
31
+
32
+
33
+ token1 do |w|
34
+ w.sub(/[A-Z]/,'A').
35
+ sub(/[a-z]/,'a').
36
+ sub(/[0-9]/,'0').
37
+ sub(/[^0-9a-z]/i,'x')
38
+ end
39
+ token2 do |w|
40
+ w.sub(/[A-Z]+/,'A').
41
+ sub(/[a-z]+/,'a').
42
+ sub(/[0-9]+/,'0').
43
+ sub(/[^0-9a-z]+/i,'x')
44
+ end
45
+ token3 do |w| w.downcase end
46
+ special do |w| w.is_special? end
47
+
48
+ context %w(special token2 isPunctuation isDelim)
49
+ window %w(1 2 3 -1 -2 -3)
50
+ #direction :reverse
51
+
@@ -7,7 +7,7 @@ class TestCorpusPubmed < Test::Unit::TestCase
7
7
  def test_add_pmid
8
8
  corpus = Document::Corpus.setup({})
9
9
 
10
- document = corpus.add_pmid("32299157", :abstract).first
10
+ document = corpus.add_pmid("33359141", :abstract).first
11
11
  title = document.to(:title)
12
12
  assert title.include?("COVID-19")
13
13
  end
@@ -4,6 +4,7 @@ require 'rbbt/document/corpus'
4
4
  require 'rbbt/segment'
5
5
  require 'rbbt/document/annotation'
6
6
  require 'rbbt/segment/named_entity'
7
+ require 'rbbt/ner/abner'
7
8
 
8
9
  class TestAnnotation < Test::Unit::TestCase
9
10
  class CalledOnce < Exception; end
@@ -28,6 +29,12 @@ class TestAnnotation < Test::Unit::TestCase
28
29
  self.split(" ").collect{|e| NamedEntity.setup(e, :code => Misc.digest(e)) }
29
30
  end
30
31
 
32
+ Document.define :abner do
33
+ $called_once = true
34
+ Abner.new.match(self)
35
+ end
36
+
37
+
31
38
  Document.persist :ner
32
39
  end
33
40
 
@@ -133,7 +140,9 @@ class TestAnnotation < Test::Unit::TestCase
133
140
  text.ner
134
141
 
135
142
  assert ! $called_once
136
-
143
+
144
+ assert_equal text.abner.first.docid, text.docid
145
+
137
146
  assert text.ner.first.segid.include?("TEST:")
138
147
  end
139
148
  end
@@ -29,5 +29,19 @@ class TestDocumentCorpus < Test::Unit::TestCase
29
29
  assert corpus.docids("TEST:").include?(text.docid)
30
30
  end
31
31
  end
32
+
33
+ def test_load
34
+ text = "This is a document"
35
+ Document.setup(text, "TEST", "test_doc1", nil)
36
+
37
+ TmpFile.with_file do |path|
38
+ corpus = Persist.open_tokyocabinet(path, true, :single, "BDB")
39
+ corpus.extend Document::Corpus
40
+
41
+ corpus.add_document(text)
42
+
43
+ assert corpus.docids("TEST:").include?(text.docid)
44
+ end
45
+ end
32
46
  end
33
47
 
@@ -0,0 +1,11 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_helper.rb')
2
+ require 'rbbt/ner/rnorm'
3
+
4
+ class TestRNorm < Test::Unit::TestCase
5
+ def test_evaluate
6
+ t = Tokenizer.new
7
+ assert t.evaluate("PDGFRA","PDGFRalpha") > 0
8
+ iii t.evaluate("JUNB","JunB")
9
+ end
10
+ end
11
+
@@ -0,0 +1,132 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+ require 'rbbt'
3
+ require 'rbbt/ner/rner'
4
+ require 'test/unit'
5
+
6
+ class TestRNer < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @parser = NERFeatures.new() do
10
+ isLetters /^[A-Z]+$/i
11
+ context prefix_3 /^(...)/
12
+ downcase do |w| w.downcase end
13
+
14
+ context %w(downcase)
15
+ end
16
+ end
17
+
18
+ def test_config
19
+ config = <<-EOC
20
+ isLetters /^[A-Z]+$/i
21
+ context prefix_3 /^(...)/
22
+ downcase do |w| w.downcase end
23
+
24
+ context %w(downcase)
25
+ EOC
26
+
27
+ assert_equal config.strip, @parser.config.strip
28
+ end
29
+
30
+ def test_reverse
31
+ assert_equal("protein P53", NERFeatures.reverse("P53 protein"))
32
+ assert_equal(
33
+ ". LH of assay - radioimmuno serum the with compared was LH urinary for ) GONAVIS - HI ( test hemagglutination direct new A",
34
+ NERFeatures.reverse(
35
+ "A new direct hemagglutination test (HI-GONAVIS) for urinary LH was compared with the serum\n radioimmuno-assay of LH."
36
+ ))
37
+ end
38
+
39
+ def test_features
40
+ assert_equal @parser.features("abCdE"), ["abCdE",true,'abC','abcde']
41
+ end
42
+
43
+ def test_template
44
+ template =<<-EOT
45
+ UisLetters: %x[0,1]
46
+ Uprefix_3: %x[0,2]
47
+ Uprefix_3#1: %x[1,2]
48
+ Uprefix_3#-1: %x[-1,2]
49
+ Udowncase: %x[0,3]
50
+ Udowncase#1: %x[1,3]
51
+ Udowncase#-1: %x[-1,3]
52
+ B
53
+ EOT
54
+
55
+ assert(@parser.template == template)
56
+ end
57
+
58
+ def test_tokens
59
+ assert( NERFeatures.tokens("A new direct hemagglutination test (HI-GONAVIS) for urinary LH was compared with the serum\n radioimmuno-assay of LH.")==
60
+ ["A", "new", "direct", "hemagglutination", "test", "(", "HI", "-", "GONAVIS", ")", "for", "urinary", "LH", "was", "compared", "with", "the", "serum", "radioimmuno", "-", "assay", "of", "LH", "."])
61
+
62
+
63
+ end
64
+ def test_text_features
65
+
66
+ assert(@parser.text_features("abCdE 1234") == [["abCdE",true, "abC", "abcde"], ["1234",false, "123", "1234"]])
67
+ assert(@parser.text_features("abCdE 1234",true) == [["abCdE",true, "abC", "abcde",1], ["1234",false, "123", "1234",2]])
68
+ assert(@parser.text_features("abCdE 1234",false) == [["abCdE",true, "abC", "abcde",0], ["1234",false, "123", "1234",0]])
69
+
70
+ end
71
+
72
+ def test_tagged_features
73
+ assert_equal(
74
+ [["phosphorilation",true, "pho", "phosphorilation", 0],
75
+ ["of",true, false, "of", 0],
76
+ ["GENE1",false, "GEN", "gene1", 1],
77
+ [".", false, false, ".", 0]],
78
+ @parser.tagged_features("phosphorilation of GENE1.",['GENE1']))
79
+
80
+ assert_equal(
81
+ [["GENE1",false, "GEN", "gene1", 1],
82
+ ["phosphorilation",true, "pho", "phosphorilation", 0]],
83
+ @parser.tagged_features("GENE1 phosphorilation",['GENE1']))
84
+
85
+
86
+ assert_equal(
87
+ [["phosphorilation",true, "pho", "phosphorilation", 0],
88
+ ["of",true, false, "of", 0],
89
+ ["GENE",true, "GEN", "gene", 1],
90
+ ["1",false, false, "1", 2],
91
+ [".", false, false, ".", 0]],
92
+ @parser.tagged_features("phosphorilation of GENE 1.",['GENE 1']))
93
+ end
94
+
95
+ def test_tagged_features_reverse
96
+ @parser.reverse = true
97
+ assert_equal(
98
+ [
99
+ ["GENE1",false, "GEN", "gene1", 1],
100
+ ["of",true, false, "of", 0],
101
+ ["phosphorilation",true, "pho", "phosphorilation", 0]
102
+ ],
103
+ @parser.tagged_features("phosphorilation of GENE1",['GENE1']))
104
+
105
+ assert_equal(
106
+ [
107
+ [".", false, false, ".", 0],
108
+ ["1",false, false, "1", 1],
109
+ ["GENE",true, "GEN", "gene", 2],
110
+ ["of",true, false, "of", 0],
111
+ ["phosphorilation",true, "pho", "phosphorilation", 0]
112
+ ],
113
+ @parser.tagged_features("phosphorilation of GENE 1.",['GENE 1']))
114
+ end
115
+
116
+ def test_default_config
117
+ require 'rbbt/bow/misc'
118
+ text =<<-EOF
119
+ This text explains how MDM2 interacts with TP53.
120
+ EOF
121
+ @parser = NERFeatures.new Rbbt.share.rner["config.rb"].find
122
+ features = @parser.tagged_features text, %w(TP53 MDM2)
123
+ assert features.first.first == "This"
124
+ end
125
+
126
+
127
+
128
+ def __test_CRFPP_install
129
+ assert(require File.join(Rbbt.datadir, 'third_party/crf++/ruby/CRFPP'))
130
+ end
131
+
132
+ end
@@ -43,4 +43,9 @@ S000000376 AAA GENE1 DDD
43
43
  def test_order
44
44
  assert_equal(["S000000375"], @norm.resolve("GENE1"))
45
45
  end
46
+
47
+ def test_token_evaluate
48
+ iii @norm.token_evaluate("PDGFRA","PDGFRalpha")
49
+ end
50
+
46
51
  end
@@ -24,7 +24,8 @@ class TestClass < Test::Unit::TestCase
24
24
 
25
25
  def test_tsv
26
26
  a = "test"
27
- NamedEntity.setup a, 10, "TYPE", "CODE", "SCORE"
27
+ NamedEntity.setup a, 10, "DocID", "TYPE", "CODE", "SCORE"
28
+ ppp Annotated.tsv([a,a])
28
29
  assert Annotated.tsv([a]).fields.include? "code"
29
30
  assert Annotated.tsv([a], nil).fields.include? "code"
30
31
  assert Annotated.tsv([a], :all).fields.include? "code"
@@ -144,7 +144,7 @@ More recently, PPAR activators were shown to inhibit the activation of inflammat
144
144
  gene2.entity_type = "Protein"
145
145
 
146
146
  Transformed.with_transform(a, [gene1,gene2], Proc.new{|e| e.html}) do
147
- assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene'>TP53</span> gene and the <span class='Entity' attr-entity-type='Protein'>CDK5R1</span> protein", a
147
+ assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene' title='Gene'>TP53</span> gene and the <span class='Entity' attr-entity-type='Protein' title='Protein'>CDK5R1</span> protein", a
148
148
  end
149
149
  end
150
150
 
@@ -165,7 +165,7 @@ More recently, PPAR activators were shown to inhibit the activation of inflammat
165
165
  gene2.entity_type = "Protein"
166
166
 
167
167
  Transformed.with_transform(a, [gene1,gene2], Proc.new{|e| e.html}) do
168
- assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene'>TP53</span> gene and the <span class='Entity' attr-entity-type='Protein'>CDK5R1</span> protein", a
168
+ assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene' title='Gene'>TP53</span> gene and the <span class='Entity' attr-entity-type='Protein' title='Protein'>CDK5R1</span> protein", a
169
169
  end
170
170
  end
171
171
 
@@ -185,9 +185,9 @@ More recently, PPAR activators were shown to inhibit the activation of inflammat
185
185
  assert_equal [gene1], Segment.overlaps(Segment.sort([gene1,gene2]))
186
186
 
187
187
  Transformed.with_transform(a, [gene1], Proc.new{|e| e.html}) do
188
- assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene'>TP53</span> gene and the CDK5R1 protein", a
188
+ assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Gene' title='Gene'>TP53</span> gene and the CDK5R1 protein", a
189
189
  Transformed.with_transform(a, [gene2], Proc.new{|e| e.html}) do
190
- assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Expanded Gene'><span class='Entity' attr-entity-type='Gene'>TP53</span> gene</span> and the CDK5R1 protein", a
190
+ assert_equal "This sentence mentions the <span class='Entity' attr-entity-type='Expanded Gene' title='Expanded Gene'><span class='Entity' attr-entity-type='Gene' title='Gene'>TP53</span> gene</span> and the CDK5R1 protein", a
191
191
  end
192
192
  end
193
193
  end
@@ -393,43 +393,26 @@ This is another sentence. Among the nonstructural proteins, the leader protein (
393
393
  end
394
394
  end
395
395
 
396
- def ___test_transform
397
- a = "This sentence mentions the TP53 gene and the CDK5 protein"
396
+ def test_transform_sorter_end
397
+ a = "The transcription factors farnesoid X receptor, small heterodimer partner, liver receptor homolog-1, and liver X receptor comprise the signaling cascade network that regulates the expression and secretion of apoM."
398
398
  original = a.dup
399
399
 
400
- gene1 = "TP53"
400
+ gene1 = "liver receptor homolog-1"
401
401
  gene1.extend Segment
402
402
  gene1.offset = a.index gene1
403
403
 
404
- gene2 = "CDK5"
404
+ gene2 = "apoM"
405
405
  gene2.extend Segment
406
406
  gene2.offset = a.index gene2
407
407
 
408
408
  assert_equal gene1, a[gene1.range]
409
409
  assert_equal gene2, a[gene2.range]
410
410
 
411
- c = a.dup
412
-
413
- c[gene2.range] = "GN"
414
- assert_equal c, Transformed.transform(a,[gene2], "GN")
415
- c[gene1.range] = "GN"
416
- assert_equal c, Transformed.transform(a,[gene1], "GN")
417
-
418
- iii a.transformation_offset_differences
419
- raise
420
- assert_equal gene2.offset, a.transformation_offset_differences.first.first.first
421
- assert_equal gene1.offset, a.transformation_offset_differences.last.first.first
422
-
423
-
424
- gene3 = "GN gene"
425
- gene3.extend Segment
426
- gene3.offset = a.index gene3
427
-
428
- assert_equal gene3, a[gene3.range]
429
-
430
- a.restore([gene3])
431
- assert_equal original, a
432
- assert_equal "TP53 gene", a[gene3.range]
411
+ Transformed.with_transform(a, [gene1], "[TF]") do
412
+ Transformed.with_transform(a, [gene2], "[TG]") do
413
+ assert_equal "The transcription factors farnesoid X receptor, small heterodimer partner, [TF], and liver X receptor comprise the signaling cascade network that regulates the expression and secretion of [TG].", a
414
+ end
415
+ end
433
416
 
434
417
  end
435
418