bibtex-ruby 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bibtex-ruby might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae103a8c9230f10e182351e8c51e2d221d346bec
4
- data.tar.gz: 81648119699714f234735ba3734bb317ab44786c
3
+ metadata.gz: 8579fc07e8437d733ae2593adedd2e9b9a53cdc6
4
+ data.tar.gz: 8bc0cb71db6ce4b2e80fe1385251e8f261cc6b8b
5
5
  SHA512:
6
- metadata.gz: 1a5367f8a072bf8bd4bc941159d4741b221716c452f1c7feef319990c7c9cf5b20f0dacaa996673199e1b138ead4a406955f313f9b04c60d5e3a5267ebafbd2c
7
- data.tar.gz: 7d1c9b931e9a42ee05e577fea66b193b9858feff69ab36337c2664c57219abf9e082869c5571a91426f8b1bc3999e14c1964b58c39da651e5af7a7a865d6056c
6
+ metadata.gz: 5fc0d42f2a46852bb5d3c9f837ae9870a6c0a12511da63157d9f6955fd86dc95ebf1ab67b6c8df355754d2c54f97b75934e1135573865b0066871f14d23a2354
7
+ data.tar.gz: 08560e71aae34c126709a9ea6ba7cb016702c246201948af8952ad81ea8e56370532d932fbc836d20a6950d1da7b0841b540f3835e1a5d11efd494552c56adbe
data/Gemfile CHANGED
@@ -1,38 +1,50 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- # RDF Export
5
- gem 'rdf', '~>0.3'
4
+ gem 'rdf', '~>1.1'
5
+ gem 'json', '~>1.8', :platforms => [:mri_18, :jruby, :rbx]
6
6
 
7
+ gem 'rubysl', '~>2.0', :platforms => :rbx
7
8
 
8
9
  group :debug do
9
- gem 'debugger', :require => false, :platforms => [:mri_19, :mri_20]
10
+ gem 'debugger', :require => false, :platforms => [:mri_19, :mri_20, :mri_21]
10
11
  gem 'ruby-debug', :require => false, :platforms => [:mri_18]
12
+ gem 'rubinius-debugger', :require => false, :platforms => :rbx
13
+ gem 'rubinius-compiler', :require => false, :platforms => :rbx
11
14
  end
12
15
 
13
16
  group :test do
14
- gem 'minitest', '~>4.0'
15
- gem 'minitest-colorize'
16
- gem 'cucumber', ['~>1.0']
17
- gem 'unicode', :platforms => [:rbx, :mswin, :mingw, :mri_19, :mri_20]
17
+ gem 'minitest', '~>4.7', :require => false
18
+ gem 'rubysl-test-unit', '~>2.0', :platforms => :rbx
19
+ gem 'minitest-ansi'
20
+ gem 'cucumber', '~>1.3'
21
+ gem 'unicode', '~>0.4', :platforms => [:rbx, :mswin, :mingw, :mri_19, :mri_20, :mri_21]
18
22
  end
19
23
 
20
24
  group :extra do
21
- gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
22
- gem 'guard-minitest', :platforms => [:ruby_20]
23
- gem 'guard-cucumber', :platforms => [:ruby_20]
24
- gem 'redcarpet', :platforms => [:rbx, :mri_20, :mri_19]
25
+ if RUBY_PLATFORM =~ /darwin/i
26
+ gem 'rb-fsevent', :require => false
27
+ end
28
+
29
+ gem 'guard-minitest', :platforms => [:ruby_21, :ruby_20, :ruby_19]
30
+ gem 'guard-cucumber', :platforms => [:ruby_21, :ruby_20, :ruby_19]
31
+ gem 'redcarpet', :platforms => [:ruby_21, :ruby_20, :ruby_19]
25
32
  end
26
33
 
27
34
  group :profile do
28
- gem 'ruby-prof', ['~>0.10'], :platforms => [:mri_19, :mri_20]
29
- gem 'gnuplot', ['~>2.4']
30
- gem 'simplecov'
35
+ gem 'ruby-prof', '~>0.14', :platforms => [:mri_19, :mri_20, :mri_21]
36
+ gem 'gnuplot', '~>2.4', :platforms => [:mri_19, :mri_20, :mri_21]
37
+ gem 'simplecov', '~>0.8', :require => false, :platforms => [:ruby_21, :ruby_20]
38
+ gem 'rubinius-coverage', :require => false, :platforms => :rbx
31
39
  end
