Module: Document::Corpus
- Defined in:
- lib/rbbt/document/corpus.rb,
lib/rbbt/document/corpus/pubmed.rb
Class Attribute Summary collapse
-
.claims ⇒ Object
Returns the value of attribute claims.
Class Method Summary collapse
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #add_document(document) ⇒ Object
- #add_pmid(pmid, type = nil) ⇒ Object
- #add_pubmed_query(query, max = 3000, type = nil) ⇒ Object
Class Attribute Details
.claims ⇒ Object
Returns the value of attribute claims.
31 32 33 |
# File 'lib/rbbt/document/corpus.rb', line 31 def claims @claims end |
Class Method Details
.claim(namespace, &block) ⇒ Object
32 33 34 35 |
# File 'lib/rbbt/document/corpus.rb', line 32 def claim(namespace, &block) @claims = {} @claims[namespace.to_s] = block end |
Instance Method Details
#[](*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rbbt/document/corpus.rb', line 13 def [](*args) docid, *rest = args res = super(*args) return res if args.length > 1 namespace, id, type = docid.split(":") if res.nil? if Document::Corpus.claims.include?(namespace.to_s) res = self.instance_exec(id, type, &Document::Corpus.claims[namespace.to_s]) end end Document.setup(res, namespace, id, type, self) unless res.nil? res end |
#add_document(document) ⇒ Object
9 10 11 |
# File 'lib/rbbt/document/corpus.rb', line 9 def add_document(document) self[document.docid] = document end |
#add_pmid(pmid, type = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbbt/document/corpus/pubmed.rb', line 4 def add_pmid(pmid, type = nil) pmids = Array === pmid ? pmid : [pmid] type = nil if String === type and type.empty? res = PubMed.get_article(pmids).collect do |pmid, article| Log.debug "Loading pmid #{pmid}" document = if type.nil? || type.to_sym == :abstract Document.setup(article.abstract || "", "PMID", pmid, :abstract, self, :corpus => self) elsif type.to_sym == :title Document.setup(article.title, :PMID, pmid, :title, self) else raise "No FullText available for #{ pmid }" if article.full_text.nil? Document.setup(article.full_text, :PMID, pmid, :fulltext, self, :corpus => self) end add_document(document) end Document.setup(res) end |
#add_pubmed_query(query, max = 3000, type = nil) ⇒ Object
24 25 26 27 |
# File 'lib/rbbt/document/corpus/pubmed.rb', line 24 def add_pubmed_query(query, max = 3000, type = nil) pmids = PubMed.query(query, max) add_pmid(pmids, type) end |