citation 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/citation/citation.rb +20 -49
- data/lib/citation/rules/apa.rb +26 -0
- data/lib/citation/rules/base.rb +11 -0
- data/lib/citation/rules/iso.rb +22 -0
- data/lib/citation/rules/mla.rb +26 -0
- data/lib/citation/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2a8afb97fc644a93cd0304a13a88e1a80cf348b
|
4
|
+
data.tar.gz: 544201f296624df7b1dc1538222a485e21222643
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98fed2ac0f201b0ff770e8a3f0f548d4fe2366547ad8b1c1a0d75d37b341244f7f82ba509a3fa64e16a28b2fbfcc098b050e7024131f810a681e51f3b7b05ad9
|
7
|
+
data.tar.gz: 2e033505322ca312197f059cf6016b4d5c6d777b49afa826251e9afbb0bcd91aba05158e96fcf730dfabfd9890ecb6cc532679e889bd2daf0b928a93aa3e5daa
|
data/lib/citation/citation.rb
CHANGED
@@ -3,6 +3,9 @@ lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
|
|
3
3
|
$:.unshift lib
|
4
4
|
require 'uri'
|
5
5
|
require 'time'
|
6
|
+
require 'rules/mla'
|
7
|
+
require 'rules/apa'
|
8
|
+
require 'rules/iso'
|
6
9
|
|
7
10
|
module Citation
|
8
11
|
class Base
|
@@ -31,7 +34,6 @@ module Citation
|
|
31
34
|
when 'ISO'
|
32
35
|
str = "#{@author} #{@title} #{@desc}, #{@year}."
|
33
36
|
when 'bibtex'
|
34
|
-
|
35
37
|
str = "@article{#{@author.gsub(' ','').gsub(/( |\.|,)/,'').downcase[0..5]}#{@year}#{@title.split.select{|i| i.length >3 }[0].downcase},
|
36
38
|
title={#{@title}},
|
37
39
|
author={#{@author.gsub(', and ',', ')}},
|
@@ -53,7 +55,7 @@ module Citation
|
|
53
55
|
base.url = urls
|
54
56
|
|
55
57
|
# fetch square bracket
|
56
|
-
bracket_matcher = string.match(/\[([
|
58
|
+
bracket_matcher = string.match(/\[([a-zA-Z0-9_ ]).+\]/)
|
57
59
|
base.sq = bracket_matcher[0] unless bracket_matcher.nil?
|
58
60
|
string.slice!(base.sq)
|
59
61
|
|
@@ -66,59 +68,28 @@ module Citation
|
|
66
68
|
string.slice!(base.year)
|
67
69
|
|
68
70
|
# fetch title if format is MLA
|
69
|
-
|
70
|
-
|
71
|
-
base.title = title_matcher[0] unless title_matcher.nil?
|
72
|
-
s = string.split(base.title)
|
73
|
-
string.slice!(base.title)
|
74
|
-
string.slice!('()')
|
75
|
-
base.title.gsub!('"','')
|
76
|
-
|
77
|
-
author = s.shift
|
78
|
-
base.author = author
|
79
|
-
base.desc = s.shift
|
80
|
-
base.type = 'MLA'.to_sym
|
81
|
-
|
82
|
-
string.slice!(base.author)
|
83
|
-
string.slice!(base.desc)
|
71
|
+
if MLA.satisfy?(string, base)
|
72
|
+
string, base.title, base.author, base.desc, base.type = MLA.fetch(string, base)
|
84
73
|
end
|
85
74
|
|
86
|
-
|
87
|
-
|
88
|
-
if base.type.empty? and not title_matcher.nil?
|
89
|
-
base.title = title_matcher[0] unless title_matcher.nil?
|
90
|
-
base.title.gsub!(/"|\(\)\. /,'')
|
91
|
-
|
92
|
-
string.slice!(base.title)
|
93
|
-
s = string.split('(). ')
|
94
|
-
author = s.shift
|
95
|
-
base.author = author
|
96
|
-
base.desc = s.shift
|
97
|
-
base.type = 'APA'.to_sym
|
98
|
-
string.slice!(base.author)
|
99
|
-
string.slice!(base.desc)
|
75
|
+
if APA.satisfy?(string, base)
|
76
|
+
string, base.title, base.author, base.desc, base.type = APA.fetch(string, base)
|
100
77
|
end
|
101
78
|
|
102
79
|
|
103
|
-
|
104
|
-
|
105
|
-
if base.type.empty? and not iso_matcher.nil?
|
106
|
-
s = string.gsub(/ ([A-Z]). /,'_\1_ ')
|
107
|
-
arr = s.split('. ')
|
108
|
-
base.author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
|
109
|
-
base.title = arr.shift if base.title == ''
|
110
|
-
base.desc = arr.shift
|
111
|
-
base.type = 'ISO 6900'.to_sym
|
80
|
+
if ISO.satisfy?(string, base)
|
81
|
+
string, base.title, base.author, base.desc, base.type = ISO.fetch(string, base)
|
112
82
|
end
|
113
83
|
|
114
84
|
|
115
85
|
# fetch other
|
116
86
|
if base.type.empty?
|
117
|
-
s = string.gsub(/ ([A-Z])
|
87
|
+
s = string.gsub(/ ([A-Z]).,{0,1} /,'_\1_ ')
|
88
|
+
s.gsub!('()','')
|
118
89
|
arr = s.split('. ')
|
119
90
|
base.author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
|
120
|
-
base.title = arr.shift if base.title == ''
|
121
|
-
base.desc = arr
|
91
|
+
base.title = arr.shift if base.title == '' or base.title.nil?
|
92
|
+
base.desc = arr.join(' ')
|
122
93
|
end
|
123
94
|
return base
|
124
95
|
|
@@ -128,20 +99,20 @@ end
|
|
128
99
|
|
129
100
|
if __FILE__ == $0
|
130
101
|
test = '[B ́at09] Norbert B ́atfai. On the Running Time of the Shortest Programs. CoRR, abs/0908.1159, 2009. http://arxiv.org/abs/0908.1159.'
|
131
|
-
|
102
|
+
p Citation.parse(test, false)
|
132
103
|
# MLA
|
133
104
|
test = 'Bátfai, Norbert. "A disembodied developmental robotic agent called Samu B\'atfai." arXiv preprint arXiv:1511.02889 (2015).'
|
134
|
-
|
105
|
+
p Citation.parse(test, false)
|
135
106
|
|
136
107
|
# APA
|
137
108
|
test = 'Bátfai, N. (2015). A disembodied developmental robotic agent called Samu B\'atfai. arXiv preprint arXiv:1511.02889.'
|
138
|
-
|
109
|
+
p Citation.parse(test, false)
|
139
110
|
|
140
111
|
# ISO 690
|
141
112
|
test = 'BÁTFAI, Norbert. A disembodied developmental robotic agent called Samu B\'atfai. arXiv preprint arXiv:1511.02889, 2015.'
|
142
|
-
|
113
|
+
p Citation.parse(test, false)
|
143
114
|
test = 'MacKay, D. J. C., & Peto, L. C. B. (1995). A hierarchical Dirichlet language model. Natural Language Engineer- ing, 1, 289–307.'
|
144
|
-
|
115
|
+
p Citation.parse(test, false)
|
145
116
|
test = '[20] Y. Teh, M. Jordan, M. Beal, and D. Blei. Hierarchical Dirichlet processes. Journal of the American Statistical Association, 101(476):1566–1581, 2007.'
|
146
|
-
|
117
|
+
p Citation.parse(test,false).out('bibtex')
|
147
118
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
|
4
|
+
$:.unshift lib
|
5
|
+
require 'base'
|
6
|
+
|
7
|
+
class APA < RuleBase
|
8
|
+
def self.satisfy?(string, base)
|
9
|
+
@matcher = string.match(/\(\)\. .+\. /)
|
10
|
+
base.type.empty? and not @matcher.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.fetch(string, base)
|
14
|
+
title = @matcher[0] unless @matcher.nil?
|
15
|
+
title.gsub!(/"|\(\)\. /,'')
|
16
|
+
string.slice!(title)
|
17
|
+
|
18
|
+
s = string.split('(). ')
|
19
|
+
author = s.shift
|
20
|
+
desc = s.shift
|
21
|
+
type = 'APA'.to_sym
|
22
|
+
string.slice!(author) unless string.empty?
|
23
|
+
string.slice!(desc) unless string.empty?
|
24
|
+
return string, title, author, desc, type
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
|
3
|
+
$:.unshift lib
|
4
|
+
require 'base'
|
5
|
+
|
6
|
+
class ISO < RuleBase
|
7
|
+
def self.satisfy?(string, base)
|
8
|
+
@matcher = string.match(/, \.$/)
|
9
|
+
base.type.empty? and not @matcher.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch(string, base)
|
13
|
+
s = string.gsub(/ ([A-Z]). /,'_\1_ ')
|
14
|
+
string.gsub!('()','')
|
15
|
+
arr = s.split('. ')
|
16
|
+
author = arr.shift.gsub(/_([A-Z])_ /,' \1. ')
|
17
|
+
title = arr.shift if title == '' or title.nil?
|
18
|
+
desc = arr.shift
|
19
|
+
type = 'ISO 6900'.to_sym
|
20
|
+
return string, title, author, desc, type
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
lib = Pathname.new(__FILE__).dirname.join().expand_path.to_s
|
3
|
+
$:.unshift lib
|
4
|
+
require 'base'
|
5
|
+
|
6
|
+
class MLA < RuleBase
|
7
|
+
def self.satisfy?(string, base)
|
8
|
+
@matcher = string.match(/".+"/)
|
9
|
+
!@matcher.nil?
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.fetch(string, base)
|
13
|
+
title = @matcher[0]
|
14
|
+
string.slice!('()')
|
15
|
+
s = string.split(title)
|
16
|
+
string.slice!(title)
|
17
|
+
title.gsub!('"','')
|
18
|
+
|
19
|
+
author = s.shift
|
20
|
+
desc = s.shift
|
21
|
+
type = 'MLA'.to_sym
|
22
|
+
string.slice!(author) unless string.empty?
|
23
|
+
string.slice!(desc) unless string.empty?
|
24
|
+
return string, title, author, desc, type
|
25
|
+
end
|
26
|
+
end
|
data/lib/citation/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: citation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Nishimura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,6 +93,10 @@ files:
|
|
93
93
|
- lib/citation.rb
|
94
94
|
- lib/citation/citation.rb
|
95
95
|
- lib/citation/entrypoint.rb
|
96
|
+
- lib/citation/rules/apa.rb
|
97
|
+
- lib/citation/rules/base.rb
|
98
|
+
- lib/citation/rules/iso.rb
|
99
|
+
- lib/citation/rules/mla.rb
|
96
100
|
- lib/citation/version.rb
|
97
101
|
homepage: https://github.com/nishimuuu/citation
|
98
102
|
licenses:
|