Module: PaperMetadata

Defined in:
lib/paper_metadata.rb,
lib/paper_metadata/version.rb

Constant Summary collapse

VERSION =
"0.0.5"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.doi_usernameObject

Returns the value of attribute doi_username.



11
12
13
# File 'lib/paper_metadata.rb', line 11

def doi_username
  @doi_username
end

Class Method Details

.metadata_for(identifier) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/paper_metadata.rb', line 18

def (identifier)
  if identifier =~ /^arxiv\:(.*)/i
    ($1.strip)
  elsif identifier =~ /^doi\:\s*(10\.6084\/.*)/i
    ($1.strip)
  elsif identifier =~ /^doi\:(.*)/i
    ($1.strip)
  end
end

.metadata_for_arxiv(identifier) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/paper_metadata.rb', line 89

def (identifier)
  identifier.gsub!(/^arXiv\:/i, '')
  url = URI.parse("http://export.arxiv.org/api/query?search_query=#{CGI.escape(identifier)}&start=0&max_results=1")
  res = Net::HTTP.get_response(url)
  doc = Nokogiri::XML(res.body)
  doc.remove_namespaces!
  paper = Hash.new
  if entry = doc.xpath("//entry").first
    paper[:title] = entry.xpath('title').text
    paper[:authors] = entry.xpath('author').text.split("\n").map{|a| a.strip if a.strip != ""}.compact.join(', ')
    paper[:id] = entry.xpath('id').text
    paper[:updated] = entry.xpath('updated').text
    paper[:summary] = entry.xpath('summary').text
    paper[:published] = entry.xpath('published').text
    paper[:journal] = 'arXiv'
  end
  paper
end

.metadata_for_doi(doi) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/paper_metadata.rb', line 28

def (doi)
  doc = Nokogiri::XML(open("http://www.crossref.org/guestquery?queryType=doi&restype=unixref&doi=#{URI.escape(doi)}&doi_search=Search"))
  paper = Hash.new

  doc = doc.css('table[name=doiresult]').first

  if doc.xpath("//titles/title").first
    paper[:volume] = doc.xpath("//journal_issue/journal_volume/volume").inner_html.to_s
    paper[:isssue] = doc.xpath("//journal_issue/issue").inner_html.to_s
    paper[:first_page] = doc.xpath("//pages/first_page").inner_html.to_s
    paper[:last_page] = doc.xpath("//pages/last_page").inner_html.to_s
    paper[:title] = doc.xpath("//titles/title").inner_html.to_s
    paper[:authors] = doc.xpath("//contributors/person_name").
      map{ |author| author.content.strip}

    paper[:authors] = paper[:authors].map do |author|
      author.gsub(/\s+/, ' ')
    end.join(', ')

    paper[:journal] = doc.xpath("//abbrev_title").inner_html + " " +
      doc.xpath("//journal_issue/publication_date/year").first.inner_html
    paper[:resource] = doc.xpath("//journal_article/doi_data/resource").inner_html
  else
    paper = (doi)
  end
  paper
end

.metadata_for_doi_from_datacite(doi) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/paper_metadata.rb', line 56

def (doi)
  paper = {}
  response = JSON.parse(open("http://search.datacite.org/api?q=#{CGI.escape(doi)}&fl=doi,creator,title,publisher,publicationYear,datacentre&wt=json").read)
  if response && !response['response']['docs'].empty? && response['response']['docs'].first['title']
    result = response['response']['docs'].first
    paper[:title] = result['title'].first
    paper[:authors] = result['creator'].map{|c| c.split(', ').reverse.join(' ')}.join(', ')
    paper[:published] = result['publicationYear']
    paper[:publisher] = result['publisher']
    paper[:datacentre] = result['datacentre']
    paper[:journal] = 'DataCite'
    paper
  else
    {status: :NODOI}
  end
end

.metadata_for_doi_from_figshare(doi) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/paper_metadata.rb', line 73

def (doi)
  paper = {}
  response = JSON.parse(open("http://api.figshare.com/articles/#{doi}").read)

  if response && response['items'] && response['items'].first
    result = response['items'].first
    paper[:title] = result['title']
    paper[:authors] = result['authors'].map{|a| a['full_name']}.join(', ')
    paper[:published] = result['published_date']
    paper[:journal] = 'FigShare'
    paper
  else
    {status: :NODOI}
  end
end