class GemanticScholar::Paper

Attributes

paper_data[RW]

Public Class Methods

new(paper_id, id_type) click to toggle source
# File lib/gemantic_scholar.rb, line 9
def initialize(paper_id, id_type)
  @paper_data = JSON.parse(fetch_paper(paper_id, id_type))
end

Public Instance Methods

abstract() click to toggle source
# File lib/gemantic_scholar.rb, line 13
def abstract
  paper_data['abstract']
end
arxiv_id() click to toggle source
# File lib/gemantic_scholar.rb, line 17
def arxiv_id
  paper_data['arxivId']
end
authors() click to toggle source
# File lib/gemantic_scholar.rb, line 21
def authors
  paper_data['authors']
end
citations() click to toggle source
# File lib/gemantic_scholar.rb, line 25
def citations
  paper_data['citations']
end
doi() click to toggle source
# File lib/gemantic_scholar.rb, line 29
def doi
  paper_data['doi']
end
fetch_paper(paper_id, id_type) click to toggle source
# File lib/gemantic_scholar.rb, line 69
def fetch_paper(paper_id, id_type)
  if id_type == 'arxiv'
    id_param = "arXiv:#{paper_id}"
  elsif id_type == 'mag'
    id_param = "MAG:#{paper_id}"
  elsif id_type == 'acl'
    id_param = "ACL:#{paper_id}"
  elsif id_type == 'pubmed'
    id_param = "PMID:#{paper_id}"
  elsif id_type == 'corpus'
    id_param = "CorpusID:#{paper_id}"
  else
    id_param = paper_id
  end
  uri = URI("https://api.semanticscholar.org/v1/paper/#{id_param}?include_unknown_references=true")
  rsp = Net::HTTP.get_response(uri)
  if rsp.code == '404'
    return '["404: No paper found"]'
  else
    return rsp.body
  end
end
intent() click to toggle source
# File lib/gemantic_scholar.rb, line 45
def intent
  paper_data['intent']
end
publisher() click to toggle source
# File lib/gemantic_scholar.rb, line 57
def publisher
  paper_data['venue']
end
references() click to toggle source
# File lib/gemantic_scholar.rb, line 33
def references
  paper_data['references']
end
semscholar_id() click to toggle source
# File lib/gemantic_scholar.rb, line 61
def semscholar_id
  paper_data['paperId']
end
title() click to toggle source
# File lib/gemantic_scholar.rb, line 41
def title
  paper_data['title']
end
topics() click to toggle source
# File lib/gemantic_scholar.rb, line 49
def topics
  paper_data['topics']
end
venue() click to toggle source
# File lib/gemantic_scholar.rb, line 65
def venue
  self.publisher
end
works_cited() click to toggle source
# File lib/gemantic_scholar.rb, line 37
def works_cited
  self.references
end
year() click to toggle source
# File lib/gemantic_scholar.rb, line 53
def year
  paper_data['year']
end