arxiv-references 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/arxiv-references.gemspec +36 -0
- data/bin/arxiv-ref +5 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/arxiv/references/ArxivReferences.rb +30 -0
- data/lib/arxiv/references/myUtil.rb +112 -0
- data/lib/arxiv/references/version.rb +5 -0
- data/lib/arxiv/references.rb +8 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 656e917d4e104aa9d021fee3b7baaba58f17d965
|
4
|
+
data.tar.gz: 6127173a8386c3acadf8df386222f95097c46aa7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4e97408b244a340b4bc72a5ad782df5b1cecec19839d8aa521bf3c0b27ed4ead82fea39b5c1da7be5a5c236689d52e989d9a61cc6302373f554ff654d9bdba0
|
7
|
+
data.tar.gz: 69db2385c567c48ba668a07c391c209d2ee56ebe7f6211df57117ec067c080936bb9905961ddeb065db3de22eda74bb7c017668594a4f08fe348dfd3280c93ff
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Takahiro Nishimura
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Arxiv::References
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/arxiv/references`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'arxiv-references'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install arxiv-references
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/arxiv-references. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arxiv/references/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arxiv-references"
|
8
|
+
spec.version = Arxiv::References::VERSION
|
9
|
+
spec.authors = ["Takahiro Nishimura"]
|
10
|
+
spec.email = ["tkhr.nishimura@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{This library is to fetch information of Title, Author, Abstruct and Citations from Arxiv Paper}
|
13
|
+
spec.description = %q{This library is for suvey.}
|
14
|
+
spec.homepage = "https://github.com/nishimuuu/Arxiv-references"
|
15
|
+
spec.license = "GPL"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_dependency 'thor', "~> 0.19"
|
34
|
+
spec.add_dependency 'pdf-reader', "~> 1.4"
|
35
|
+
spec.add_dependency 'nokogiri', "~> 1.6"
|
36
|
+
end
|
data/bin/arxiv-ref
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arxiv/references"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'pathname'
|
5
|
+
lib = Pathname.new(__FILE__).dirname.join().expand_path
|
6
|
+
p lib.to_s
|
7
|
+
$:.unshift lib.to_s
|
8
|
+
require 'myUtil'
|
9
|
+
|
10
|
+
|
11
|
+
module ArxivReferences
|
12
|
+
class CLI < Thor
|
13
|
+
include ArxivUtil
|
14
|
+
desc 'url', 'Extract references from arxiv URL'
|
15
|
+
p $:
|
16
|
+
def url(urlName)
|
17
|
+
return ArxivUtil.fetchFromUrl(urlName)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'id', 'Extract references from Arxiv id'
|
21
|
+
def arxivid(idName)
|
22
|
+
return ArxivUtil.fetchFromArxivId(idName)
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'pdfurl', 'Extract references from pdf URL'
|
26
|
+
def pdfurl(pdfUrlName)
|
27
|
+
return ArxivUtil.fetchFromPdfUrl(pdfUrlName)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'digest/sha2'
|
3
|
+
require 'time'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'pty'
|
6
|
+
require 'expect'
|
7
|
+
require 'pdf-reader'
|
8
|
+
require 'nokogiri'
|
9
|
+
require 'json'
|
10
|
+
module ArxivUtil
|
11
|
+
BASE_URL = "https://arxiv.org"
|
12
|
+
REFERENCE_START_REGEXP = /References|REFERENCES|Reference|REFERENCE/
|
13
|
+
REFERENCE_REGEXP = /(\[[0-9]?[0-9]\]|\[.+?\])/
|
14
|
+
def self.makeId
|
15
|
+
return Digest::SHA256.hexdigest Time.now.strftime("%F %H:%M:%S")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.makeDir(id)
|
19
|
+
Dir.mkdir("/tmp/#{id}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.removeDir(id)
|
23
|
+
FileUtils.rm_rf("/tmp/#{id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.makeFile(id)
|
27
|
+
return "/tmp/#{id}/output.pdf"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self. getK2Pdf(id)
|
31
|
+
return "/tmp/#{id}/output_k2opt.pdf"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def self.fetchFromUrl(urlName)
|
36
|
+
puts "fetch => #{urlName}"
|
37
|
+
charset = nil
|
38
|
+
html = open(urlName) do |f|
|
39
|
+
charset = f.charset
|
40
|
+
f.read
|
41
|
+
end
|
42
|
+
|
43
|
+
page = Nokogiri::HTML.parse(html, nil, charset)
|
44
|
+
result = {}
|
45
|
+
result[:title] = page.xpath('//*[@id="abs"]/div[2]/h1').text
|
46
|
+
result[:authors] = page.xpath('//*[@id="abs"]/div[2]/div[2]/a').text
|
47
|
+
result[:abstruct] = page.xpath('//*[@id="abs"]/div[2]/blockquote').text
|
48
|
+
result[:pdfurl] = "#{BASE_URL}#{page.xpath('//*[@id="abs"]/div[1]/div[1]/ul/li[1]/a').attr('href').value}"
|
49
|
+
result[:references] = fetchFromPdfUrl(result[:pdfurl])
|
50
|
+
puts result.to_json
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.fetchFromArxivId(id)
|
54
|
+
target_url = "#{BASE_URL}/abs/#{id}"
|
55
|
+
fetchFromUrl(target_url)
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.fetchFromPdfUrl(pdfUrl)
|
59
|
+
job_id = makeId
|
60
|
+
makeDir(job_id)
|
61
|
+
file_name = makeFile(job_id)
|
62
|
+
|
63
|
+
open(file_name, 'wb') do |o|
|
64
|
+
open(pdfUrl) do |data|
|
65
|
+
o.write(data.read)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
cmd = "k2pdfopt -dev kpw #{file_name}"
|
69
|
+
PTY.spawn(cmd) do |i,o|
|
70
|
+
o.sync = true
|
71
|
+
i.expect(/\S.*Enter option above \(h=help, q=quit\):/,10){|line|
|
72
|
+
o.puts "\n"
|
73
|
+
o.flush
|
74
|
+
}
|
75
|
+
while( i.eof? == false )
|
76
|
+
res = i.gets
|
77
|
+
print res
|
78
|
+
break unless res.index('written').nil?
|
79
|
+
end
|
80
|
+
end
|
81
|
+
executed_pdf = getK2Pdf(job_id)
|
82
|
+
reader = PDF::Reader.new(executed_pdf)
|
83
|
+
page_no = reader.
|
84
|
+
pages.
|
85
|
+
reject{|i|
|
86
|
+
i.text.index(REFERENCE_START_REGEXP).nil?
|
87
|
+
}.
|
88
|
+
map(&:number).
|
89
|
+
sort.
|
90
|
+
shift
|
91
|
+
puts "Detect References page=> #{page_no} "
|
92
|
+
ref_page = reader.
|
93
|
+
pages.
|
94
|
+
select{|i|
|
95
|
+
i.number >= page_no
|
96
|
+
}.
|
97
|
+
map{|i|
|
98
|
+
i.text.gsub(/\n+/,"\n").gsub(/ +/,' ')
|
99
|
+
}.
|
100
|
+
join(' ').
|
101
|
+
gsub(REFERENCE_REGEXP,"\n\\1").
|
102
|
+
gsub('- ','').
|
103
|
+
split("\n")
|
104
|
+
|
105
|
+
references = ref_page[(ref_page.index(REFERENCE_START_REGEXP)+1)..ref_page.length].
|
106
|
+
select{|i|
|
107
|
+
i.length > 5
|
108
|
+
}
|
109
|
+
removeDir(job_id)
|
110
|
+
return references
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arxiv-references
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takahiro Nishimura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.19'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.19'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pdf-reader
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
description: This library is for suvey.
|
98
|
+
email:
|
99
|
+
- tkhr.nishimura@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- arxiv-references.gemspec
|
113
|
+
- bin/arxiv-ref
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/arxiv/references.rb
|
117
|
+
- lib/arxiv/references/ArxivReferences.rb
|
118
|
+
- lib/arxiv/references/myUtil.rb
|
119
|
+
- lib/arxiv/references/version.rb
|
120
|
+
homepage: https://github.com/nishimuuu/Arxiv-references
|
121
|
+
licenses:
|
122
|
+
- GPL
|
123
|
+
metadata:
|
124
|
+
allowed_push_host: https://rubygems.org
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.4.5.1
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: This library is to fetch information of Title, Author, Abstruct and Citations
|
145
|
+
from Arxiv Paper
|
146
|
+
test_files: []
|