Module: PubMed
- Defined in:
- lib/rbbt/sources/pubmed.rb
Overview
This module offers an interface with PubMed, to perform queries, and retrieve simple information from articles. It uses the caching services of Rbbt.
Defined Under Namespace
Classes: Article
Class Method Summary collapse
-
.get_article(pmid) ⇒ Object
Returns the Article object containing the information for the PubMed ID specified as an argument.
-
.query(query, retmax = nil) ⇒ Object
Performs the specified query and returns an array with the PubMed Ids returned.
Class Method Details
.get_article(pmid) ⇒ Object
Returns the Article object containing the information for the PubMed ID specified as an argument. If pmid
is an array instead of a single identifier it returns an hash with the Article object for each id. It uses the Rbbt cache to save the articles xml.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/rbbt/sources/pubmed.rb', line 201 def self.get_article(pmid) if pmid.is_a? Array missing = [] list = {} pmid.each{|p| filename = p.to_s + '.xml' if File.exists? FileCache.path(filename) list[p] = Article.new(Open.read(FileCache.path(filename))) else missing << p end } return list unless missing.any? articles = get_online(missing) articles.each{|p, xml| filename = p + '.xml' FileCache.add(filename,xml) list[p] = Article.new(xml) } return list else filename = pmid.to_s + '.xml' if File.exists? FileCache.path(filename) return Article.new(Open.read(FileCache.path(filename))) else xml = get_online(pmid) FileCache.add(filename,xml) return Article.new(xml) end end end |
.query(query, retmax = nil) ⇒ Object
Performs the specified query and returns an array with the PubMed Ids returned. retmax
can be used to limit the number of ids returned, if is not specified 30000 is used.
245 246 247 248 249 |
# File 'lib/rbbt/sources/pubmed.rb', line 245 def self.query(query, retmax=nil) retmax ||= 30000 Open.read("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?retmax=#{retmax}&db=pubmed&term=#{query}",:quiet => true, :nocache => true).scan(/<Id>(\d+)<\/Id>/).flatten end |