32
40
 
33
41
  group :development do
34
42
  gem 'rake'
35
- gem 'racc', :platforms => [:mri_20, :mri_19]
36
- gem 'yard'
37
- gem 'iconv', :platforms => [:ruby_20]
43
+ gem 'yard'
44
+ gem 'iconv', :platforms => [:ruby_20, :ruby_21]
45
+ end
46
+
47
+ group :travis do
48
+ # Gem is required at runtime for RBX!
49
+ gem 'racc', :platforms => [:ruby_21, :ruby_20, :ruby_19]
38
50
  end
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ 3.1.0 / 2014-01-20
2
+ ==================
3
+
4
+ * Fixed and refactored RDF Export (@tmaier)
5
+
1
6
  3.0.1 / 2013-12-30
2
7
  ==================
3
8
 
data/Manifest CHANGED
@@ -39,11 +39,17 @@ features/support/env.rb
39
39
  lib
40
40
  lib/bibtex
41
41
  lib/bibtex.rb
42
+ lib/bibtex/bibliography
42
43
  lib/bibtex/bibliography.rb
44
+ lib/bibtex/bibliography/rdf_converter.rb
43
45
  lib/bibtex/bibtex.y
44
46
  lib/bibtex/compatibility.rb
45
47
  lib/bibtex/elements.rb
48
+ lib/bibtex/entry
46
49
  lib/bibtex/entry.rb
50
+ lib/bibtex/entry/bibtexml_converter.rb
51
+ lib/bibtex/entry/citeproc_converter.rb
52
+ lib/bibtex/entry/rdf_converter.rb
47
53
  lib/bibtex/error.rb
48
54
  lib/bibtex/extensions.rb
49
55
  lib/bibtex/filters
@@ -63,6 +69,8 @@ lib/bibtex/version.rb
63
69
  test
64
70
  test/benchmark.rb
65
71
  test/bibtex
72
+ test/bibtex/entry
73
+ test/bibtex/entry/test_rdf_converter.rb
66
74
  test/bibtex/test_bibliography.rb
67
75
  test/bibtex/test_elements.rb
68
76
  test/bibtex/test_entry.rb
data/README.md CHANGED
@@ -64,7 +64,7 @@ look the same in their `#sort_order(:initials => true)` form.
64
64
  Unify certain fields across the bibliography:
65
65
 
66
66
  b.unify :publisher, /o'?reilly/i, "O'Reilly"
67
-
67
+
68
68
  b.unify :publisher, /^penguin/i do |entry|
69
69
  entry.publisher = 'Penguin Books'
70
70
  entry.address = 'London'
@@ -450,7 +450,7 @@ constitutes a simple BibTeX to YAML converter:
450
450
  >> BibTeX.open('example.bib').to_yaml
451
451
 
452
452
  Starting with version 2.0, BibTeX-Ruby's `#to_xml` exports your bibliography
