biburi 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.mediawiki +3 -0
- data/biburi.gemspec +6 -6
- data/bin/biburi.rb +63 -0
- data/lib/biburi/driver/coins.rb +272 -0
- data/lib/biburi/driver/doi.rb +31 -98
- data/lib/biburi/driver.rb +3 -1
- data/lib/biburi/version.rb +1 -1
- data/lib/biburi.rb +2 -4
- data/spec/biburi_spec.rb +129 -16
- data/spec/doi_spec.rb +10 -20
- metadata +30 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5826c0467c0aa9d64cd79d4347eb09811e81b4aa
|
4
|
+
data.tar.gz: 707baa6b8b9bda043ec66f9a05606819e142f52e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0fbed4417f1903c3ed9f0aa38407ec80e952458c293334db4fbfde99562a108971f3bd3f0d1e4ea99def2aef86568346ba2f06ca62088e38e7316ea5a63822
|
7
|
+
data.tar.gz: 322a876c1a113d12aaf4e96f11505d952aa7aa342fa59a11f07d070e6fb023c5ac86c556cbd3b4b68ca6fe63b19c89f14ede7ca5b0d207ac8ae6f53661159a7c
|
data/CHANGELOG.mediawiki
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
= BibURI Changelog =
|
2
2
|
|
3
|
+
* 0.1.0 (October 4, 2013)
|
4
|
+
** MAJOR CHANGE: lookup() now returns a single BibTeX::Entry object, instead of an Array. One driver supports lookup_all() to return all entries.
|
5
|
+
|
3
6
|
* 0.0.1 (October 2, 2013)
|
4
7
|
** First release, with basic support for DOIs using the CrossRef API.
|
data/biburi.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler", "~>
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "coveralls"
|
21
|
+
spec.add_development_dependency "bundler", "~>1.3.5"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
24
|
+
spec.add_development_dependency "coveralls", "~> 0.7.0"
|
26
25
|
|
27
|
-
spec.add_runtime_dependency 'bibtex-ruby', '~> 2.
|
26
|
+
spec.add_runtime_dependency 'bibtex-ruby', '~> 2.3.4'
|
27
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6.0'
|
28
28
|
end
|
data/bin/biburi.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# A binary to access BibURI from the command line.
|
5
|
+
#
|
6
|
+
require 'biburi'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
# Command line options
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
# Reads command line arguments and figures out what to run.
|
13
|
+
def main
|
14
|
+
# Process command line options.
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.banner = "Usage: biburi [arguments] [uri]\n\n" +
|
17
|
+
"biburi can read any number of URIs in its arguments.\n" +
|
18
|
+
"If no URI is provided, biburi will read URIs from STDIN\nand return one BibTeX citation per input line."
|
19
|
+
|
20
|
+
opts.separator ""
|
21
|
+
|
22
|
+
# Documentary stuff.
|
23
|
+
opts.on("-h", "--help", "Show this message") do
|
24
|
+
puts opts
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-v", "--[no-]verbose", "Produce verbose output") do |v|
|
28
|
+
options[:verbose] = v
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.separator ""
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
# Do we have command line argument URIs?
|
35
|
+
if !ARGV.empty? then
|
36
|
+
ARGV.each do |uri|
|
37
|
+
uri_to_bibtex(uri)
|
38
|
+
end
|
39
|
+
else
|
40
|
+
# If not, open STDIN and process that instead.
|
41
|
+
lines = STDIN.readlines
|
42
|
+
lines.each do |line|
|
43
|
+
line.chomp!
|
44
|
+
uri_to_bibtex(line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Returns a URI as BibTeX thanks to the magic of BibURI.
|
50
|
+
def uri_to_bibtex(uri)
|
51
|
+
entry = BibURI::lookup(uri)
|
52
|
+
if entry.nil? then
|
53
|
+
entry = BibTeX::Entry.new(
|
54
|
+
:title => uri,
|
55
|
+
:identifiers => uri
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
puts entry.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
# Start execution
|
63
|
+
main()
|
@@ -0,0 +1,272 @@
|
|
1
|
+
# A driver to read BibTeX from web pages by reading
|
2
|
+
# in COinS on that page. Find out more about COinS
|
3
|
+
# at: http://ocoins.info/
|
4
|
+
#
|
5
|
+
# Author:: Gaurav Vaidya
|
6
|
+
# Copyright:: Copyright (c) 2013 Gaurav Vaidya
|
7
|
+
# License:: MIT
|
8
|
+
|
9
|
+
require 'biburi'
|
10
|
+
require 'biburi/driver'
|
11
|
+
require 'net/http'
|
12
|
+
require 'json'
|
13
|
+
require 'bibtex'
|
14
|
+
require 'uri'
|
15
|
+
require 'nokogiri'
|
16
|
+
require 'cgi'
|
17
|
+
|
18
|
+
# This driver reads COinS citations in an HTML
|
19
|
+
# page and returns them. It defaults to returning
|
20
|
+
# a single citation, but can be used to return all
|
21
|
+
# citations.
|
22
|
+
|
23
|
+
module BibURI::Driver::COinS
|
24
|
+
include BibURI::Driver
|
25
|
+
|
26
|
+
# We support an identifier if we can make them look
|
27
|
+
# canonical.
|
28
|
+
def self.supported?(id)
|
29
|
+
canonical = self.canonical(id)
|
30
|
+
return !(canonical.nil?)
|
31
|
+
end
|
32
|
+
|
33
|
+
# The canonical form of this identifier is the
|
34
|
+
# normalized URI, IF it has a scheme of 'http'
|
35
|
+
# or 'https'.
|
36
|
+
def self.canonical(id)
|
37
|
+
uri = URI.parse(id)
|
38
|
+
|
39
|
+
unless uri.scheme == 'http' || uri.scheme == 'https'
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
return uri.to_s
|
44
|
+
|
45
|
+
rescue URI::InvalidURIError
|
46
|
+
# If there is an error in the URI, it is not an identifier.
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a list of parsed values with
|
51
|
+
# BibTeX names by looking up the provided id (a URL).
|
52
|
+
#
|
53
|
+
# This will call self.lookup_all(), and then only
|
54
|
+
# return the first match. For pages like Mendeley, this is
|
55
|
+
# necessary to avoid pulling in 'related to' citations
|
56
|
+
# or to pull in all entries.
|
57
|
+
def self.lookup(id)
|
58
|
+
self.lookup_all(id) do |first_only|
|
59
|
+
return first_only
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# This method returns ALL COinS on this page. For Mendeley,
|
64
|
+
# this will return the pages' COinS as well as all related
|
65
|
+
# papers. Use self.lookup() to find a single one.
|
66
|
+
def self.lookup_all(id)
|
67
|
+
# Calculate the canonical identifier.
|
68
|
+
url = canonical(id)
|
69
|
+
if url.nil? then
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# Retrieve the HTML.
|
74
|
+
content = Net::HTTP.get(URI(url))
|
75
|
+
doc = Nokogiri::HTML(content)
|
76
|
+
spans = doc.css('span.Z3988')
|
77
|
+
|
78
|
+
# Go through results and format them as BibTeX::Entry.
|
79
|
+
# We support both
|
80
|
+
results = [] unless block_given?
|
81
|
+
|
82
|
+
spans.each do |span|
|
83
|
+
coins = span['title']
|
84
|
+
|
85
|
+
bibentry = self.coins_to_bibtex(coins)
|
86
|
+
|
87
|
+
# Set identifiers so we know where this came from.
|
88
|
+
bibentry[:url] = url
|
89
|
+
|
90
|
+
identifiers = bibentry[:identifiers].split("\n")
|
91
|
+
identifiers.push(url)
|
92
|
+
bibentry.add(:identifiers, identifiers.join("\n"))
|
93
|
+
|
94
|
+
# See if we have a DOI.
|
95
|
+
identifiers.each do |identifier|
|
96
|
+
match = identifier.match(/^(?:http:\/\/dx\.doi\.org\/|doi:|info:doi\/)(.*)$/i)
|
97
|
+
if match then
|
98
|
+
bibentry[:doi] = match[1]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Yield values or return array.
|
103
|
+
if block_given? then
|
104
|
+
yield(bibentry)
|
105
|
+
else
|
106
|
+
results.push(bibentry)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# If we built an array, return it.
|
111
|
+
unless block_given? then
|
112
|
+
return results
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Converts a COinS string to a BibTeX entry.
|
117
|
+
def self.coins_to_bibtex(coins)
|
118
|
+
# Create a BibTeX entry to store these values.
|
119
|
+
bibentry = BibTeX::Entry.new
|
120
|
+
|
121
|
+
# If we have COinS data, we have a lot more data.
|
122
|
+
coins_kv = CGI::parse(coins)
|
123
|
+
metadata = {}
|
124
|
+
coins_kv.each do |key, val|
|
125
|
+
if val.length == 1 then
|
126
|
+
metadata[key] = val[0]
|
127
|
+
else
|
128
|
+
metadata[key] = val
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# COinS values are explained at http://ocoins.info/cobg.html
|
133
|
+
# and in http://ocoins.info/cobgbook.html.
|
134
|
+
|
135
|
+
# If we're not Z3988-2004, skip out.
|
136
|
+
ctx_ver = metadata['ctx_ver']
|
137
|
+
if ctx_ver != 'Z39.88-2004' then
|
138
|
+
ctx_ver = "" if ctx_ver.nil?
|
139
|
+
raise "ctx_ver is: '#{ctx_ver}'"
|
140
|
+
end
|
141
|
+
|
142
|
+
# Add ALL the identifiers.
|
143
|
+
bibentry[:identifiers] = ""
|
144
|
+
if metadata.key?('rft_id') then
|
145
|
+
if metadata['rft_id'].kind_of?(Array) then
|
146
|
+
bibentry[:identifiers] = metadata['rft_id'].join("\n")
|
147
|
+
else
|
148
|
+
bibentry[:identifiers] = metadata['rft_id']
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# COinS supports some types
|
153
|
+
genre = metadata['rft.genre']
|
154
|
+
if genre == 'article' then
|
155
|
+
bibentry.type = "article"
|
156
|
+
elsif genre == 'book' then
|
157
|
+
bibentry.type = "book"
|
158
|
+
elsif genre == 'bookitem' then
|
159
|
+
bibentry.type = "inbook"
|
160
|
+
elsif genre == 'proceeding' then
|
161
|
+
bibentry.type = "proceedings"
|
162
|
+
elsif genre == 'conference' then
|
163
|
+
bibentry.type = "inproceedings"
|
164
|
+
elsif genre == 'report' then
|
165
|
+
bibentry.type = "techreport"
|
166
|
+
end
|
167
|
+
|
168
|
+
# Journal title: title, jtitle
|
169
|
+
journal_title = metadata['rft.title'] # The old-style journal title.
|
170
|
+
journal_title ||= metadata['rft.stitle'] # An abbreviated title.
|
171
|
+
journal_title ||= metadata['rft.jtitle'] # Complete title.
|
172
|
+
bibentry[:journal] = journal_title
|
173
|
+
|
174
|
+
# Book title: btitle
|
175
|
+
if metadata.key?('rft.btitle')
|
176
|
+
if journal_title
|
177
|
+
bibentry[:booktitle] = metadata['rft.btitle']
|
178
|
+
else
|
179
|
+
bibentry[:title] = metadata['rft.btitle']
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# Pages: spage, epage
|
184
|
+
pages = metadata['rft.pages'] # If only pages are provided
|
185
|
+
|
186
|
+
# Expand a single dash to a BibTeX-y double-dash.
|
187
|
+
pages.gsub!(/([^\-])\-([^\-])/, '\1--\2') unless pages.nil?
|
188
|
+
|
189
|
+
pages ||= metadata['rft.spage'] + "--" + metadata['rft.epage']
|
190
|
+
# If we have start and end pages
|
191
|
+
bibentry[:pages] = pages
|
192
|
+
|
193
|
+
# Authors are all in 'rft.au'
|
194
|
+
authors = []
|
195
|
+
metadata['rft.au'] = [ metadata['rft.au'] ] unless metadata['rft.au'].kind_of?(Array)
|
196
|
+
metadata['rft.au'].each do |author|
|
197
|
+
authors.push(BibTeX::Name.parse(author)) unless author.nil?
|
198
|
+
end
|
199
|
+
|
200
|
+
# However! Sometimes a name is in aufirst/aulast
|
201
|
+
# and also in au; and sometimes it's only in aufirst/aulast.
|
202
|
+
first_author = BibTeX::Name.new
|
203
|
+
first_author.last = metadata['rft.aulast']
|
204
|
+
first_author.suffix = metadata['rft.ausuffix'] if metadata.key?('rft.ausuffix')
|
205
|
+
if metadata.key?('rft.aufirst') then
|
206
|
+
first_author.first = metadata['rft.aufirst']
|
207
|
+
elsif metadata.key?('rft.auinit') then
|
208
|
+
first_author.first = metadata['rft.auinit']
|
209
|
+
elsif
|
210
|
+
first_author.first = metadata['rft.auinit1']
|
211
|
+
first_author.first += " " + metadata['rftinitm'] if metadata.key?('rftinitm')
|
212
|
+
end
|
213
|
+
if !authors.include?(first_author) then
|
214
|
+
authors.unshift(first_author)
|
215
|
+
end
|
216
|
+
|
217
|
+
bibentry[:author] = BibTeX::Names.new(authors)
|
218
|
+
|
219
|
+
# Dates.
|
220
|
+
date = metadata['rft.date']
|
221
|
+
bibentry[:date] = date
|
222
|
+
|
223
|
+
# Citeulike dates are easy to parse.
|
224
|
+
unless date.nil? then
|
225
|
+
if match = date.match(/^(\d{4})$/) then
|
226
|
+
bibentry[:year] = match[1]
|
227
|
+
|
228
|
+
elsif match = date.match(/^(\d{4})-(\d{1,2})$/) then
|
229
|
+
bibentry[:year] = match[1]
|
230
|
+
bibentry[:month] = match[2]
|
231
|
+
|
232
|
+
elsif match = date.match(/^(\d{4})-(\d{1,2})-(\d{1,2})$/) then
|
233
|
+
bibentry[:year] = match[1]
|
234
|
+
bibentry[:month] = match[2]
|
235
|
+
bibentry[:day] = match[3]
|
236
|
+
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
# Map remaining fields to BibTeX.
|
241
|
+
standard_mappings = {
|
242
|
+
"rft.atitle" => "title",
|
243
|
+
"rft.volume" => "volume",
|
244
|
+
"rft.issue" => "number",
|
245
|
+
"rft.artnum" => "article_number",
|
246
|
+
"rft.issn" => "issn",
|
247
|
+
"rft.eissn" => "eissn",
|
248
|
+
"rft.isbn" => "isbn",
|
249
|
+
"rft.coden" => "CODEN",
|
250
|
+
"rft.sici" => "SICI",
|
251
|
+
"rft.chron" => "chronology",
|
252
|
+
"rft.ssn" => "season",
|
253
|
+
"rft.quarter" => "quarter",
|
254
|
+
"rft.part" => "part",
|
255
|
+
|
256
|
+
"rft.place" => "address",
|
257
|
+
"rft.pub" => "publisher",
|
258
|
+
"rft.edition" => "edition",
|
259
|
+
"rft.tpages" => "total_pages",
|
260
|
+
"rft.series" => "series",
|
261
|
+
"rft.bici" => "bici"
|
262
|
+
}
|
263
|
+
|
264
|
+
standard_mappings.keys.each do |field|
|
265
|
+
if metadata.key?(field) then
|
266
|
+
bibentry[standard_mappings[field]] = metadata[field]
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
return bibentry
|
271
|
+
end
|
272
|
+
end
|
data/lib/biburi/driver/doi.rb
CHANGED
@@ -7,13 +7,11 @@
|
|
7
7
|
|
8
8
|
require 'biburi'
|
9
9
|
require 'biburi/driver'
|
10
|
+
require 'biburi/driver/coins'
|
10
11
|
require 'net/http'
|
11
12
|
require 'json'
|
12
13
|
require 'bibtex'
|
13
14
|
|
14
|
-
# For CGI::parse to make sense of COinS
|
15
|
-
require 'cgi'
|
16
|
-
|
17
15
|
# This driver provides information in BibTeX on a DOI by
|
18
16
|
# querying CrossRef's metadata search API.
|
19
17
|
|
@@ -72,103 +70,38 @@ module BibURI::Driver::DOI
|
|
72
70
|
# Go through results and format them as BibTeX::Entry.
|
73
71
|
# We support both
|
74
72
|
results = [] unless block_given?
|
75
|
-
as_json.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
if val.length == 1 then
|
101
|
-
metadata[key] = val[0]
|
102
|
-
else
|
103
|
-
metadata[key] = val
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# COinS values are explained at http://ocoins.info/cobg.html
|
108
|
-
# Some values need to be handled separately.
|
109
|
-
|
110
|
-
# Journal title: title, jtitle
|
111
|
-
journal_title = metadata['rft.title'] # The old-style journal title.
|
112
|
-
journal_title ||= metadata['rft.stitle'] # An abbreviated title.
|
113
|
-
journal_title ||= metadata['rft.jtitle'] # Complete title.
|
114
|
-
bibentry[:journal] = journal_title
|
115
|
-
|
116
|
-
# Pages: spage, epage
|
117
|
-
pages = metadata['rft.pages'] # If only pages are provided
|
118
|
-
pages ||= metadata['rft.spage'] + "-" + metadata['rft.epage']
|
119
|
-
# If we have start and end pages
|
120
|
-
bibentry[:pages] = pages
|
121
|
-
|
122
|
-
# Authors are all in 'rft.au'
|
123
|
-
authors = BibTeX::Names.new
|
124
|
-
metadata['rft.au'].each do |author|
|
125
|
-
authors.add(BibTeX::Name.parse(author))
|
126
|
-
end
|
127
|
-
bibentry[:author] = authors
|
128
|
-
|
129
|
-
# COinS supports some types
|
130
|
-
genre = metadata['rft.genre']
|
131
|
-
if genre == 'article' then
|
132
|
-
bibentry.type = "article"
|
133
|
-
elsif genre == 'proceeding' || genre == 'conference' then
|
134
|
-
bibentry.type = "inproceeding"
|
135
|
-
end
|
136
|
-
|
137
|
-
# Map remaining fields to BibTeX.
|
138
|
-
standard_mappings = {
|
139
|
-
"rft.atitle" => "title",
|
140
|
-
"rft.date" => "date",
|
141
|
-
"rft.volume" => "volume",
|
142
|
-
"rft.issue" => "number",
|
143
|
-
"rft.artnum" => "article_number",
|
144
|
-
"rft.issn" => "issn",
|
145
|
-
"rft.eissn" => "eissn",
|
146
|
-
"rft.isbn" => "isbn",
|
147
|
-
"rft.coden" => "CODEN",
|
148
|
-
"rft.sici" => "SICI",
|
149
|
-
"rft.chron" => "chronology",
|
150
|
-
"rft.ssn" => "season",
|
151
|
-
"rft.quarter" => "quarter",
|
152
|
-
"rft.part" => "part",
|
153
|
-
}
|
154
|
-
standard_mappings.keys.each do |field|
|
155
|
-
if metadata.key?(field) then
|
156
|
-
bibentry[standard_mappings[field]] = metadata[field]
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
# Yield values or return array.
|
162
|
-
if block_given? then
|
163
|
-
yield(bibentry)
|
164
|
-
else
|
165
|
-
results.push(bibentry)
|
166
|
-
end
|
73
|
+
match = as_json.first
|
74
|
+
|
75
|
+
# Skip non-identical DOI matches.
|
76
|
+
return nil unless match['doi'].downcase == canonical_id.downcase
|
77
|
+
|
78
|
+
# Create a BibTeX entry to store these values.
|
79
|
+
bibentry = BibTeX::Entry.new
|
80
|
+
|
81
|
+
# Process any COinS content first, if any.
|
82
|
+
if match.key?('coins') then
|
83
|
+
bibentry = BibURI::Driver::COinS::coins_to_bibtex(match['coins'])
|
84
|
+
end
|
85
|
+
|
86
|
+
# Set identifiers so we know where this came from.
|
87
|
+
bibentry[:url] = canonical_id
|
88
|
+
|
89
|
+
identifiers = bibentry[:identifiers].split("\n")
|
90
|
+
identifiers.push(canonical_id)
|
91
|
+
bibentry.add(:identifiers, identifiers.join("\n"))
|
92
|
+
|
93
|
+
bibentry[:doi] = canonical_id.match(/^http:\/\/dx\.doi\.org\/(.*)$/)[1]
|
94
|
+
|
95
|
+
# CrossRef itself provides a full citation and year.
|
96
|
+
if !bibentry.has_field?('title') and match.key?('fullCitation') then
|
97
|
+
bibentry[:title] = match['fullCitation']
|
167
98
|
end
|
168
99
|
|
169
|
-
|
170
|
-
|
171
|
-
return results
|
100
|
+
if !bibentry.has_field?('year') and match.key?('year') then
|
101
|
+
bibentry[:year] = match['year']
|
172
102
|
end
|
103
|
+
|
104
|
+
# Yield values or return array.
|
105
|
+
return bibentry
|
173
106
|
end
|
174
107
|
end
|
data/lib/biburi/driver.rb
CHANGED
@@ -41,10 +41,12 @@ end
|
|
41
41
|
# Load all the drivers, and add them to BibURI::Driver
|
42
42
|
# in order of preference.
|
43
43
|
require "biburi/driver/doi"
|
44
|
+
require "biburi/driver/coins"
|
44
45
|
|
45
46
|
module BibURI::Driver
|
46
47
|
@@drivers = [
|
47
|
-
BibURI::Driver::DOI
|
48
|
+
BibURI::Driver::DOI,
|
49
|
+
BibURI::Driver::COinS
|
48
50
|
]
|
49
51
|
end
|
50
52
|
|
data/lib/biburi/version.rb
CHANGED
data/lib/biburi.rb
CHANGED
@@ -19,10 +19,8 @@ module BibURI
|
|
19
19
|
def self.lookup(id)
|
20
20
|
self.drivers.each do |driver|
|
21
21
|
if driver.supported?(id) then
|
22
|
-
|
23
|
-
|
24
|
-
return results
|
25
|
-
end
|
22
|
+
bibtex = driver.lookup(id)
|
23
|
+
return bibtex unless bibtex.nil?
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
data/spec/biburi_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require_relative 'spec_helper'
|
2
4
|
|
3
5
|
describe BibURI do
|
@@ -17,33 +19,144 @@ describe BibURI do
|
|
17
19
|
end
|
18
20
|
|
19
21
|
describe "lookup" do
|
20
|
-
it "should be able to do
|
22
|
+
it "should be able to do DOI lookups" do
|
21
23
|
queries = {
|
22
|
-
"doi:10.1038/171737a0" =>
|
24
|
+
"doi:10.1038/171737a0" =>
|
23
25
|
BibTeX::Entry.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
26
|
+
:type => 'article',
|
27
|
+
:identifiers => "info:doi/http://dx.doi.org/10.1038/171737a0\nhttp://dx.doi.org/10.1038/171737a0",
|
28
|
+
:journal => "Nature",
|
29
|
+
:pages => "737--738",
|
27
30
|
:author => "WATSON, J. D. and CRICK, F. H. C.",
|
28
31
|
:date => "1953",
|
32
|
+
:year => "1953",
|
33
|
+
:title => "Molecular Structure of Nucleic Acids: A Structure for Deoxyribose Nucleic Acid",
|
29
34
|
:volume => "171",
|
30
|
-
:number => "4356"
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
:number => "4356",
|
36
|
+
:url => "http://dx.doi.org/10.1038/171737a0",
|
37
|
+
:doi => "10.1038/171737a0",
|
38
|
+
),
|
39
|
+
"http://dx.doi.org/10.1111/j.1096-0031.2010.00329.x" =>
|
34
40
|
BibTeX::Entry.new({
|
35
|
-
|
36
|
-
"
|
37
|
-
"title" => "SequenceMatrix: concatenation software for the fast assembly of multi-gene datasets with character set and codon information",
|
38
|
-
"year" => "2011",
|
41
|
+
:type => 'article',
|
42
|
+
"identifiers" => "info:doi/http://dx.doi.org/10.1111/j.1096-0031.2010.00329.x\nhttp://dx.doi.org/10.1111/j.1096-0031.2010.00329.x",
|
39
43
|
"journal" => "Cladistics",
|
40
|
-
"pages" => "171
|
44
|
+
"pages" => "171--180",
|
41
45
|
"author" => "Vaidya, Gaurav and Lohman, David J. and Meier, Rudolf",
|
42
46
|
"date" => "2011",
|
47
|
+
"year" => "2011",
|
48
|
+
"title" => "SequenceMatrix: concatenation software for the fast assembly of multi-gene datasets with character set and codon information",
|
43
49
|
"volume" => "27",
|
44
|
-
"number" => "2"
|
50
|
+
"number" => "2",
|
51
|
+
"url" => "http://dx.doi.org/10.1111/j.1096-0031.2010.00329.x",
|
52
|
+
"doi" => "10.1111/j.1096-0031.2010.00329.x",
|
45
53
|
})
|
46
|
-
|
54
|
+
}
|
55
|
+
|
56
|
+
queries.keys.each do |query|
|
57
|
+
result = BibURI::lookup(query)
|
58
|
+
|
59
|
+
expect(result.to_s).to eq(queries[query].to_s)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should be able to do COinS lookups" do
|
64
|
+
queries = {
|
65
|
+
"http://www.mendeley.com/research/outline-morphometric-approach-identifying-fossil-spiders-preliminary-examination-florissant-formation/" =>
|
66
|
+
BibTeX::Entry.new(
|
67
|
+
:type => 'article',
|
68
|
+
:identifiers => "info:doi/10.1130/2008.2435(07).\nhttp://www.mendeley.com/research/outline-morphometric-approach-identifying-fossil-spiders-preliminary-examination-florissant-formation/",
|
69
|
+
:journal => "Society",
|
70
|
+
:pages => "105",
|
71
|
+
:author => "Kinchloe Roberts, A and Smith, D M and Guralnick, R P and Cushing, P E and Krieger, J",
|
72
|
+
:date => "2008",
|
73
|
+
:year => "2008",
|
74
|
+
:title => "An outline morphometric approach to identifying fossil spiders: A preliminary examination from the Florissant Formation",
|
75
|
+
:volume => "435",
|
76
|
+
:number => "303",
|
77
|
+
:url => "http://www.mendeley.com/research/outline-morphometric-approach-identifying-fossil-spiders-preliminary-examination-florissant-formation/",
|
78
|
+
:doi => "10.1130/2008.2435(07)." # This is wrong though
|
79
|
+
),
|
80
|
+
"http://www.mendeley.com/catalog/big-questions-biodiversity-informatics/" =>
|
81
|
+
BibTeX::Entry.new(
|
82
|
+
:type => 'article',
|
83
|
+
:identifiers => "info:doi/10.1080/14772001003739369\nhttp://www.mendeley.com/catalog/big-questions-biodiversity-informatics/",
|
84
|
+
:journal => "Systematics and Biodiversity",
|
85
|
+
:pages => "159--168",
|
86
|
+
:author => "Peterson, A Townsend and Knapp, Sandra and Guralnick, Robert and Soberón, Jorge and Holder, Mark T",
|
87
|
+
:date => "2010",
|
88
|
+
:year => "2010",
|
89
|
+
:title => "The big questions for biodiversity informatics",
|
90
|
+
:volume => "8",
|
91
|
+
:number => "2",
|
92
|
+
:issn => "14772000",
|
93
|
+
:url => "http://www.mendeley.com/catalog/big-questions-biodiversity-informatics/",
|
94
|
+
:doi => "10.1080/14772001003739369"
|
95
|
+
),
|
96
|
+
"http://www.mendeley.com/catalog/biodiversity-informatics-automated-approaches-documenting-global-biodiversity-patterns-processes/" =>
|
97
|
+
BibTeX::Entry.new(
|
98
|
+
:type => 'article',
|
99
|
+
:identifiers => "info:pmid/19129210\nhttp://www.mendeley.com/catalog/biodiversity-informatics-automated-approaches-documenting-global-biodiversity-patterns-processes/",
|
100
|
+
:journal => "Bioinformatics",
|
101
|
+
:pages => "421--428",
|
102
|
+
:author => "Guralnick, Robert and Hill, Andrew",
|
103
|
+
:date => "2009",
|
104
|
+
:year => "2009",
|
105
|
+
:title => "Biodiversity informatics: automated approaches for documenting global biodiversity patterns and processes.",
|
106
|
+
:volume => "25",
|
107
|
+
:number => "4",
|
108
|
+
:url => "http://www.mendeley.com/catalog/biodiversity-informatics-automated-approaches-documenting-global-biodiversity-patterns-processes/"
|
109
|
+
),
|
110
|
+
"http://www.mendeley.com/research/hs-2-w-estern-o-ffshoots-1500-2001-australia-canada-new-zealand-united-states/" =>
|
111
|
+
BibTeX::Entry.new(
|
112
|
+
:type => 'article',
|
113
|
+
:identifiers => "http://www.mendeley.com/research/hs-2-w-estern-o-ffshoots-1500-2001-australia-canada-new-zealand-united-states/",
|
114
|
+
:journal => "Work",
|
115
|
+
:pages => "71--90",
|
116
|
+
:author => "Offshoots, Western",
|
117
|
+
:date => "2001",
|
118
|
+
:year => "2001",
|
119
|
+
:title => "HS – 2 : W ESTERN O FFSHOOTS : 1500 – 2001 ( Australia , Canada , New Zealand , and the United States )",
|
120
|
+
:volume => "2001",
|
121
|
+
:isbn => "9264022619",
|
122
|
+
:url => "http://www.mendeley.com/research/hs-2-w-estern-o-ffshoots-1500-2001-australia-canada-new-zealand-united-states/"
|
123
|
+
),
|
124
|
+
"http://www.citeulike.org/user/bjbraams/article/12683220" =>
|
125
|
+
BibTeX::Entry.new(
|
126
|
+
:type => 'article',
|
127
|
+
:identifiers => "info:doi/10.1016/s0009-2614(02)00988-0\nhttp://www.citeulike.org/user/bjbraams/article/12683220",
|
128
|
+
:journal => "Chemical Physics Letters",
|
129
|
+
:pages => "520--524",
|
130
|
+
:author => "Scemama, Anthony and Chaquin, Patrick and Gazeau, Marie-Claire and Bénilan, Yves",
|
131
|
+
:date => "2002-8",
|
132
|
+
:year => "2002",
|
133
|
+
:month => "8",
|
134
|
+
:title => "Semi-empirical calculation of electronic absorption wavelengths of polyynes, monocyano- and dicyanopolyynes. Predictions for long chain compounds and carbon allotrope carbyne",
|
135
|
+
:volume => "361",
|
136
|
+
:number => "5-6",
|
137
|
+
:issn => "00092614",
|
138
|
+
:url => "http://www.citeulike.org/user/bjbraams/article/12683220",
|
139
|
+
:doi => "10.1016/s0009-2614(02)00988-0"
|
140
|
+
),
|
141
|
+
#"http://www.bioone.org/doi/abs/10.1642/0004-8038(2002)119%5B0897:FTSTTA%5D2.0.CO%3B2" =>
|
142
|
+
# BibTeX::Entry.new(
|
143
|
+
#
|
144
|
+
# ),
|
145
|
+
"http://www.biodiversitylibrary.org/part/87340#/summary" =>
|
146
|
+
BibTeX::Entry.new(
|
147
|
+
:type => 'article',
|
148
|
+
:identifiers => "info:doi/10.2307/4067078\nurn:ISSN:0004-8038\nhttp://www.biodiversitylibrary.org/part/87340\nhttp://www.biodiversitylibrary.org/part/87340#/summary",
|
149
|
+
:journal => "The Auk",
|
150
|
+
:pages => "60--66",
|
151
|
+
:author => "Allen, J A and Brewster, William and Coues, Elliott and Ridgway, Robert and Sage, John H",
|
152
|
+
:date => "1890",
|
153
|
+
:year => "1890",
|
154
|
+
:title => "Second Supplement to the American Ornithologists' Union Check-List of North American Birds",
|
155
|
+
:volume => "7",
|
156
|
+
:issn => "0004-8038",
|
157
|
+
:url => "http://www.biodiversitylibrary.org/part/87340#/summary",
|
158
|
+
:doi => "10.2307/4067078"
|
159
|
+
)
|
47
160
|
}
|
48
161
|
|
49
162
|
queries.keys.each do |query|
|
data/spec/doi_spec.rb
CHANGED
@@ -46,31 +46,21 @@ describe BibURI::Driver::DOI do
|
|
46
46
|
describe "lookup" do
|
47
47
|
it "should be able to download information on some DOIs" do
|
48
48
|
queries = {
|
49
|
-
"doi:10.1038/171737a0" =>
|
49
|
+
"doi:10.1038/171737a0" =>
|
50
50
|
BibTeX::Entry.new(
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
51
|
+
:type => 'article',
|
52
|
+
:identifiers => "info:doi/http://dx.doi.org/10.1038/171737a0\nhttp://dx.doi.org/10.1038/171737a0",
|
53
|
+
:journal => "Nature",
|
54
|
+
:pages => "737--738",
|
54
55
|
:author => "WATSON, J. D. and CRICK, F. H. C.",
|
55
56
|
:date => "1953",
|
57
|
+
:year => "1953",
|
58
|
+
:title => "Molecular Structure of Nucleic Acids: A Structure for Deoxyribose Nucleic Acid",
|
56
59
|
:volume => "171",
|
57
|
-
:number => "4356"
|
60
|
+
:number => "4356",
|
61
|
+
:url => "http://dx.doi.org/10.1038/171737a0",
|
62
|
+
:doi => "10.1038/171737a0"
|
58
63
|
)
|
59
|
-
],
|
60
|
-
"http://dx.doi.org/10.1111/j.1096-0031.2010.00329.x" => [
|
61
|
-
BibTeX::Entry.new({
|
62
|
-
"url" => "http://dx.doi.org/10.1111/j.1096-0031.2010.00329.x",
|
63
|
-
"doi" => "10.1111/j.1096-0031.2010.00329.x",
|
64
|
-
"title" => "SequenceMatrix: concatenation software for the fast assembly of multi-gene datasets with character set and codon information",
|
65
|
-
"year" => "2011",
|
66
|
-
"journal" => "Cladistics",
|
67
|
-
"pages" => "171-180",
|
68
|
-
"author" => "Vaidya, Gaurav and Lohman, David J. and Meier, Rudolf",
|
69
|
-
"date" => "2011",
|
70
|
-
"volume" => "27",
|
71
|
-
"number" => "2"
|
72
|
-
})
|
73
|
-
]
|
74
64
|
}
|
75
65
|
|
76
66
|
queries.keys.each do |query|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biburi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gaurav Vaidya
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,88 +16,89 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.5
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.3.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.14.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.14.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.7.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.7.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: bibtex-ruby
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :
|
75
|
+
version: 2.3.4
|
76
|
+
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.3.4
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: nokogiri
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.6.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.6.0
|
97
97
|
description: Find the BibTeX information when your citation has an identifier
|
98
98
|
email:
|
99
99
|
- gaurav@ggvaidya.com
|
100
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- biburi.rb
|
101
102
|
extensions: []
|
102
103
|
extra_rdoc_files: []
|
103
104
|
files:
|
@@ -109,8 +110,10 @@ files:
|
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|
111
112
|
- biburi.gemspec
|
113
|
+
- bin/biburi.rb
|
112
114
|
- lib/biburi.rb
|
113
115
|
- lib/biburi/driver.rb
|
116
|
+
- lib/biburi/driver/coins.rb
|
114
117
|
- lib/biburi/driver/doi.rb
|
115
118
|
- lib/biburi/version.rb
|
116
119
|
- spec/biburi_spec.rb
|