rbbt 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,6 +51,7 @@ class RegExpNER
51
51
  end
52
52
 
53
53
  def match_hash(text)
54
+ return {} if text.nil? || text == ""
54
55
  matches = {}
55
56
  @index.each{|code, re|
56
57
  RegExpNER.match_re(text, re).each{|match|
@@ -133,13 +133,13 @@ module Organism
133
133
  if i == 0
134
134
  i += 1
135
135
  next unless l=~/^\s*#/
136
- formats = l.chomp.sub(/^[\s#]+/,'').split(/\t/).collect{|n| n.strip}
136
+ formats = Open.fields(l.sub(/^[\s#]+/,'')).collect{|n| n.strip}
137
137
  return formats unless examples
138
138
  next
139
139
  end
140
140
 
141
- if l.chomp.split(/\t/).select{|name| name && name =~ /\w/}.length > examples.length
142
- examples = l.chomp.split(/\t/).collect{|name| name.split(/\|/).first}
141
+ if Open.fields(l).select{|name| name && name =~ /\w/}.length > examples.length
142
+ examples = Open.fields(l).collect{|name| name.split(/\|/).first}
143
143
  end
144
144
  i += 1
145
145
  }
@@ -163,9 +163,10 @@ module Organism
163
163
  end
164
164
 
165
165
  lines.each{|l|
166
- ids_per_type = l.split(/\t/)
166
+ ids_per_type = Open.fields(l)
167
167
  formats.zip(ids_per_type).each{|p|
168
168
  format = p[0]
169
+ p[1] ||= ""
169
170
  ids = p[1].split(/\|/)
170
171
  ids.each{|id|
171
172
  next if id.nil? || id == ""
@@ -18,8 +18,18 @@ module Polysearch
18
18
 
19
19
  @@indexes = {}
20
20
  def self.type_index(type) #:nodoc:
21
- @@indexes[type] ||= RegExpNER.new(File.join(Rbbt.datadir,'dbs','polysearch',type.to_s + '.txt'))
22
- #@@indexes[type] ||= DictionaryNER.new(File.join(Rbbt.datadir,'dbs','polysearch',type + '.txt'))
21
+ if $stopwords
22
+ stopwords = $stopwords
23
+ else
24
+ stopwords = []
25
+ end
26
+
27
+ case type.to_sym
28
+ when :disease
29
+ stopwords << 'use'
30
+ end
31
+
32
+ @@indexes[type] ||= RegExpNER.new(File.join(Rbbt.datadir,'dbs','polysearch',type.to_s + '.txt'), :stopwords => stopwords)
23
33
  end
24
34
 
25
35
  # Find matches in a string of text, the types array specifies which thesauri
@@ -36,6 +36,9 @@ module Index
36
36
  class << index; self; end.instance_eval{
37
37
  alias_method :old_get, :[]
38
38
  define_method(:[], proc{|key| old_get(key.to_s.downcase)})
39
+
40
+ alias_method :old_values_at, :values_at
41
+ define_method(:values_at, proc{|*keys| old_values_at(*keys.collect{|key| key.to_s.downcase }) })
39
42
  }
40
43
  end
41
44
 
@@ -4,7 +4,7 @@ require 'rbbt/util/open'
4
4
  class String
5
5
  CONSONANTS = []
6
6
  if File.exists? File.join(Rbbt.datadir, 'wordlists/consonants')
7
- Open.read(File.join(Rbbt.datadir, 'wordlists/consonants')).each_line{|l| CONSONANTS << l.chomp}
7
+ Object::Open.read(File.join(Rbbt.datadir, 'wordlists/consonants')).each_line{|l| CONSONANTS << l.chomp}
8
8
  end
9
9
 
10
10
  # Uses heuristics to checks if a string seems like a special word, like a gene name.
@@ -1,11 +1,19 @@
1
- require 'rbbt/util/tmpfile'
2
1
  require 'rbbt'
2
+ require 'rbbt/util/tmpfile'
3
3
 
4
4
 
5
5
  # Provides with a few helper functions to read and write files, as well # as
6
6
  # for accessing remote files. It supports caching the files.
7
7
  module Open
8
8
 
9
+ def self.fields(line, sep = "\t")
10
+ chunks = line.chomp.split(/(#{sep})/).select{|c| c !~ /^#{sep}$/ }
11
+ if line =~ /#{sep}$/
12
+ chunks << ""
13
+ end
14
+ chunks
15
+ end
16
+
9
17
  class DirectoryNotFoundError < StandardError; end
10
18
 
11
19
  private
@@ -165,19 +173,19 @@ module Open
165
173
  l = fix.call(l) if fix
166
174
  next if exclude and exclude.call(l)
167
175
 
168
- parts = l.chomp.split(/#{sep}/)
169
- id = parts[native]
176
+ row_fields = self.fields(l, sep)
177
+ id = row_fields[native]
170
178
  next if id.nil? || id == ""
171
179
 
172
180
  data[id] ||= []
173
181
  if extra
174
182
  fields = extra
175
183
  else
176
- fields = (0..(parts.length - 1)).to_a - [native]
184
+ fields = (0..(row_fields.length - 1)).to_a - [native]
177
185
  end
178
186
  fields.each_with_index{|pos,i|
179
187
  data[id][i] ||= []
180
- data[id][i] << parts[pos]
188
+ data[id][i] << row_fields[pos]
181
189
  }
182
190
  }
183
191
 
@@ -1,18 +1,67 @@
1
- def step(name, previous = nil, &block)
2
- re = Regexp.new(/(?:^|\/)#{name}\/.*$/)
1
+ require 'rake'
3
2
 
4
- $step_descriptions ||= {}
5
- if Rake.application.last_description
6
- $step_descriptions[re] = {:step => name, :message => Rake.application.last_description}
7
- Rake.application.last_description = nil
3
+ module Rake::Pipeline
4
+
5
+ def step_def(*args)
6
+ Rake::Pipeline::Step.step_def(*args)
7
+ end
8
+
9
+ def step_descriptions
10
+ Rake::Pipeline::Step.step_descriptions
11
+ end
12
+
13
+ def infile(t, &block)
14
+ File.open(t.prerequisites.first)do |f|
15
+ block.call(f)
16
+ end
8
17
  end
9
18
 
10
- if previous.nil?
11
- deps = []
12
- else
13
- deps = lambda{|filename| filename.sub(name.to_s, previous.to_s)}
19
+ def outfile(t, &block)
20
+ File.open(t.name, 'w')do |f|
21
+ block.call(f)
22
+ end
23
+ end
24
+
25
+
26
+ end
27
+
28
+ module Rake::Pipeline::Step
29
+
30
+ class << self
31
+ @@step_descriptions = {}
32
+ def step_descriptions
33
+ @@step_descriptions
34
+ end
35
+
36
+ def add_description(re, step, message)
37
+ @@step_descriptions[re] = "#{ step }: #{ message }"
38
+ end
39
+
40
+ def step_def(name, dependencies = nil)
41
+
42
+ re = Regexp.new(/(?:^|\/)#{name}\/.*$/)
43
+ re = Regexp.new(/#{name}\/.*/)
44
+
45
+ # Take the last_description and associate it with the name
46
+ if Rake.application.last_description
47
+ add_description(re, name, Rake.application.last_description)
48
+ end
49
+
50
+
51
+ # Generate the Hash definition
52
+ case
53
+ when dependencies.nil?
54
+ re
55
+ when String === dependencies || Symbol === dependencies
56
+ {re => lambda{|filename| filename.sub(name.to_s,dependencies.to_s) }}
57
+ when Array === dependencies
58
+ {re => lambda{|filename| dependencies.collect{|dep| filename.sub(name.to_s, dep.to_s) } }}
59
+ when Proc === dependencies
60
+ {re => dependencies}
61
+ end
62
+ end
14
63
  end
15
64
 
16
- Rake.application.create_rule(re => deps, &block)
17
65
  end
18
66
 
67
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-08 00:00:00 +01:00
12
+ date: 2009-12-16 00:00:00 +01:00
13
13
  default_executable: rbbt_config
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency