daily-dev.net

React, firebase, 機械学習など

rubyでarxivの論文タイトルをPDF/absのURLから取得する

sponsored

APIを利用してJSONをパースする。

APIは以下のような構造。

https://api.altmetric.com/version/arxiv/arXiv_id
require 'net/http'
require 'uri'
require 'json'



arxiv_id = target_url.split('/').last.match(/\d+\.\d+/).to_s
api_url = "https://api.altmetric.com/v1/arxiv/" + arxiv_id
    
uri = URI.parse(api_url)

json = Net::HTTP.get(uri)
result = JSON.parse(json)
puts result

でOK

以下のようなjson が返却されているので

title = result['title']で取得できる。

{
title: "Controllable Text Generation",
arxiv_id: "1703.00955",
tq: [
"Controllable Text Generation. (arXiv:1703.00955v1 )",
"Toward Controlled Generation of Text",
"Toward Controlled Generation of Text. (arXiv:1703.00955v2 UPDATED)",
"Toward Controlled Generation of Text. (arXiv:1703.00955v2 UPDATED) #NLProc",
"cs.LG: Toward Controlled Generation of Text. (arXiv:1703.00955v2 UPDATED)"
],
isbns: [ ],
altmetric_jid: "arxiv",
issns: [ ],
journal: "arXiv",
cohorts: {
pub: 85,
sci: 33
},
context: {
all: {
count: 10292367,
mean: 7.4204043235432,
rank: 172202,
pct: 98,
higher_than: 10124075
},
journal: {
count: 547842,
mean: 2.8423856556922,
rank: 2316,
pct: 99,
higher_than: 545617
},
similar_age_3m: {
count: 256079,
mean: 13.846370972906,
rank: 10002,
pct: 96,
higher_than: 246074
},
similar_age_journal_3m: {
count: 26787,
mean: 4.2607061151348,
rank: 221,
pct: 99,
higher_than: 26566
}
},
authors: [
"Zhiting Hu",
"Zichao Yang",
"Xiaodan Liang",
"Ruslan Salakhutdinov",
"Eric P. Xing"
],
type: "article",
handles: [ ],
altmetric_id: 17035438,
schema: "1.5.4",
is_oa: false,
cited_by_posts_count: 153,
cited_by_tweeters_count: 118,
cited_by_fbwalls_count: 3,
cited_by_gplus_count: 1,
cited_by_rdts_count: 1,
cited_by_accounts_count: 123,
last_updated: 1516804863,
score: 68.4,
history: {
1y: 7.5,
6m: 2.25,
3m: 0,
1m: 0,
1w: 0,
6d: 0,
5d: 0,
4d: 0,
3d: 0,
2d: 0,
1d: 0,
at: 68.4
},
url: "https://arxiv.org/abs/1703.00955",
added_on: 1488763848,
published_on: 1488489827,
readers: {
citeulike: 0,
mendeley: 314,
connotea: 0
},
readers_count: 314,
downloads: [ ],
images: {
small: "https://badges.altmetric.com/?size=64&score=69&types=rtttttfg",
medium: "https://badges.altmetric.com/?size=100&score=69&types=rtttttfg",
large: "https://badges.altmetric.com/?size=180&score=69&types=rtttttfg"
},
details_url: "http://www.altmetric.com/details.php?citation_id=17035438"
}