453
- to the [BibTeXML](http//bibtexml.sf.net/) format. By passing the option
453
+ to the [BibTeXML](http://bibtexml.sf.net/) format. By passing the option
454
454
  `:extended => true` you can make use of the BibTeXML's extended format which
455
455
  will return individual person elements and name tokens (provided you have
456
456
  successfully parsed the names of your bibliography).
@@ -468,32 +468,34 @@ successfully parsed the names of your bibliography).
468
468
  This example parse a BibTeX entry, formats it as extended BibTeXML,
469
469
  and writes the following XML to standard out:
470
470
 
471
- <?xml version='1.0' encoding='UTF-8'?>
472
- <bibtex:file xmlns:bibtex='http://bibtexml.sf.net/'>
473
- <bibtex:entry id='pickaxe'>
474
- <bibtex:book>
475
- <bibtex:address>Raleigh, North Carolina</bibtex:address>
476
- <bibtex:person>
477
- <bibtex:first>Dave</bibtex:first>
478
- <bibtex:last>Thomas</bibtex:last>
479
- </bibtex:person>
480
- <bibtex:person>
481
- <bibtex:first>Chad</bibtex:first>
482
- <bibtex:last>Fowler</bibtex:last>
483
- </bibtex:person>
484
- <bibtex:person>
485
- <bibtex:first>Andy</bibtex:first>
486
- <bibtex:last>Hunt</bibtex:last>
487
- </bibtex:person>
488
- <bibtex:author/>
489
- <bibtex:publisher>The Pragmatic Bookshelf</bibtex:publisher>
490
- <bibtex:title>
491
- Programming Ruby 1.9: The Pragmatic Programmer&apos;s Guide
492
- </bibtex:title>
493
- <bibtex:year>2009</bibtex:year>
494
- </bibtex:book>
495
- </bibtex:entry>
496
- </bibtex:file>
471
+ ```xml
472
+ <?xml version='1.0' encoding='UTF-8'?>
473
+ <bibtex:file xmlns:bibtex='http://bibtexml.sf.net/'>
474
+ <bibtex:entry id='pickaxe'>
475
+ <bibtex:book>
476
+ <bibtex:address>Raleigh, North Carolina</bibtex:address>
477
+ <bibtex:person>
478
+ <bibtex:first>Dave</bibtex:first>
479
+ <bibtex:last>Thomas</bibtex:last>
480
+ </bibtex:person>
481
+ <bibtex:person>
482
+ <bibtex:first>Chad</bibtex:first>
483
+ <bibtex:last>Fowler</bibtex:last>
484
+ </bibtex:person>
485
+ <bibtex:person>
486
+ <bibtex:first>Andy</bibtex:first>
487
+ <bibtex:last>Hunt</bibtex:last>
488
+ </bibtex:person>
489
+ <bibtex:author/>
490
+ <bibtex:publisher>The Pragmatic Bookshelf</bibtex:publisher>
491
+ <bibtex:title>
492
+ Programming Ruby 1.9: The Pragmatic Programmer&apos;s Guide
493
+ </bibtex:title>
494
+ <bibtex:year>2009</bibtex:year>
495
+ </bibtex:book>
496
+ </bibtex:entry>
497
+ </bibtex:file>
498
+ ```
497
499
 
498
500
  Look at the 'examples' directory for more elaborate examples of a BibTeX to
499
501
  YAML and a BibTeX to HTML converter using **#to_citeproc** to format a
@@ -554,13 +556,13 @@ For more information about the BibTeX format and the parser's idiosyncrasies
554
556
  Contributing
555
557
  ------------
556
558
  The BibTeX-Ruby source code is
557
- [hosted on GitHub](http://github.com/inukshuk/bibtex-ruby/).
559
+ [hosted on GitHub](https://github.com/inukshuk/bibtex-ruby/).
558
560
  You can check out a copy of the latest code using Git:
559
561
 
560
562
  $ git clone https://github.com/inukshuk/bibtex-ruby.git
561
563
 
562
564
  If you've found a bug or have a question, please open an issue on the
563
- [BibTeX-Ruby issue tracker](http://github.com/inukshuk/bibtex-ruby/issues).
565
+ [BibTeX-Ruby issue tracker](https://github.com/inukshuk/bibtex-ruby/issues).
564
566
  For extra credit, clone the BibTeX-Ruby repository, write a failing
565
567
  example, or cucumber feature, fix the bug and submit a pull request (for
566
568
  useful examples, take a look at the cucumber features in the
@@ -587,7 +589,7 @@ To execute the test suite continuously while you're working run:
587
589
  Credits
588
590
  -------
589
591
 
590
- Copyright 2011-2013 [Sylvester Keil](http://sylvester.keil.or.at/).
592
+ Copyright 2011-2014 [Sylvester Keil](http://sylvester.keil.or.at/).
591
593
 
592
594
  Kudos to all [contributors](https://github.com/inukshuk/bibtex-ruby/contributors)
593
595
  who have made BibTeX-Ruby possible.
data/bibtex-ruby.gemspec CHANGED
@@ -24,9 +24,8 @@ Gem::Specification.new do |s|
24
24
  instructions to unicode; if you are in a hurry, it also allows for easy
25
25
  export/conversion to formats such as YAML, JSON, CSL, and XML (BibTeXML).
26
26
  END_DESCRIPTION
27
-
27
+
28
28
  s.add_runtime_dependency('latex-decode', ['>=0.0.6'])
29
- s.add_runtime_dependency('multi_json', ['~>1.3'])
30
29
 
31
30
  s.files = File.open('Manifest').readlines.map(&:chomp)
32
31
  s.test_files = Dir.glob('test/**/test*.rb')
@@ -36,4 +35,4 @@ Gem::Specification.new do |s|
36
35
  s.has_rdoc = 'yard'
37
36
  end
38
37
 
39
- # vim: syntax=ruby
38
+ # vim: syntax=ruby
@@ -8,7 +8,7 @@ Feature: Parse BibTeX files and convert LaTeX to Unicode
8
8
  When I create an entry with these elements:
9
9
  | type | author | title | location | year |
10
10
  | book | Christian Müller | Title | Berlin | 2013 |
11
- Then my bibliography should contain an entry with a key like "mu.?ller2013a"
11
+ Then my bibliography should contain an entry with a key like "mu?.?ller2013a"
12
12
 
13
13
  @default_keys
14
14
  Scenario: Multiple entries with an author whose name contains non-ASCII characters
@@ -16,5 +16,5 @@ Feature: Parse BibTeX files and convert LaTeX to Unicode
16
16
  | type | author | title | location | year |
17
17
  | book | Christian Müller | First Title | Berlin | 2013 |
18
18
  | book | Christian Müller | Second Title | Berlin | 2013 |
19
- Then my bibliography should contain an entry with a key like "mu.?ller2013a"
20
- And my bibliography should contain an entry with a key like "mu.?ller2013b"
19
+ Then my bibliography should contain an entry with a key like "mu?.?ller2013a"
20
+ And my bibliography should contain an entry with a key like "mu?.?ller2013b"
@@ -1,18 +1,20 @@
1
- begin
2
- if RUBY_VERSION > '1.8'
3
- require 'debugger'
4
- require 'simplecov'
1
+ begin
2
+ require 'simplecov'
3
+ rescue LoadError
4
+ # ignore
5
+ end
6
+
7
+ begin
8
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
9
+ require 'rubinius-debugger'
5
10
  else
6
- require 'ruby-debug'
7
- Debugger.start
11
+ require 'debugger'
8
12
  end
9
13
  rescue LoadError
10
14
  # ignore
11
15
  end
12
16
 
17
+ require 'minitest/unit'
13
18
  require 'bibtex'
14
- require 'minitest/autorun'
15
19
 
16
- World do
17
- extend Minitest::Assertions
18
- end
20
+ World(MiniTest::Assertions)
data/lib/bibtex.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2013 Sylvester Keil <sylvester.keil.or.at>
3
+ # Copyright (C) 2010-2014 Sylvester Keil <sylvester.keil.or.at>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@ require 'forwardable'
21
21
  require 'logger'
22
22
  require 'open-uri'
23
23
 
24
- require 'multi_json'
24
+ require 'json'
25
25
 
26
26
  require 'bibtex/version'
27
27
 
@@ -32,7 +32,7 @@ require 'bibtex/version'
32
32
  # +Preamble+, +Comment+, and +Entry+.
33
33
  #
34
34
  # Author:: {Sylvester Keil}[http://sylvester.keil.or.at]
35
- # Copyright:: Copyright (c) 2010-2011 Sylvester Keil
35
+ # Copyright:: Copyright (c) 2010-2014 Sylvester Keil
36
36
  # License:: GNU GPL 3.0
37
37
  #
38
38
  module BibTeX
@@ -67,7 +67,17 @@ require 'bibtex/names'
67
67
  require 'bibtex/replaceable'
68
68
  require 'bibtex/elements'
69
69
  require 'bibtex/entry'
70
+ require 'bibtex/entry/bibtexml_converter'
71
+ require 'bibtex/entry/citeproc_converter'
70
72
  require 'bibtex/error'
71
73
  require 'bibtex/parser'
72
74
  require 'bibtex/bibliography'
73
- require 'bibtex/utilities'
75
+ require 'bibtex/utilities'
76
+
77
+ begin
78
+ require 'rdf'
79
+ require 'bibtex/entry/rdf_converter'
80
+ require 'bibtex/bibliography/rdf_converter'
81
+ rescue LoadError
82
+ # ignored
83
+ end
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2013 Sylvester Keil <sylvester.keil.or.at>
3
+ # Copyright (C) 2010-2014 Sylvester Keil <sylvester.keil.or.at>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -382,6 +382,10 @@ module BibTeX
382
382
  self
383
383
  end
384
384
 
385
+ def sort(*arguments, &block)
386
+ dup.sort!(*arguments, &block)
387
+ end
388
+
385
389
  def sort_by!(*arguments, &block)
386
390
  data.sort_by!(*arguments, &block)
387
391
  self
@@ -412,7 +416,7 @@ module BibTeX
412
416
 
413
417
  # Returns a JSON representation of the bibliography.
414
418
  def to_json(options = {})
415
- MultiJson.dump(to_a(options))
419
+ ::JSON.dump(to_a(options))
416
420
  end
417
421
 
418
422
  # Returns a CiteProc JSON representation of the bibliography. Only BibTeX enrties are exported.
@@ -440,17 +444,11 @@ module BibTeX
440
444
  # Returns an RDF::Graph representation of the bibliography. The graph
441
445
  # can be serialized using any of the RDF serializer plugins.
442
446
  def to_rdf(options = {})
443
- require 'rdf'
444
-
445
- graph = RDF::Graph.new
446
-
447
- q('@entry').each do |entry|
448
- graph << entry.to_rdf(options)
447
+ if defined?(::RDF)
448
+ RDFConverter.convert(self)
449
+ else
450
+ BibTeX.log.error 'Please `gem install rdf` for RDF support.'
449
451
  end
450
-
451
- graph
452
- rescue LoadError
453
- BibTeX.log.error "Please gem install rdf for RDF support."
454
452
  end
455
453
 
456
454
  # call-seq:
@@ -0,0 +1,27 @@
1
+ class BibTeX::Bibliography::RDFConverter
2
+ # converts a BibTeX Bibliography to RDF
3
+ # @return [RDF::Graph] the RDF graph of the bibliography
4
+ def self.convert(bibtex)
5
+ new(bibtex).convert!
6
+ end
7
+
8
+ # @param [BibTeX::Entry] the bibliography to convert
9
+ def initialize(bibtex, graph = RDF::Graph.new)
10
+ @bibtex = bibtex
11
+ @graph = graph
12
+ @agent = {}
13
+ end
14
+
15
+ # @return [RDF::Graph] the RDF graph of this bibliography
16
+ def convert!
17
+ bibtex.q('@entry').each do |entry|
18
+ BibTeX::Entry::RDFConverter.convert(entry, graph, agent)
19
+ end
20
+
21
+ graph
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :bibtex, :graph, :agent
27
+ end
@@ -13,7 +13,7 @@ end
13
13
  if RUBY_VERSION < '1.9'
14
14
  $KCODE = 'u'
15
15
  require 'jcode'
16
-
16
+
17
17
  BibTeX::NameParser.patterns[:upper] = /[[:upper:]ÄÖÜ][^\t\r\n\s\{\}\d\\,]*/o
18
18
  end
19
19
 
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2013 Sylvester Keil <sylvester.keil.or.at>
3
+ # Copyright (C) 2010-2014 Sylvester Keil <sylvester.keil.or.at>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -155,7 +155,7 @@ module BibTeX
155
155
  # to this method.
156
156
  options = {} unless options.is_a?(::Hash)
157
157
 
158
- MultiJson.dump(to_hash(options))
158
+ ::JSON.dump(to_hash(options))
159
159
  end
160
160
 
161
161
  def to_xml(options = {})
data/lib/bibtex/entry.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #--
2
2
  # BibTeX-Ruby
3
- # Copyright (C) 2010-2013 Sylvester Keil <sylvester.keil.or.at>
3
+ # Copyright (C) 2010-2014 Sylvester Keil <sylvester.keil.or.at>
4
4
  #
5
5
  # This program is free software: you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
@@ -65,79 +65,6 @@ module BibTeX
65
65
  end
66
66
  end
67
67
 
68
- CSL_FILTER = Hash.new {|h,k|k}.merge(Hash[*%w{
69
- date issued
70
- isbn ISBN
71
- booktitle container-title
72
- journal container-title
73
- series collection-title
74
- address publisher-place
75
- pages page
76
- number issue
77
- url URL
78
- doi DOI
79
- year issued
80
- type genre
81
- }.map(&:intern)]).freeze
82
-
83
- CSL_FIELDS = %w{ abstract annote archive archive_location archive-place
84
- authority call-number chapter-number citation-label citation-number
85
- collection-title container-title DOI edition event event-place
86
- first-reference-note-number genre ISBN issue jurisdiction keyword locator
87
- medium note number number-of-pages number-of-volumes original-publisher
88
- original-publisher-place original-title page page-first publisher
89
- publisher-place references section status title URL version volume
90
- year-suffix accessed container event-date issued original-date
91
- author editor translator recipient interviewer publisher composer
92
- original-publisher original-author container-author collection-editor
93
- }.map(&:intern).freeze
94
-
95
- CSL_TYPES = Hash.new {|h,k|k}.merge(Hash[*%w{
96
- booklet pamphlet
97
- conference paper-conference
98
- inbook chapter
99
- incollection chapter
100
- inproceedings paper-conference
101
- manual book
102
- mastersthesis thesis
103
- misc article
104
- phdthesis thesis
105
- proceedings paper-conference
106
- techreport report
107
- unpublished manuscript
108
- article article-journal
109
- }.map(&:intern)]).freeze
110
-
111
- BIBO_FIELDS = Hash[*%w{
112
- pages pages
113
- number issue
114
- isbn isbn
115
- issn issn
116
- doi doi
117
- edition edition
118
- abstract abstract
119
- volume volume
120
- }.map(&:intern)].freeze
121
-
122
- BIBO_TYPES = Hash.new(:Document).merge(Hash[*%w{
123
- booklet Book
124
- book Book
125
- conference Conference
126
- inbook Article
127
- incollection Article
128
- inproceedings Article
129
- manual Manual
130
- mastersthesis Thesis
131
- phdthesis Thesis
132
- proceedings Proceedings
133
- techreport Report
134
- journal Journal
135
- periodical Periodical
136
- unpublished Manuscript
137
- article Article
138
- }.map(&:intern)]).freeze
139
-
140
-
141
68
  attr_reader :fields, :type
142
69
 
143
70
  def_delegators :@fields, :empty?
@@ -637,7 +564,8 @@ module BibTeX
637
564
 
638
565
  # Returns true if this entry is published inside a book, collection or journal
639
566
  def contained?
640
- has_field?(:booktitle, :container, :journal)
567
+ has_field?(:container, :journal) ||
568
+ has_field?(:booktitle) && get(:booktitle) != get(:title)
641
569
  end
642
570
 
643
571
  # Returns an array containing the values associated with the given keys.
@@ -691,176 +619,24 @@ module BibTeX
691
619
  end
692
620
 
693
621
  def to_citeproc(options = {})
694
- options[:quotes] ||= []
695
-
696
- parse_names
697
- parse_month
698
-
699
- hash = {}
700
-
701
- each_pair do |k,v|
702
- hash[CSL_FILTER[k].to_s] = v.to_citeproc(options) unless DATE_FIELDS.include?(k)
703
- end
704
-
705
- hash['id'] = key.to_s
706
- hash['type'] = CSL_TYPES[type].to_s
707
-
708
- case type
709
- when :mastersthesis
710
- hash['genre'] = "Master's thesis"
711
- when :phdthesis
712
- hash['genre'] = 'PhD thesis'
713
- else
714
- # empty
715
- end unless hash.key?('genre')
716
-
717
- hash['issued'] = citeproc_date
718
-
719
- hash
622
+ CiteProcConverter.convert(self, options)
720
623
  end
721
624
 
722
- def issued
723
- return unless has_field?(:year)
724
-
725
- parts = [fields[:year].to_s]
726
-
727
- return { 'literal' => parts[0] } unless parts[0] =~ /^\d+$/
728
-
729
- if has_field?(:month)
730
- parts.push MONTHS.find_index(fields[:month].to_s.intern)
731
- parts[1] = parts[1] + 1 unless parts[1].nil?
732
- end
733
-
734
- { 'date-parts' => [parts.compact.map(&:to_i)] }
735
- end
736
-
737
- alias citeproc_date issued
738
-
739
625
  def to_xml(options = {})
740
- require 'rexml/document'
741
-
742
- xml = REXML::Element.new('bibtex:entry')
743
- xml.attributes['id'] = key
744
-
745
- entry = REXML::Element.new("bibtex:#{type}")
746
-
747
- fields.each do |key, value|
748
- field = REXML::Element.new("bibtex:#{key}")
749
-
750
- if options[:extended] && value.name?
751
- value.each { |n| entry.add_element(n.to_xml) }
752
- else
753
- field.text = value.to_s(options)
754
- end
755
-
756
- entry.add_element(field)
757
- end
758
-
759
- xml.add_element(entry)
760
- xml
626
+ BibTeXMLConverter.convert(self, options)
761
627
  end
762
628
 
763
629
  # Returns a RDF::Graph representation of the entry using the BIBO ontology.
764
- # TODO: improve level of detail captured by export
765
630
  def to_rdf(options = {})
766
- require 'rdf'
767
-
768
- bibo = RDF::Vocabulary.new('http://purl.org/ontology/bibo/')
769
-
770
- graph = RDF::Graph.new
771
- entry = RDF::URI.new(identifier)
772
-
773
- graph << [entry, RDF.type, bibo[BIBO_TYPES[type]]]
774
-
775
- [:title, :language].each do |key|
776
- graph << [entry, RDF::DC[key], get(key).to_s] if field?(key)
777
- end
778
-
779
- graph << [entry, RDF::DC.date, get(:year).to_s] if field?(:year)
780
-
781
- if field?(:publisher)
782
- address = RDF::Vocabulary.new('http://schemas.talis.com/2005/address/schema#')
783
- pub = RDF::Node.new
784
-
785
- graph << [pub, RDF.type, RDF::FOAF[:Organization]]
786
- graph << [pub, RDF::FOAF.name, get(:publisher)]
787
-
788
- graph << [pub, address[:localityName], get(:address)] if field?(:address)
789
-
790
- graph << [entry, RDF::DC.published, pub]
791
- end
792
-
793
- [:doi, :edition, :volume].each do |key|
794
- graph << [entry, bibo[key], get(key).to_s] if field?(key)
795
- end
796
-
797
- if has_field?(:pages)
798
- if get(:pages).to_s =~ /^\s*(\d+)\s*-+\s*(\d+)\s*$/
799
- graph << [entry, bibo[:pageStart], $1]
800
- graph << [entry, bibo[:pageEnd], $2]
801
- else
802
- graph << [entry, bibo[:pages], get(:pages).to_s]
803
- end
804
- end
805
-
806
- if has_field?(:author)
807
- seq = RDF::Node.new
808
-
809
- graph << [seq, RDF.type, RDF[:Seq]]
810
- graph << [entry, bibo[:authorList], seq]
811
-
812
- authors.each do |author|
813
- a = RDF::Node.new
814
-
815
- graph << [a, RDF.type, RDF::FOAF[:Person]]
816
-
817
- if author.is_a?(Name)
818
- [:given, :family, :prefix, :suffix].each do |part|
819
- graph << [a, bibo["#{part}Name"], author.send(part).to_s]
820
- end
821
- else
822
- graph << [a, RDF::FOAF.name, author.to_s]
823
- end
824
-
825
- graph << [entry, RDF::DC.creator, a]
826
- graph << [seq, RDF.li, a]
827
- end
828
- end
829
-
830
- if has_field?(:editor)
831
- seq = RDF::Node.new
832
-
833
- graph << [seq, RDF.type, RDF[:Seq]]
834
- graph << [entry, bibo[:editorList], seq]
835
-
836
- editors.each do |editor|
837
- e = RDF::Node.new
838
-
839
- graph << [e, RDF.type, RDF::FOAF[:Person]]
840
-
841
- if editor.is_a?(Name)
842
- [:given, :family, :prefix, :suffix].each do |part|
843
- graph << [e, bibo["#{part}Name"], editor.send(part).to_s]
844
- end
845
- else
846
- graph << [e, RDF::FOAF.name, editor.to_s]
847
- end
848
-
849
- graph << [entry, bibo.editor, a]
850
- graph << [seq, RDF.li, e]
851
- end
631
+ if defined?(::RDF)
632
+ RDFConverter.convert(self)
633
+ else
634
+ BibTeX.log.error 'Please `gem install rdf` for RDF support.'
852
635
  end
853
-
854
- graph
855
- rescue LoadError
856
- BibTeX.log.error "Please gem install rdf for RDF support."
857
636
  end
858
637
 
859
638
  alias to_bibo to_rdf
860
639
 
861
-
862
-
863
-
864
640
  private
865
641
 
866
642
  # Returns a default key for this entry.