paper_metadata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.sublime-project
19
+ *.sublime-workspace
20
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paper_metadata.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jure Triglav
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # PaperMetadata
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'paper_metadata'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install paper_metadata
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,68 @@
1
+ require 'paper_metadata/version'
2
+ require 'nokogiri'
3
+ require 'net/http'
4
+ require 'open-uri'
5
+ require 'pry'
6
+
7
+ module PaperMetadata
8
+ class << self
9
+ attr_accessor :doi_username
10
+
11
+ def doi_username
12
+ raise "PaperMetadata needs the DOI username to work with CrossRef API" unless @doi_username
13
+ @doi_username
14
+ end
15
+
16
+ def metadata_for(identifier)
17
+ if identifier =~ /^arxiv\:/i
18
+ metadata_for_arxiv(identifier)
19
+ elsif identifier =~ /^doi\:/i
20
+ metadata_for_doi(identifier)
21
+ end
22
+ end
23
+
24
+ def metadata_for_doi(doi)
25
+ doc = Nokogiri::XML(open("http://www.crossref.org/openurl/?id=doi:#{doi}&noredirect=true&pid=#{PaperMetadata.doi_username}&format=unixref"))
26
+ paper = Hash.new
27
+
28
+ if doc.xpath("//titles/title").first
29
+ paper[:volume] = doc.xpath("//journal_issue/journal_volume/volume").inner_html.to_s
30
+ paper[:isssue] = doc.xpath("//journal_issue/issue").inner_html.to_s
31
+ paper[:first_page] = doc.xpath("//pages/first_page").inner_html.to_s
32
+ paper[:last_page] = doc.xpath("//pages/last_page").inner_html.to_s
33
+ paper[:title] = doc.xpath("//titles/title").inner_html.to_s
34
+ paper[:authors] = doc.xpath("//contributors/person_name").
35
+ map{ |author| author.content.strip}
36
+
37
+ paper[:authors] = paper[:authors].map do |author|
38
+ author.gsub(/\s+/, ' ')
39
+ end.join(', ')
40
+
41
+ paper[:journal] = doc.xpath("//abbrev_title").inner_html + " " +
42
+ doc.xpath("//journal_issue/publication_date/year").first.inner_html
43
+ paper[:resource] = doc.xpath("//journal_article/doi_data/resource").inner_html
44
+ else
45
+ paper[:status] = :NODOI
46
+ end
47
+ paper
48
+ end
49
+
50
+ def metadata_for_arxiv(identifier)
51
+ identifier.gsub!(/^arXiv\:/i, '')
52
+ url = URI.parse("http://export.arxiv.org/api/query?search_query=#{identifier}&start=0&max_results=1")
53
+ res = Net::HTTP.get_response(url)
54
+ doc = Nokogiri::XML(res.body)
55
+ doc.remove_namespaces!
56
+ paper = Hash.new
57
+ if entry = doc.xpath("//entry").first
58
+ paper[:title] = entry.xpath('title').text
59
+ paper[:author] = entry.xpath('author').text.strip
60
+ paper[:id] = entry.xpath('id').text
61
+ paper[:updated] = entry.xpath('updated').text
62
+ paper[:summary] = entry.xpath('summary').text
63
+ paper[:published] = entry.xpath('published').text
64
+ end
65
+ paper
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module PaperMetadata
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'paper_metadata/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "paper_metadata"
8
+ gem.version = PaperMetadata::VERSION
9
+ gem.authors = ["Jure Triglav"]
10
+ gem.email = ["juretriglav@gmail.com"]
11
+ gem.summary = %q{Paper_metadata gem gets the metadata for papers with a DOI or an arXiv identifier}
12
+ gem.description = %q{Metadata getter for scientific papers}
13
+ gem.homepage = "http://github.com/jure/paper_metadata"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "pry"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "webmock"
23
+ gem.add_runtime_dependency "nokogiri", ["= 1.5.6"]
24
+
25
+ end
data/test/arxiv.xml ADDED
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom">
3
+ <link href="http://arxiv.org/api/query?search_query%3D1301.7746%26id_list%3D%26start%3D0%26max_results%3D1" rel="self" type="application/atom+xml"/>
4
+ <title type="html">ArXiv Query: search_query=1301.7746&amp;id_list=&amp;start=0&amp;max_results=1</title>
5
+ <id>http://arxiv.org/api/NIaVv86zj4leHWkr6xTS1LwRjlw</id>
6
+ <updated>2013-02-02T00:00:00-05:00</updated>
7
+ <opensearch:totalResults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:totalResults>
8
+ <opensearch:startIndex xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">0</opensearch:startIndex>
9
+ <opensearch:itemsPerPage xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:itemsPerPage>
10
+ <entry>
11
+ <id>http://arxiv.org/abs/1301.7746v1</id>
12
+ <updated>2013-01-31T20:46:12Z</updated>
13
+ <published>2013-01-31T20:46:12Z</published>
14
+ <title>Phases and phase transitions in disordered quantum systems</title>
15
+ <summary> These lecture notes give a pedagogical introduction to phase transitions in
16
+ disordered quantum systems and to the exotic Griffiths phases induced in their
17
+ vicinity. We first review some fundamental concepts in the physics of phase
18
+ transitions. We then derive criteria governing under what conditions spatial
19
+ disorder or randomness can change the properties of a phase transition. After
20
+ introducing the strong-disorder renormalization group method, we discuss in
21
+ detail some of the exotic phenomena arising at phase transitions in disordered
22
+ quantum systems. These include infinite-randomness criticality, rare regions
23
+ and quantum Griffiths singularities, as well as the smearing of phase
24
+ transitions. We also present a number of experimental examples.
25
+ </summary>
26
+ <author>
27
+ <name>Thomas Vojta</name>
28
+ </author>
29
+ <arxiv:comment xmlns:arxiv="http://arxiv.org/schemas/atom">Pedagogical introduction to strong disorder physics at quantum phase
30
+ transitions. Based on lectures given at the XVII Training Course in the
31
+ Physics of Strongly Correlated Systems in Vietri sul Mare, Italy in October
32
+ 2012. Submitted to the proceedings of this school. 60 pages and 23 figures.
33
+ Builds on material reviewed in arXiv:cond-mat/0602312 and arXiv:1005.2707</arxiv:comment>
34
+ <link href="http://arxiv.org/abs/1301.7746v1" rel="alternate" type="text/html"/>
35
+ <link title="pdf" href="http://arxiv.org/pdf/1301.7746v1" rel="related" type="application/pdf"/>
36
+ <arxiv:primary_category xmlns:arxiv="http://arxiv.org/schemas/atom" term="cond-mat.dis-nn" scheme="http://arxiv.org/schemas/atom"/>
37
+ <category term="cond-mat.dis-nn" scheme="http://arxiv.org/schemas/atom"/>
38
+ <category term="cond-mat.str-el" scheme="http://arxiv.org/schemas/atom"/>
39
+ </entry>
40
+ </feed>
data/test/doi.xml ADDED
@@ -0,0 +1,59 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <doi_records>
3
+ <doi_record owner="10.1021" timestamp="2011-05-21 00:52:16">
4
+ <crossref>
5
+ <journal>
6
+ <journal_metadata language="en">
7
+ <full_title>Analytical Chemistry</full_title>
8
+ <abbrev_title>Anal. Chem.</abbrev_title>
9
+ <issn media_type="print">0003-2700</issn>
10
+ <issn media_type="electronic">1520-6882</issn>
11
+ </journal_metadata>
12
+ <journal_issue>
13
+ <publication_date media_type="print">
14
+ <month>10</month>
15
+ <year>2010</year>
16
+ </publication_date>
17
+ <journal_volume>
18
+ <volume>82</volume>
19
+ </journal_volume>
20
+ <issue>19</issue>
21
+ </journal_issue>
22
+ <journal_article publication_type="full_text">
23
+ <titles>
24
+ <title>Basic Modeling Approach To Optimize Elemental Imaging by Laser Ablation ICPMS</title>
25
+ </titles>
26
+ <contributors>
27
+ <person_name sequence="first" contributor_role="author">
28
+ <given_name>Jure</given_name>
29
+ <surname>Triglav</surname>
30
+ </person_name>
31
+ <person_name sequence="additional" contributor_role="author">
32
+ <given_name>Johannes T.</given_name>
33
+ <surname>van Elteren</surname>
34
+ </person_name>
35
+ <person_name sequence="additional" contributor_role="author">
36
+ <given_name>Vid S.</given_name>
37
+ <surname>Šelih</surname>
38
+ </person_name>
39
+ </contributors>
40
+ <publication_date media_type="print">
41
+ <month>10</month>
42
+ <year>2010</year>
43
+ </publication_date>
44
+ <pages>
45
+ <first_page>8153</first_page>
46
+ <last_page>8160</last_page>
47
+ </pages>
48
+ <publisher_item>
49
+ <identifier id_type="doi">10.1021/ac1014832</identifier>
50
+ </publisher_item>
51
+ <doi_data>
52
+ <doi>10.1021/ac1014832</doi>
53
+ <resource>http://pubs.acs.org/doi/abs/10.1021/ac1014832</resource>
54
+ </doi_data>
55
+ </journal_article>
56
+ </journal>
57
+ </crossref>
58
+ </doi_record>
59
+ </doi_records>
@@ -0,0 +1 @@
1
+ require 'webmock/test_unit'
@@ -0,0 +1,34 @@
1
+ require 'test/unit'
2
+ require 'paper_metadata'
3
+ require 'test_helper'
4
+
5
+ class PaperMetadataTest < Test::Unit::TestCase
6
+ def test_doi_parsing
7
+
8
+ doi_response = File.read(File.join(File.dirname(__FILE__), 'doi.xml'))
9
+ stub_request(:any, /www.crossref.org\/.*/).
10
+ to_return(:body => doi_response, :status => 200, :headers => { 'Content-Length' => doi_response.length } )
11
+
12
+ PaperMetadata.doi_username = 'test@example.com'
13
+ assert_equal "Basic Modeling Approach To Optimize Elemental Imaging by Laser Ablation ICPMS",
14
+ PaperMetadata.metadata_for('doi:10.1021/ac1014832')[:title]
15
+ end
16
+
17
+ def test_fail_doi_if_no_username
18
+ doi_response = File.read(File.join(File.dirname(__FILE__), 'doi.xml'))
19
+ stub_request(:any, /www.crossref.org\/.*/).
20
+ to_return(:body => doi_response, :status => 200, :headers => { 'Content-Length' => doi_response.length } )
21
+ PaperMetadata.doi_username = nil
22
+ assert_raise RuntimeError do
23
+ PaperMetadata.metadata_for('doi:10.1021/ac1014832')
24
+ end
25
+ end
26
+
27
+ def test_arxiv_parsing
28
+ arxiv_response = File.read(File.join(File.dirname(__FILE__), 'arxiv.xml'))
29
+ stub_request(:any, /.*arxiv.org\/.*/).
30
+ to_return(:body => arxiv_response, :status => 200, :headers => { 'Content-Length' => arxiv_response.length } )
31
+ assert_equal "Thomas Vojta",
32
+ PaperMetadata.metadata_for('arXiv:1301.7746')[:author]
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paper_metadata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jure Triglav
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: nokogiri
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.6
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.6
78
+ description: Metadata getter for scientific papers
79
+ email:
80
+ - juretriglav@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .DS_Store
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - lib/paper_metadata.rb
92
+ - lib/paper_metadata/version.rb
93
+ - paper_metadata.gemspec
94
+ - test/arxiv.xml
95
+ - test/doi.xml
96
+ - test/test_helper.rb
97
+ - test/test_paper_metadata.rb
98
+ homepage: http://github.com/jure/paper_metadata
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.23
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Paper_metadata gem gets the metadata for papers with a DOI or an arXiv identifier
122
+ test_files:
123
+ - test/arxiv.xml
124
+ - test/doi.xml
125
+ - test/test_helper.rb
126
+ - test/test_paper_metadata.rb
127
+ has_rdoc: