researchmap2bib 0.1.1 → 0.2.1
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/Guardfile +42 -0
- data/bin/console +2 -9
- data/exe/researchmap2bib +9 -1
- data/lib/researchmap2bib/version.rb +1 -1
- data/lib/researchmap2bib.rb +160 -1
- data/researchmap2bib.gemspec +5 -0
- metadata +58 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3ca939dcd16b60e8b4c847a8248759967857f79
|
4
|
+
data.tar.gz: ab0aa94131d490e0c000d9a718a49262959090aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb917952d6015c74fd244ae2a71d0b3297fe18e80aba9eb8d4dcf2f48d196ce35481a46640084c4f39375346277b6e58ab02a3b50dc0b493a37b02bb02ab3d3
|
7
|
+
data.tar.gz: d11615610efeeb942b912104d6a3b2719c0e581d3f9c994721866041fd29ac67fccb237c40e0e87eb194140cd2503519bfbb405ac7c96961686e8afcd6ee1be7
|
data/Guardfile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard :minitest do
|
19
|
+
# with Minitest::Unit
|
20
|
+
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
|
21
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
|
22
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
23
|
+
|
24
|
+
# with Minitest::Spec
|
25
|
+
# watch(%r{^spec/(.*)_spec\.rb$})
|
26
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
27
|
+
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
28
|
+
|
29
|
+
# Rails 4
|
30
|
+
# watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
31
|
+
# watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
|
32
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
|
33
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
34
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
35
|
+
# watch(%r{^test/.+_test\.rb$})
|
36
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
37
|
+
|
38
|
+
# Rails < 4
|
39
|
+
# watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
|
40
|
+
# watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
|
41
|
+
# watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
|
42
|
+
end
|
data/bin/console
CHANGED
@@ -3,12 +3,5 @@
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "researchmap2bib"
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
6
|
+
require "pry"
|
7
|
+
Pry.start
|
data/exe/researchmap2bib
CHANGED
@@ -2,4 +2,12 @@
|
|
2
2
|
|
3
3
|
require "researchmap2bib"
|
4
4
|
|
5
|
-
|
5
|
+
@s = Researchmap2bib::ResearchmapReader.new
|
6
|
+
entries = @s.read_researchmap('test/ychubachi.zip')
|
7
|
+
|
8
|
+
results = Array.new
|
9
|
+
entries.each do |entry|
|
10
|
+
results.push(@s.write_bibliography_entry(entry))
|
11
|
+
end
|
12
|
+
|
13
|
+
puts results.join("\n")
|
data/lib/researchmap2bib.rb
CHANGED
@@ -1,5 +1,164 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require "researchmap2bib/version"
|
2
3
|
|
4
|
+
require 'zip'
|
5
|
+
require 'rexml/document'
|
6
|
+
require 'pp'
|
7
|
+
require 'erb'
|
8
|
+
|
3
9
|
module Researchmap2bib
|
4
|
-
|
10
|
+
Entry = Struct.new(
|
11
|
+
:title, :author, :summary, :journal, :publisher, :publicationName,
|
12
|
+
:volume, :number, :startingPage, :endingPage, :publicationDate,
|
13
|
+
:referee, :language, :paperType,
|
14
|
+
)
|
15
|
+
|
16
|
+
class ResearchmapReader
|
17
|
+
def read_researchmap(file_name)
|
18
|
+
entries = Zip::File.open(file_name) do |zip_file|
|
19
|
+
entry = zip_file.glob('*\/paper.xml').first
|
20
|
+
read_paper(entry.get_input_stream.read)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_paper(xml)
|
25
|
+
doc = REXML::Document.new(xml)
|
26
|
+
entries = Array.new
|
27
|
+
REXML::XPath.each(doc, '/feed/entry') do |entry|
|
28
|
+
entries.push(read_entry(entry))
|
29
|
+
end
|
30
|
+
entries
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_entry(entry)
|
34
|
+
title = entry.elements["title"].text
|
35
|
+
author = entry.elements["author"].elements["name"].text
|
36
|
+
author = to_hankaku(author)
|
37
|
+
summary = entry.elements["summary"].text
|
38
|
+
journal = entry.elements["rm:journal"].text
|
39
|
+
publisher = entry.elements["rm:publisher"].text
|
40
|
+
publicationName = entry.elements["rm:publicationName"].text
|
41
|
+
volume = entry.elements["rm:volume"].text
|
42
|
+
number = entry.elements["rm:number"].text
|
43
|
+
startingPage = entry.elements["rm:startingPage"].text
|
44
|
+
endingPage = entry.elements["rm:endingPage"].text
|
45
|
+
publicationDate = entry.elements["rm:publicationDate"].text
|
46
|
+
referee = entry.elements["rm:referee"] ? true : false
|
47
|
+
language = entry.elements["rm:language"].text
|
48
|
+
paperType = entry.elements["rm:paperType"].elements["id"].text
|
49
|
+
|
50
|
+
Entry.new(
|
51
|
+
title, author, summary, journal, publisher, publicationName,
|
52
|
+
volume, number, startingPage, endingPage, publicationDate,
|
53
|
+
referee, language, paperType,
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
# 0:未設定、1:研究論文(学術雑誌)、2:研究論文(国際会議プロシーディングス)、3:研究論文(大学,研究機関紀要)
|
58
|
+
# 、
|
59
|
+
# 4:研究論文(研究会,シンポジウム資料等)、5:研究論文(その他学術会議資料等)
|
60
|
+
def write_bibliography_entry(entry)
|
61
|
+
key = generate_key(entry.author, entry.publicationDate)
|
62
|
+
year, month = year_month(entry.publicationDate)
|
63
|
+
month = month.to_i
|
64
|
+
case entry.paperType.to_i
|
65
|
+
when 1, 3 then
|
66
|
+
record = <<EOS
|
67
|
+
@Article{<%= key %>,
|
68
|
+
author = {<%= entry.author %>},
|
69
|
+
title = {<%= entry.title %>},
|
70
|
+
journal = {<%= entry.journal %>},
|
71
|
+
EOS
|
72
|
+
record += ' year = <%= year %>'
|
73
|
+
if month > 0
|
74
|
+
record += ",\n month = <%= month %>"
|
75
|
+
end
|
76
|
+
if entry.volume
|
77
|
+
record += ",\n volume = <%= entry.volume %>"
|
78
|
+
end
|
79
|
+
if entry.number
|
80
|
+
record += ",\n number = <%= entry.number %>"
|
81
|
+
end
|
82
|
+
if entry.startingPage && entry.endingPage
|
83
|
+
record += ",\n pages = <%= entry.startingPage %>-<%= entry.endingPage %>"
|
84
|
+
elsif entry.startingPage
|
85
|
+
record += ",\n pages = <%= entry.startingPage %> %>"
|
86
|
+
end
|
87
|
+
record += "}\n"
|
88
|
+
if entry.summary
|
89
|
+
record += "% <%= entry.summary %>\n"
|
90
|
+
end
|
91
|
+
else
|
92
|
+
record = <<EOS
|
93
|
+
@InProceedings{<%= key %>,
|
94
|
+
author = {<%= entry.author %>},
|
95
|
+
title = {<%= entry.title %>},
|
96
|
+
booktitle = {<%= entry.journal %>},
|
97
|
+
EOS
|
98
|
+
record += ' year = <%= year %>'
|
99
|
+
if month > 0
|
100
|
+
record += ",\n month = <%= month %>"
|
101
|
+
end
|
102
|
+
if entry.volume
|
103
|
+
record += ",\n volume = <%= entry.volume %>"
|
104
|
+
end
|
105
|
+
if entry.number
|
106
|
+
record += ",\n number = <%= entry.number %>"
|
107
|
+
end
|
108
|
+
if entry.startingPage && entry.endingPage
|
109
|
+
record += ",\n pages = <%= entry.startingPage %>-<%= entry.endingPage %>"
|
110
|
+
elsif entry.startingPage
|
111
|
+
record += ",\n pages = <%= entry.startingPage %> %>"
|
112
|
+
end
|
113
|
+
if entry.publisher
|
114
|
+
record += ",\n publisher = {<%= entry.publisher %>}"
|
115
|
+
end
|
116
|
+
record += "}\n"
|
117
|
+
if entry.summary
|
118
|
+
record += "% <%= entry.summary %>\n"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
erb = ERB.new(record)
|
122
|
+
erb.result(binding)
|
123
|
+
end
|
124
|
+
|
125
|
+
def to_hankaku(str)
|
126
|
+
str.tr('0-9a-zA-Z,、 ', '0-9a-zA-Z,, ')
|
127
|
+
end
|
128
|
+
|
129
|
+
def year_month(date)
|
130
|
+
/([0-9]{4})([0-9]{2})/.match(date).captures
|
131
|
+
end
|
132
|
+
|
133
|
+
def concatenate_authors(authors)
|
134
|
+
authors.gsub(/ *, */, ' and ')
|
135
|
+
end
|
136
|
+
|
137
|
+
def first_author(authors)
|
138
|
+
r = /([^,]*)/.match(authors)
|
139
|
+
r == nil ? authors.strip : r.captures[0].strip
|
140
|
+
end
|
141
|
+
|
142
|
+
def family_name(author)
|
143
|
+
if /(^\w*) *(\w*)$/ =~ author
|
144
|
+
$2
|
145
|
+
elsif /(^\S*) *(\S*)$/ =~ author
|
146
|
+
$1
|
147
|
+
else
|
148
|
+
author
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def generate_key(authors, date)
|
153
|
+
first_author = first_author(authors)
|
154
|
+
name = family_name(first_author)
|
155
|
+
year, month = year_month(date)
|
156
|
+
year = /[0-9][0-9]([0-9][0-9])/.match(year).captures[0]
|
157
|
+
if month.to_i >0
|
158
|
+
name + year + month
|
159
|
+
else
|
160
|
+
name + year
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
5
164
|
end
|
data/researchmap2bib.gemspec
CHANGED
@@ -19,7 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "rubyzip", ">= 1.0.0"
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 1.12"
|
23
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
26
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "guard"
|
29
|
+
spec.add_development_dependency "guard-minitest"
|
25
30
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: researchmap2bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshihide Chubachi
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyzip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,48 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
55
111
|
description: This script creates bibliography files which can be used by LaTeX from
|
56
112
|
researchmap.
|
57
113
|
email:
|
@@ -64,6 +120,7 @@ files:
|
|
64
120
|
- ".gitignore"
|
65
121
|
- ".travis.yml"
|
66
122
|
- Gemfile
|
123
|
+
- Guardfile
|
67
124
|
- LICENSE.txt
|
68
125
|
- README.md
|
69
126
|
- Rakefile
|