citeproc-rb 0.0.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.
- data/README +93 -0
- data/Rakefile +73 -0
- data/TODO +25 -0
- data/VERSION +1 -0
- data/data/locales/locales_en.xml +89 -0
- data/data/locales/locales_nl.xml +96 -0
- data/data/styles/ama.csl +184 -0
- data/data/styles/apa.csl +230 -0
- data/data/styles/apsa.csl +175 -0
- data/data/styles/asa.csl +215 -0
- data/data/styles/chicago-author-date.csl +361 -0
- data/data/styles/chicago-fullnote-bibliography.csl +665 -0
- data/data/styles/chicago-note-bibliography.csl +437 -0
- data/data/styles/chicago-note.csl +383 -0
- data/data/styles/harvard.csl +185 -0
- data/data/styles/ieee.csl +111 -0
- data/data/styles/mhra.csl +317 -0
- data/data/styles/mla.csl +173 -0
- data/data/styles/nature.csl +87 -0
- data/data/styles/nlm.csl +118 -0
- data/examples/citeproc_driver.rb +174 -0
- data/lib/citeproc.rb +28 -0
- data/lib/citeproc/csl.rb +647 -0
- data/lib/citeproc/csl_parser.rb +479 -0
- data/lib/citeproc/csl_processor.rb +485 -0
- data/lib/citeproc/csl_reference.rb +228 -0
- data/lib/citeproc/filters/bibo/bibo.rb +635 -0
- data/lib/citeproc/filters/bibo/bibo_input_filter.rb +242 -0
- data/lib/citeproc/filters/bibo/bibo_utils.rb +75 -0
- data/lib/citeproc/filters/csl_citation/csl_citation.rb +137 -0
- data/lib/citeproc/filters/csl_citation/csl_citation_input_filter.rb +274 -0
- data/lib/citeproc/formatters/base_formatter.rb +115 -0
- data/lib/citeproc/formatters/xhtml_formatter.rb +144 -0
- data/lib/citeproc/input_filter.rb +97 -0
- data/test/fixtures/bibo_test_data.n3 +191 -0
- data/test/fixtures/bibo_test_data.yaml +96 -0
- data/test/fixtures/bibo_test_how_to_cook.n3 +63 -0
- data/test/fixtures/bibo_test_zotero.rdf +129 -0
- data/test/fixtures/csl_test_data.json +62 -0
- data/test/fixtures/csl_test_data.yaml +8 -0
- data/test/fixtures/locales/test_locale_en.xml +89 -0
- data/test/fixtures/styles/test_csl_parse.csl +230 -0
- data/test/fixtures/styles/test_groups.csl +32 -0
- data/test/fixtures/styles/test_names.csl +46 -0
- data/test/fixtures/styles/test_sort.csl +125 -0
- data/test/fixtures/styles/test_text_terms.csl +40 -0
- data/test/test_all.rb +14 -0
- data/test/test_bibo.rb +20 -0
- data/test/test_csl.rb +136 -0
- data/test/test_csl_parser.rb +222 -0
- data/test/test_sample_bibo.rb +82 -0
- metadata +101 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# == Synopsis
|
|
2
|
+
#
|
|
3
|
+
# Resolves CSL variables to the underlying Bibliontology model.
|
|
4
|
+
#
|
|
5
|
+
# == Author
|
|
6
|
+
#
|
|
7
|
+
# Liam Magee
|
|
8
|
+
#
|
|
9
|
+
# == Copyright
|
|
10
|
+
#
|
|
11
|
+
# Copyright (c) 2007, Liam Magee.
|
|
12
|
+
# Licensed under the same terms as Ruby - see http://www.ruby-lang.org/en/LICENSE.txt.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module Bibo
|
|
17
|
+
class BiboInputFilter < Citeproc::InputFilter
|
|
18
|
+
|
|
19
|
+
# Loads the citations from +source+, based on the content_type passed in the +params+.
|
|
20
|
+
def load_citations(source, params)
|
|
21
|
+
io = source.read
|
|
22
|
+
content_type = params[:content_type]
|
|
23
|
+
|
|
24
|
+
# Try loading the citations as either a YAML file
|
|
25
|
+
case content_type.downcase
|
|
26
|
+
when "yaml"
|
|
27
|
+
require 'yaml'
|
|
28
|
+
results = YAML.load(io)
|
|
29
|
+
if results.kind_of? Hash
|
|
30
|
+
@citations = results
|
|
31
|
+
else
|
|
32
|
+
print_type_error(results, "YAML should contain either a Document or an Array of documents.")
|
|
33
|
+
end
|
|
34
|
+
when "json"
|
|
35
|
+
require 'json'
|
|
36
|
+
results = JSON.parse(io)
|
|
37
|
+
when "rdf"
|
|
38
|
+
# Use Redland here...
|
|
39
|
+
else
|
|
40
|
+
raise RuntimeError.new("Unsupported content-type: " + content_type.inspect + ". Must be either YAML or JSON.")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def extract_contributor(role)
|
|
47
|
+
@current_citation.each_contribution do |contrib|
|
|
48
|
+
yield contrib.contributor if role == contrib.role.name
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# Tests the document class, and returns the corresponding CSL type
|
|
55
|
+
def resolve_type
|
|
56
|
+
case @current_citation.class
|
|
57
|
+
when Bibo::Book
|
|
58
|
+
'book'
|
|
59
|
+
# Need to add more
|
|
60
|
+
else
|
|
61
|
+
'article' # Reasonable default?
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def extract_date(variable)
|
|
66
|
+
case variable
|
|
67
|
+
when "issued"
|
|
68
|
+
@current_citation.date
|
|
69
|
+
when "event" # Kludgy way of handling event - treat as presentation
|
|
70
|
+
@current_citation.presented_at.time.start if @current_citation.presented_at and @current_citation.presented_at.time
|
|
71
|
+
when "accessed"
|
|
72
|
+
@current_citation.accessed
|
|
73
|
+
when "container"
|
|
74
|
+
@current_citation.belongs_to.date if @current_citation.belongs_to
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Very simple check on the value of the locator (or, in specific cases, of other document
|
|
80
|
+
# variables) to determine whether
|
|
81
|
+
# It may be be better to simply return the locator value here
|
|
82
|
+
def extract_label(variable)
|
|
83
|
+
singular = true
|
|
84
|
+
if variable == 'page'
|
|
85
|
+
singlular = (@current_citation.pages and @current_citation.pages.include?('-'))
|
|
86
|
+
locator_type = variable
|
|
87
|
+
else
|
|
88
|
+
locator_type = @current_citation.locator_type
|
|
89
|
+
case @current_citation.locator_type
|
|
90
|
+
when 'issue'
|
|
91
|
+
singlular = (@current_citation.issue and @current_citation.issue.include?('-'))
|
|
92
|
+
when 'page'
|
|
93
|
+
singlular = (@current_citation.pages and @current_citation.pages.include?('-'))
|
|
94
|
+
when 'volume'
|
|
95
|
+
singlular = (@current_citation.volume and @current_citation.volume.include?('-'))
|
|
96
|
+
else
|
|
97
|
+
singlular = (@current_citation.locator and @current_citation.locator.include?('-'))
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
return locator_type, singular
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def extract_variable(variable)
|
|
106
|
+
case variable
|
|
107
|
+
|
|
108
|
+
## the primary title for the cited item
|
|
109
|
+
when 'author', 'editor', 'translator'
|
|
110
|
+
@current_citation.contributions.each do |contrib|
|
|
111
|
+
if contrib.role == variable
|
|
112
|
+
return contrib.contributor
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
## the primary title for the cited item
|
|
117
|
+
when 'title'
|
|
118
|
+
@current_citation.title
|
|
119
|
+
|
|
120
|
+
## the secondary title for the cited item; for a book chapter, this
|
|
121
|
+
## would be a book title, for an article the journal title, etc.
|
|
122
|
+
when 'container-title'
|
|
123
|
+
@current_citation.belongs_to.title if @current_citation.belongs_to
|
|
124
|
+
|
|
125
|
+
## the tertiary title for the cited item; for example, a series title
|
|
126
|
+
when 'collection-title'
|
|
127
|
+
@current_citation.belongs_to.belongs_to.title if @current_citation.belongs_to and @current_citation.belongs_to.belongs_to
|
|
128
|
+
|
|
129
|
+
## title of a related original version; often useful in cases of translation
|
|
130
|
+
when "original-title"
|
|
131
|
+
@current_citation.translation_of.title if @current_citation.translation_of
|
|
132
|
+
@current_citation.review_of.title if @current_citation.review_of
|
|
133
|
+
@current_citation.transcript_of.title if @current_citation.transcript_of
|
|
134
|
+
|
|
135
|
+
## the name of the publisher
|
|
136
|
+
when "publisher"
|
|
137
|
+
@current_citation.publisher
|
|
138
|
+
|
|
139
|
+
## the location of the publisher
|
|
140
|
+
when "publisher-place"
|
|
141
|
+
@current_citation.place.name if @current_citation.place
|
|
142
|
+
|
|
143
|
+
## the name of the archive
|
|
144
|
+
when "archive"
|
|
145
|
+
# @current_citation.title
|
|
146
|
+
|
|
147
|
+
## the location of the archive
|
|
148
|
+
when "archive-place"
|
|
149
|
+
# @current_citation.title
|
|
150
|
+
|
|
151
|
+
## the location within an archival collection (for example, box and folder)
|
|
152
|
+
when "archive_location"
|
|
153
|
+
# @current_citation.title
|
|
154
|
+
|
|
155
|
+
## the name or title of a related event such as a conference or hearing
|
|
156
|
+
when "event"
|
|
157
|
+
@current_citation.presented_at.name if @current_citation.presented_at
|
|
158
|
+
|
|
159
|
+
## the location or place for the related event
|
|
160
|
+
when "event-place"
|
|
161
|
+
@current_citation.presented_at.place.name if @current_citation.presented_at and @current_citation.presented_at.place
|
|
162
|
+
|
|
163
|
+
##
|
|
164
|
+
when "page"
|
|
165
|
+
@current_citation.pages
|
|
166
|
+
|
|
167
|
+
## a description to locate an item within some larger container or
|
|
168
|
+
## collection; a volume or issue number is a kind of locator, for example.
|
|
169
|
+
when "locator"
|
|
170
|
+
@current_citation.locator
|
|
171
|
+
|
|
172
|
+
## version description
|
|
173
|
+
when "version"
|
|
174
|
+
@current_citation.version
|
|
175
|
+
|
|
176
|
+
## volume number for the container periodical
|
|
177
|
+
when "volume"
|
|
178
|
+
@current_citation.volume
|
|
179
|
+
|
|
180
|
+
## refers to the number of items in multi-volume books and such
|
|
181
|
+
when "number-of-volumes"
|
|
182
|
+
# ??
|
|
183
|
+
|
|
184
|
+
## the issue number for the container publication
|
|
185
|
+
when "issue"
|
|
186
|
+
@current_citation.issue
|
|
187
|
+
|
|
188
|
+
##
|
|
189
|
+
when "chapter-number"
|
|
190
|
+
@current_citation.number
|
|
191
|
+
|
|
192
|
+
## medium description (DVD, CD, etc.)
|
|
193
|
+
when "medium"
|
|
194
|
+
@current_citation.format
|
|
195
|
+
|
|
196
|
+
## the (typically publication) status of an item; for example "forthcoming"
|
|
197
|
+
when "status"
|
|
198
|
+
@current_citation.status
|
|
199
|
+
|
|
200
|
+
## an edition description
|
|
201
|
+
when "edition"
|
|
202
|
+
@current_citation.edition
|
|
203
|
+
|
|
204
|
+
##
|
|
205
|
+
when "genre"
|
|
206
|
+
@current_citation.genre
|
|
207
|
+
|
|
208
|
+
## a short inline note, often used to refer to additional details of the resource
|
|
209
|
+
when "note"
|
|
210
|
+
@current_citation.note
|
|
211
|
+
|
|
212
|
+
## notes made by a reader about the content of the resource
|
|
213
|
+
when "annote"
|
|
214
|
+
@current_citation.annote
|
|
215
|
+
|
|
216
|
+
##
|
|
217
|
+
when "abstract"
|
|
218
|
+
@current_citation.abstract
|
|
219
|
+
|
|
220
|
+
##
|
|
221
|
+
when "keyword"
|
|
222
|
+
@current_citation.keyword
|
|
223
|
+
|
|
224
|
+
## a document number; useful for reports and such
|
|
225
|
+
when "number"
|
|
226
|
+
@current_citation.number
|
|
227
|
+
|
|
228
|
+
##
|
|
229
|
+
when "URL"
|
|
230
|
+
@current_citation.uri
|
|
231
|
+
|
|
232
|
+
##
|
|
233
|
+
when "DOI"
|
|
234
|
+
@current_citation.doi
|
|
235
|
+
|
|
236
|
+
##
|
|
237
|
+
when "ISBN"
|
|
238
|
+
@current_citation.isbn10
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# == Synopsis
|
|
2
|
+
#
|
|
3
|
+
# Utility methods for generating, loading and storing Bibliontology models
|
|
4
|
+
#
|
|
5
|
+
# == Author
|
|
6
|
+
#
|
|
7
|
+
# Liam Magee
|
|
8
|
+
#
|
|
9
|
+
# == Copyright
|
|
10
|
+
#
|
|
11
|
+
# Copyright (c) 2007, Liam Magee.
|
|
12
|
+
# Licensed under the same terms as Ruby - see http://www.ruby-lang.org/en/LICENSE.txt.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
require 'yaml'
|
|
16
|
+
|
|
17
|
+
module Bibo
|
|
18
|
+
module BiboUtils
|
|
19
|
+
include Bibo
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Save/load methods for YAML
|
|
23
|
+
|
|
24
|
+
# Load the sample document from a YAML file
|
|
25
|
+
def self.from_yaml(file)
|
|
26
|
+
YAML.load(File.new(file))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Load the sample document from a YAML file
|
|
31
|
+
def self.from_yaml(file, document)
|
|
32
|
+
YAML.dump(document, File.new(file, "w+"))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Load the sample document from a RDF file
|
|
37
|
+
def self.rdf_model(file, name = "rdfxml")
|
|
38
|
+
require 'rdf/redland'
|
|
39
|
+
model = Redland::Model.new
|
|
40
|
+
parser = Redland::Parser.new(name, "")
|
|
41
|
+
parser.parse_into_model(model, file)
|
|
42
|
+
model
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Load the sample document from a RDF file
|
|
47
|
+
def self.from_rdf(file, name = "rdfxml")
|
|
48
|
+
require 'rdf/redland'
|
|
49
|
+
model = rdf_model(file, name)
|
|
50
|
+
model.triples do |s, p, o|
|
|
51
|
+
case p.to_s
|
|
52
|
+
when /type/
|
|
53
|
+
os = o.to_s
|
|
54
|
+
#puts os[os.rindex('/') + 1..os.rindex(']') - 1]
|
|
55
|
+
else
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
model
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# Provide a command-line interface to the parser
|
|
64
|
+
if __FILE__ == $0
|
|
65
|
+
if ARGV[0] and ARGV[1]
|
|
66
|
+
if (ARGV[0] == '-l' or ARGV[0] == '--load')
|
|
67
|
+
puts from_yaml(ARGV[1]).to_yaml
|
|
68
|
+
else
|
|
69
|
+
puts "Not doing anything."
|
|
70
|
+
to_yaml(ARGV[1])
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# == Synopsis
|
|
2
|
+
#
|
|
3
|
+
# Simple citation model
|
|
4
|
+
#
|
|
5
|
+
# == Author
|
|
6
|
+
#
|
|
7
|
+
# Liam Magee
|
|
8
|
+
#
|
|
9
|
+
# == Copyright
|
|
10
|
+
#
|
|
11
|
+
# Copyright (c) 2008, Liam Magee.
|
|
12
|
+
# Licensed under the same terms as Ruby - see http://www.ruby-lang.org/en/LICENSE.txt.
|
|
13
|
+
#
|
|
14
|
+
#
|
|
15
|
+
|
|
16
|
+
module CSL
|
|
17
|
+
|
|
18
|
+
# ---------- Classes -----------
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Defines the Citation class
|
|
22
|
+
class Citation
|
|
23
|
+
attr_accessor :type
|
|
24
|
+
attr_accessor :title, :container_title, :collection_title
|
|
25
|
+
attr_accessor :publisher, :publisher_place
|
|
26
|
+
attr_accessor :event, :event_place
|
|
27
|
+
attr_accessor :pages, :version, :volume, :number_of_volumes, :issue
|
|
28
|
+
attr_accessor :medium, :status, :edition, :note, :annote, :abstract
|
|
29
|
+
attr_accessor :keyword, :number
|
|
30
|
+
attr_accessor :archive, :archive_location, :archive_place
|
|
31
|
+
attr_accessor :url, :doi, :isbn
|
|
32
|
+
attr_accessor :date_issued, :date_accessed
|
|
33
|
+
attr_accessor :contributors
|
|
34
|
+
|
|
35
|
+
def initialize
|
|
36
|
+
@contributors = []
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def method_missing(name, *args)
|
|
40
|
+
case name.to_s
|
|
41
|
+
when "locator"
|
|
42
|
+
return resolve_locator
|
|
43
|
+
else
|
|
44
|
+
""
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def authors=(authors)
|
|
49
|
+
add_contributors(authors, "author")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def authors
|
|
53
|
+
contributors("author")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def editors=(editors)
|
|
57
|
+
add_contributors(editors, "editor")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def editors
|
|
61
|
+
contributors("editor")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def translators=(translators)
|
|
65
|
+
add_contributors(translators, "translator")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def translators
|
|
69
|
+
translators("translator")
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def contributors(role = nil, sort_key = nil)
|
|
73
|
+
results = @contributors.collect{|c| c if c.role and c.role == role }.compact
|
|
74
|
+
if sort_key
|
|
75
|
+
if sort_key == "first"
|
|
76
|
+
results.sort!{ |a, b| a.given_name <=> b.given_name }
|
|
77
|
+
else
|
|
78
|
+
results.sort!{ |a, b| a.name <=> b.name }
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
results
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def add_contributor_name(name, role = "author")
|
|
86
|
+
c = ContributingAgent.new
|
|
87
|
+
c.name = name
|
|
88
|
+
c.role = role
|
|
89
|
+
add_contributor(c)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def add_contributor(contributor)
|
|
93
|
+
@contributors << contributor if contributor.is_a?(ContributingAgent)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def add_contributors(contribs, role = "author")
|
|
97
|
+
contribs.each do |contrib|
|
|
98
|
+
c = ContributingAgent.new
|
|
99
|
+
c.role = role
|
|
100
|
+
contrib.each do |key, value|
|
|
101
|
+
c.send("#{key}=", value)
|
|
102
|
+
end
|
|
103
|
+
@contributors << c
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def resolve_locator
|
|
108
|
+
result = nil
|
|
109
|
+
result ||= self.issue
|
|
110
|
+
result ||= self.volume
|
|
111
|
+
result ||= self.url
|
|
112
|
+
result
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Defines the Citation class
|
|
118
|
+
class ContributingAgent
|
|
119
|
+
attr_accessor :name, :role
|
|
120
|
+
|
|
121
|
+
def initialize(role = "author", name = nil)
|
|
122
|
+
@role = role
|
|
123
|
+
@name = name
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def given_name
|
|
127
|
+
# brittle....
|
|
128
|
+
name.split(/, /)[1]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def family_name
|
|
132
|
+
# brittle....
|
|
133
|
+
name.split(/, /)[0]
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
end
|