relaton 3.1.4 → 3.1.6
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/README.adoc +1 -0
- data/lib/relaton/arxiv/README.adoc +59 -0
- data/lib/relaton/arxiv/api.rb +42 -0
- data/lib/relaton/arxiv/bibliography.rb +45 -0
- data/lib/relaton/arxiv/parser.rb +167 -0
- data/lib/relaton/arxiv/processor.rb +66 -0
- data/lib/relaton/arxiv/util.rb +8 -0
- data/lib/relaton/arxiv.rb +23 -0
- data/lib/relaton/bib/converter/endnote/from_endnote.rb +118 -0
- data/lib/relaton/bib/converter/endnote/to_endnote.rb +107 -0
- data/lib/relaton/bib/converter/endnote.rb +30 -0
- data/lib/relaton/bib/converter/ris/from_ris.rb +144 -0
- data/lib/relaton/bib/converter/ris/to_ris.rb +92 -0
- data/lib/relaton/bib/converter/ris.rb +7 -81
- data/lib/relaton/bib/item_data.rb +4 -0
- data/lib/relaton/bib.rb +1 -0
- data/lib/relaton/bibcollection.rb +45 -83
- data/lib/relaton/cie/data_fetcher.rb +142 -13
- data/lib/relaton/cli/base_convertor.rb +19 -3
- data/lib/relaton/cli/command.rb +19 -5
- data/lib/relaton/cli/relaton_file.rb +101 -64
- data/lib/relaton/cli/subcommand_collection.rb +6 -24
- data/lib/relaton/cli/xml_convertor.rb +6 -5
- data/lib/relaton/cli/xml_to_html_renderer.rb +15 -9
- data/lib/relaton/cli.rb +79 -20
- data/lib/relaton/collection_xml.rb +145 -0
- data/lib/relaton/db/registry.rb +6 -2
- data/lib/relaton/doi/README.adoc +14 -3
- data/lib/relaton/doi/crossref.rb +2 -12
- data/lib/relaton/doi/datacite.rb +40 -0
- data/lib/relaton/doi/datacite_parser.rb +301 -0
- data/lib/relaton/doi/http.rb +86 -0
- data/lib/relaton/doi/processor.rb +1 -1
- data/lib/relaton/doi/registration_agency.rb +30 -0
- data/lib/relaton/doi.rb +45 -0
- data/lib/relaton/iho/README.adoc +14 -0
- data/lib/relaton/iho/bibliography.rb +43 -1
- data/lib/relaton/iho/processor.rb +11 -0
- data/lib/relaton/iso/bibliography.rb +49 -2
- data/lib/relaton/iso/processor.rb +12 -0
- data/lib/relaton/render/iso690/styles/jis-en.yml +21 -5
- data/lib/relaton/render/iso690/styles/jis-ja.yml +11 -4
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton-cli.rb +0 -1
- data/lib/relaton.rb +1 -0
- metadata +23 -7
- data/lib/relaton/element_finder.rb +0 -29
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3bed664b07a9dda567a823e7ba2afff7ede3e389c2dce08cb98cf8a1d51640e
|
|
4
|
+
data.tar.gz: '04366806572fed9a003199d9195532bd63839af87f8563e849002cc39bebb224'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39010cd2e132c65750a98c51ec281948a6103b2cc23430540b5063a1f1db888227be6bd3028827faf11f76ba8c22e91446d4291a799f3bbdd20f9474c8309013
|
|
7
|
+
data.tar.gz: 056445dddddc6095e22842608733cfd4051c359814e90ce48587123df21ec7a2f576456df9fe0b9ec6c05c9ba367cd2cbe80c7e54703bc05c76c04804df306fd
|
data/README.adoc
CHANGED
|
@@ -508,6 +508,7 @@ usage and architecture notes.
|
|
|
508
508
|
Standards bodies:
|
|
509
509
|
|
|
510
510
|
link:lib/relaton/3gpp/README.adoc[3gpp],
|
|
511
|
+
link:lib/relaton/arxiv/README.adoc[arxiv],
|
|
511
512
|
link:lib/relaton/bipm/README.adoc[bipm],
|
|
512
513
|
link:lib/relaton/bsi/README.adoc[bsi],
|
|
513
514
|
link:lib/relaton/calconnect/README.adoc[calconnect],
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
= Relaton::Arxiv: retrieves arXiv e-prints from the arXiv API
|
|
2
|
+
|
|
3
|
+
`Relaton::Arxiv` fetches the metadata of an https://arxiv.org[arXiv] e-print
|
|
4
|
+
from the https://info.arxiv.org/help/api/[arXiv API] and answers a
|
|
5
|
+
`Relaton::Bib::ItemData`.
|
|
6
|
+
|
|
7
|
+
== Usage
|
|
8
|
+
|
|
9
|
+
`Relaton::Arxiv::Bibliography.get` takes an arXiv id, with or without the
|
|
10
|
+
`arXiv:` prefix (any case) and with or without a version. An id with no
|
|
11
|
+
version answers the latest version.
|
|
12
|
+
|
|
13
|
+
[source,ruby]
|
|
14
|
+
----
|
|
15
|
+
require "relaton/arxiv"
|
|
16
|
+
|
|
17
|
+
item = Relaton::Arxiv::Bibliography.get "arXiv:1706.03762"
|
|
18
|
+
[relaton-arxiv] INFO: (arXiv:1706.03762) Fetching from arXiv ...
|
|
19
|
+
[relaton-arxiv] INFO: (arXiv:1706.03762) Found: `arXiv:1706.03762v7`
|
|
20
|
+
|
|
21
|
+
item.docidentifier.map(&:content)
|
|
22
|
+
=> ["arXiv:1706.03762v7", "10.48550/arXiv.1706.03762"]
|
|
23
|
+
|
|
24
|
+
# an old-style id, a version
|
|
25
|
+
Relaton::Arxiv::Bibliography.get "arxiv:hep-th/9901001v2"
|
|
26
|
+
----
|
|
27
|
+
|
|
28
|
+
Through `Relaton::Db`:
|
|
29
|
+
|
|
30
|
+
[source,ruby]
|
|
31
|
+
----
|
|
32
|
+
require "relaton"
|
|
33
|
+
|
|
34
|
+
Relaton::Db.new("cache", nil).fetch "arXiv:2301.00001"
|
|
35
|
+
----
|
|
36
|
+
|
|
37
|
+
== Identifiers
|
|
38
|
+
|
|
39
|
+
Both arXiv id schemes are read (https://info.arxiv.org/help/arxiv_identifier_for_services.html):
|
|
40
|
+
|
|
41
|
+
* new: `YYMM.NNNN` (0704 to 1412), `YYMM.NNNNN` (from 1501), as `2301.00001v1`;
|
|
42
|
+
* old: `archive[.SC]/YYMMNNN`, as `hep-th/9901001`, `math.GT/0309136`.
|
|
43
|
+
|
|
44
|
+
== Data model
|
|
45
|
+
|
|
46
|
+
[cols="1,2"]
|
|
47
|
+
|===
|
|
48
|
+
| Atom element | `Bib::ItemData`
|
|
49
|
+
|
|
50
|
+
| `id` | primary docidentifier `arXiv` (versioned), `version`; and a docidentifier `DOI` `10.48550/arXiv.<id>`
|
|
51
|
+
| `title` | `title` (`main`)
|
|
52
|
+
| `summary` | `abstract`
|
|
53
|
+
| `published`, `updated` | `date`
|
|
54
|
+
| `author` (`name`, `arxiv:affiliation`) | contributor, role `author`
|
|
55
|
+
| `arxiv:primary_category`, `category` | `keyword` (the primary first)
|
|
56
|
+
| `link` (`alternate`, `pdf`) | `source` (`src`, `pdf`)
|
|
57
|
+
| `arxiv:journal_ref` | `note` (`journal-ref`); the type is then `article`, else `misc`
|
|
58
|
+
| `arxiv:doi` | relation `hasManifestation` to the journal article
|
|
59
|
+
|===
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Arxiv
|
|
3
|
+
#
|
|
4
|
+
# The arXiv API (https://info.arxiv.org/help/api/). One `id_list` query
|
|
5
|
+
# answers one Atom feed; an unversioned id answers the latest version.
|
|
6
|
+
#
|
|
7
|
+
module Api
|
|
8
|
+
extend self
|
|
9
|
+
|
|
10
|
+
ENDPOINT = "https://export.arxiv.org/api/query".freeze
|
|
11
|
+
|
|
12
|
+
# Transport failures, raised as `Relaton::RequestError` so that
|
|
13
|
+
# `Db#net_retry` retries them (as `Relaton::Doi::Http` does).
|
|
14
|
+
NETWORK_ERRORS = [
|
|
15
|
+
SocketError, SystemCallError, Timeout::Error, OpenSSL::SSL::SSLError,
|
|
16
|
+
EOFError, IOError, Net::ProtocolError
|
|
17
|
+
].freeze
|
|
18
|
+
|
|
19
|
+
#
|
|
20
|
+
# The Atom feed for an arXiv id. A feed with no entry is how arXiv
|
|
21
|
+
# answers an id it does not have, so only a transport failure raises.
|
|
22
|
+
#
|
|
23
|
+
# @param id [String] the bare id, `2301.00001v1` or `hep-th/9901001`
|
|
24
|
+
# @return [String] the Atom XML
|
|
25
|
+
# @raise [Relaton::RequestError] a non-200 answer or a network failure
|
|
26
|
+
#
|
|
27
|
+
def feed(id)
|
|
28
|
+
uri = URI ENDPOINT
|
|
29
|
+
uri.query = URI.encode_www_form(id_list: id)
|
|
30
|
+
response = Net::HTTP.get_response uri
|
|
31
|
+
unless response.is_a? Net::HTTPSuccess
|
|
32
|
+
raise Relaton::RequestError,
|
|
33
|
+
"arXiv API answered #{response.code} for #{id}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
response.body.dup.force_encoding Encoding::UTF_8
|
|
37
|
+
rescue *NETWORK_ERRORS => e
|
|
38
|
+
raise Relaton::RequestError, "arXiv API: #{e.class}: #{e.message}"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Arxiv
|
|
3
|
+
#
|
|
4
|
+
# Fetch an arXiv e-print by its id.
|
|
5
|
+
#
|
|
6
|
+
module Bibliography
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# @param ref [String, Pubid::Arxiv::Identifier] `arXiv:2301.00001v1`,
|
|
11
|
+
# `arxiv:hep-th/9901001`; a parsed pubid is not mutated
|
|
12
|
+
# @param _year [String, nil] ignored: the id carries its year
|
|
13
|
+
# @param _opts [Hash]
|
|
14
|
+
# @return [Relaton::Bib::ItemData, nil]
|
|
15
|
+
# @raise [Relaton::RequestError] the arXiv API did not answer
|
|
16
|
+
#
|
|
17
|
+
def get(ref, _year = nil, _opts = {})
|
|
18
|
+
pubid = ref.is_a?(::Pubid::Arxiv::Identifier) ? ref : parse(ref)
|
|
19
|
+
unless pubid
|
|
20
|
+
Util.info "Not an arXiv identifier.", key: ref.to_s
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Util.info "Fetching from arXiv ...", key: pubid.to_s
|
|
25
|
+
item = Parser.parse Api.feed(pubid.to_s(with_publisher: false))
|
|
26
|
+
if item
|
|
27
|
+
Util.info "Found: `#{item.docidentifier.first.content}`", key: pubid.to_s
|
|
28
|
+
else
|
|
29
|
+
Util.info "Not found.", key: pubid.to_s
|
|
30
|
+
end
|
|
31
|
+
item
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
#
|
|
35
|
+
# @param ref [String]
|
|
36
|
+
# @return [Pubid::Arxiv::Identifier, nil]
|
|
37
|
+
#
|
|
38
|
+
def parse(ref)
|
|
39
|
+
::Pubid::Arxiv.parse ref.strip
|
|
40
|
+
rescue ArgumentError, ::Pubid::Errors::Error
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
module Relaton
|
|
2
|
+
module Arxiv
|
|
3
|
+
#
|
|
4
|
+
# Map the entry of an arXiv API Atom feed to a `Bib::ItemData`. Elements
|
|
5
|
+
# are found by local name: Atom elements have the default namespace, and
|
|
6
|
+
# the arXiv extensions (`arxiv:doi`, `arxiv:journal_ref`, …) their own.
|
|
7
|
+
#
|
|
8
|
+
class Parser
|
|
9
|
+
ATTRS = %i[type fetched title docidentifier source date contributor
|
|
10
|
+
abstract version keyword note relation ext].freeze
|
|
11
|
+
|
|
12
|
+
# The DOI prefix under which arXiv registers each e-print with DataCite.
|
|
13
|
+
DOI_PREFIX = "10.48550/arXiv.".freeze
|
|
14
|
+
|
|
15
|
+
ID_PATTERN = %r{\Ahttps?://arxiv\.org/abs/(?<id>.+?)(?:v(?<version>\d+))?\z}
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# @param xml [String] the Atom feed
|
|
19
|
+
# @return [Relaton::Bib::ItemData, nil] nil when the feed has no entry,
|
|
20
|
+
# or only arXiv's error entry (`<id>https://arxiv.org/api/errors#…`),
|
|
21
|
+
# which is how arXiv answers an id it rejects
|
|
22
|
+
#
|
|
23
|
+
def self.parse(xml)
|
|
24
|
+
doc = Moxml.new.parse xml
|
|
25
|
+
entry = doc.xpath("//*[local-name()='entry']").first
|
|
26
|
+
return unless entry
|
|
27
|
+
|
|
28
|
+
id = entry.children.detect { |n| n.is_a?(Moxml::Element) && n.name == "id" }
|
|
29
|
+
match = id && ID_PATTERN.match(id.text.strip)
|
|
30
|
+
new(entry, match).parse if match
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param entry [Moxml::Element]
|
|
34
|
+
# @param id [MatchData] the entry id matched by ID_PATTERN
|
|
35
|
+
def initialize(entry, id)
|
|
36
|
+
@entry = entry
|
|
37
|
+
@id = id
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @return [Relaton::Bib::ItemData]
|
|
41
|
+
def parse
|
|
42
|
+
Bib::ItemData.new(**ATTRS.to_h { |a| [a, send("parse_#{a}")] })
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def children(name)
|
|
48
|
+
@entry.children.select { |n| n.is_a?(Moxml::Element) && n.name == name }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def text(name, node = @entry)
|
|
52
|
+
el = node.children.detect { |n| n.is_a?(Moxml::Element) && n.name == name }
|
|
53
|
+
el && squeeze(el.text)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def squeeze(str)
|
|
57
|
+
str.to_s.gsub(/\s+/, " ").strip
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def bare_id = @id[:id]
|
|
61
|
+
|
|
62
|
+
# An e-print a journal published is cited as an article; otherwise it
|
|
63
|
+
# is a preprint.
|
|
64
|
+
def parse_type
|
|
65
|
+
text("journal_ref") ? "article" : "misc"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def parse_fetched = Date.today.to_s
|
|
69
|
+
|
|
70
|
+
def parse_title
|
|
71
|
+
title = text("title")
|
|
72
|
+
title && !title.empty? ? [Bib::Title.new(type: "main", content: title)] : []
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def parse_docidentifier
|
|
76
|
+
versioned = "arXiv:#{bare_id}#{"v#{@id[:version]}" if @id[:version]}"
|
|
77
|
+
[
|
|
78
|
+
Bib::Docidentifier.new(type: "arXiv", content: versioned, primary: true),
|
|
79
|
+
Bib::Docidentifier.new(type: "DOI", content: "#{DOI_PREFIX}#{bare_id}"),
|
|
80
|
+
]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def parse_source
|
|
84
|
+
children("link").filter_map do |link|
|
|
85
|
+
case [link["rel"], link["title"]]
|
|
86
|
+
in ["alternate", _] then Bib::Uri.new(type: "src", content: link["href"])
|
|
87
|
+
in ["related", "pdf"] then Bib::Uri.new(type: "pdf", content: link["href"])
|
|
88
|
+
else nil
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def parse_date
|
|
94
|
+
%w[published updated].filter_map do |type|
|
|
95
|
+
value = text(type)
|
|
96
|
+
Bib::Date.new(type: type, at: value[0, 10]) if value && !value.empty?
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def parse_contributor
|
|
101
|
+
children("author").filter_map do |author|
|
|
102
|
+
name = text("name", author)
|
|
103
|
+
next if name.nil? || name.empty?
|
|
104
|
+
|
|
105
|
+
Bib::Contributor.new(
|
|
106
|
+
person: create_person(name, author),
|
|
107
|
+
role: [Bib::Contributor::Role.new(type: "author")],
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def create_person(name, author)
|
|
113
|
+
affiliation = author.children.filter_map do |n|
|
|
114
|
+
next unless n.is_a?(Moxml::Element) && n.name == "affiliation"
|
|
115
|
+
|
|
116
|
+
org = Bib::Organization.new(
|
|
117
|
+
name: [Bib::TypedLocalizedString.new(content: squeeze(n.text))],
|
|
118
|
+
)
|
|
119
|
+
Bib::Affiliation.new(organization: org)
|
|
120
|
+
end
|
|
121
|
+
Bib::Person.new(
|
|
122
|
+
name: Bib::FullName.new(completename: Bib::LocalizedString.new(content: name)),
|
|
123
|
+
affiliation: affiliation,
|
|
124
|
+
)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def parse_abstract
|
|
128
|
+
summary = text("summary")
|
|
129
|
+
summary && !summary.empty? ? [Bib::Abstract.new(content: summary)] : []
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def parse_version
|
|
133
|
+
@id[:version] ? [Bib::Version.new(content: @id[:version])] : []
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# The categories, the primary first.
|
|
137
|
+
def parse_keyword
|
|
138
|
+
primary = children("primary_category").first&.[]("term")
|
|
139
|
+
terms = children("category").map { |c| c["term"] }
|
|
140
|
+
([primary] + terms).compact.uniq.map do |term|
|
|
141
|
+
Bib::Keyword.new(vocab: Bib::LocalizedString.new(content: term))
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def parse_note
|
|
146
|
+
ref = text("journal_ref")
|
|
147
|
+
ref ? [Bib::Note.new(type: "journal-ref", content: ref)] : []
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# The journal article an e-print became, by the DOI arXiv records.
|
|
151
|
+
def parse_relation
|
|
152
|
+
doi = text("doi")
|
|
153
|
+
return [] unless doi && !doi.empty?
|
|
154
|
+
|
|
155
|
+
# An ItemData, not an ItemBase: the YAML serializer rejects an
|
|
156
|
+
# ItemBase in a relation (Lutaml::Model::IncorrectModelError).
|
|
157
|
+
docid = Bib::Docidentifier.new(type: "DOI", content: doi)
|
|
158
|
+
[Bib::Relation.new(type: "hasManifestation",
|
|
159
|
+
bibitem: Bib::ItemData.new(docidentifier: [docid]))]
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def parse_ext
|
|
163
|
+
Bib::Ext.new(flavor: "arxiv")
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require_relative "../core/processor"
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
module Arxiv
|
|
5
|
+
class Processor < Relaton::Core::Processor
|
|
6
|
+
attr_reader :idtype
|
|
7
|
+
|
|
8
|
+
def initialize # rubocop:disable Lint/MissingSuper
|
|
9
|
+
@short = :relaton_arxiv
|
|
10
|
+
@prefix = "arXiv"
|
|
11
|
+
@pubid_flavor = :Arxiv # prefixes and the Db cache key
|
|
12
|
+
@defaultprefix = /^arXiv[:\s]/i
|
|
13
|
+
@idtype = "arXiv"
|
|
14
|
+
@datasets = %w[]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @param code [String, Pubid::Arxiv::Identifier]
|
|
18
|
+
# @param date [String, nil] year (ignored: the id carries it)
|
|
19
|
+
# @param opts [Hash]
|
|
20
|
+
# @return [Relaton::Bib::ItemData, nil]
|
|
21
|
+
def get(code, date, opts)
|
|
22
|
+
require_relative "../arxiv"
|
|
23
|
+
::Relaton::Arxiv::Bibliography.get(code, date, opts)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# `Pubid.parse` routes by a case-sensitive prefix; `Pubid::Arxiv.parse`
|
|
27
|
+
# also reads `arxiv:…` and a bare id.
|
|
28
|
+
def cache_pubid(ref)
|
|
29
|
+
require "pubid"
|
|
30
|
+
::Pubid::Arxiv.parse ref.strip
|
|
31
|
+
rescue ArgumentError, ::Pubid::Errors::Error
|
|
32
|
+
require_relative "../bib"
|
|
33
|
+
Relaton::Bib::Util.info "does not parse as an arXiv id; passing " \
|
|
34
|
+
"the reference to the flavor as written",
|
|
35
|
+
"relaton-db", key: ref
|
|
36
|
+
nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# An arXiv id carries its year and month, and they are identity: a
|
|
40
|
+
# year option must not make a key for another month's paper.
|
|
41
|
+
def fold_year(pubid, _year)
|
|
42
|
+
pubid
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# @param xml [String]
|
|
46
|
+
# @return [Relaton::Bib::ItemData]
|
|
47
|
+
def from_xml(xml)
|
|
48
|
+
require_relative "../arxiv"
|
|
49
|
+
::Relaton::Bib::Bibitem.from_xml xml
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @param hash [Hash]
|
|
53
|
+
# @return [Relaton::Bib::ItemData]
|
|
54
|
+
def from_yaml(hash)
|
|
55
|
+
require_relative "../arxiv"
|
|
56
|
+
::Relaton::Bib::Bibitem.from_hash hash
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# @return [String]
|
|
60
|
+
def grammar_hash
|
|
61
|
+
require_relative "../arxiv"
|
|
62
|
+
@grammar_hash ||= ::Relaton::Arxiv.grammar_hash
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "digest/md5"
|
|
3
|
+
require "pubid"
|
|
4
|
+
require "moxml"
|
|
5
|
+
require_relative "bib"
|
|
6
|
+
require_relative "version"
|
|
7
|
+
require_relative "core/request_error"
|
|
8
|
+
require_relative "arxiv/util"
|
|
9
|
+
require_relative "arxiv/parser"
|
|
10
|
+
require_relative "arxiv/api"
|
|
11
|
+
require_relative "arxiv/bibliography"
|
|
12
|
+
|
|
13
|
+
module Relaton
|
|
14
|
+
# arXiv e-prints, from the arXiv API (relaton#42).
|
|
15
|
+
module Arxiv
|
|
16
|
+
module_function
|
|
17
|
+
|
|
18
|
+
# @return [String]
|
|
19
|
+
def grammar_hash
|
|
20
|
+
Digest::MD5.hexdigest Relaton::VERSION
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
module Bib
|
|
5
|
+
module Converter
|
|
6
|
+
module Endnote
|
|
7
|
+
class FromEndnote
|
|
8
|
+
TAG_LINE = /\A%([A-Z@]) (.*)\z/
|
|
9
|
+
|
|
10
|
+
# @param refer_str [String]
|
|
11
|
+
# @return [Hash{String=>Relaton::Bib::ItemData}] keyed by the
|
|
12
|
+
# first title (Refer has no identifier tag), falling back to
|
|
13
|
+
# the record position
|
|
14
|
+
def self.parse(refer_str)
|
|
15
|
+
refer_str.split(/\n\s*\n/).map(&:lines).reject(&:empty?)
|
|
16
|
+
.each_with_object({}).with_index do |(record_lines, hash), i|
|
|
17
|
+
item = new(record_lines).item
|
|
18
|
+
title = Array(item.title).first&.content.to_s
|
|
19
|
+
hash[title.empty? ? "record-#{i + 1}" : title] = item
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @param record_lines [Array<String>]
|
|
24
|
+
def initialize(record_lines)
|
|
25
|
+
@tags = Hash.new { |h, k| h[k] = [] }
|
|
26
|
+
record_lines.each do |line|
|
|
27
|
+
next unless (m = line.chomp.match(TAG_LINE))
|
|
28
|
+
|
|
29
|
+
@tags[m[1]] << m[2]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Relaton::Bib::ItemData]
|
|
34
|
+
def item
|
|
35
|
+
ItemData.new(
|
|
36
|
+
docidentifier: fetch_docid,
|
|
37
|
+
title: fetch_title,
|
|
38
|
+
date: fetch_date,
|
|
39
|
+
contributor: fetch_contributor,
|
|
40
|
+
edition: fetch_edition,
|
|
41
|
+
series: fetch_series,
|
|
42
|
+
keyword: fetch_keyword,
|
|
43
|
+
source: fetch_source,
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
# Refer has no identifier tag; a %R is some dialects' report
|
|
50
|
+
# number, not a docidentifier — none is invented here.
|
|
51
|
+
def fetch_docid
|
|
52
|
+
[]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def fetch_title
|
|
56
|
+
@tags["T"].map { |v| Title.new(type: "title-main", content: v) }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Refer dates are "YYYY" or a free-form date string.
|
|
60
|
+
def fetch_date
|
|
61
|
+
@tags["D"].map do |v|
|
|
62
|
+
on = v.match?(/\A\d{4}\z/) ? v : (::Date.parse(v).to_s rescue v)
|
|
63
|
+
Bib::Date.new(type: "published", at: on)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# "Surname, Forename" names a person; a bare token is an
|
|
68
|
+
# organization (the same convention the RIS importer applies to
|
|
69
|
+
# this converter's own output).
|
|
70
|
+
def fetch_contributor
|
|
71
|
+
contribs = []
|
|
72
|
+
@tags["A"].each do |name|
|
|
73
|
+
contribs << if name.include?(",")
|
|
74
|
+
person_contributor(name)
|
|
75
|
+
else
|
|
76
|
+
org_contributor(name, "author")
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
@tags["I"].each { |name| contribs << org_contributor(name, "publisher") }
|
|
80
|
+
contribs
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def person_contributor(name)
|
|
84
|
+
parts = name.split(", ")
|
|
85
|
+
surname = LocalizedString.new(content: parts.first)
|
|
86
|
+
forename = (parts[1] || "").split.map { |fn| FullNameType::Forename.new(content: fn) }
|
|
87
|
+
person = Person.new(name: FullName.new(surname: surname, forename: forename))
|
|
88
|
+
Contributor.new(person: person, role: [Contributor::Role.new(type: "author")])
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def org_contributor(name, role)
|
|
92
|
+
org = Organization.new(name: [TypedLocalizedString.new(content: name)])
|
|
93
|
+
Contributor.new(organization: org, role: [Contributor::Role.new(type: role)])
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def fetch_edition
|
|
97
|
+
Edition.new(content: @tags["@"].first.to_s) if @tags["@"].any?
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def fetch_series
|
|
101
|
+
series = []
|
|
102
|
+
@tags["J"].each { |v| series << Series.new(type: "journal", title: Title.new(content: v)) }
|
|
103
|
+
@tags["S"].each { |v| series << Series.new(title: Title.new(content: v)) }
|
|
104
|
+
series
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def fetch_keyword
|
|
108
|
+
@tags["K"].map { |v| Keyword.new(vocab: LocalizedString.new(content: v)) }
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def fetch_source
|
|
112
|
+
@tags["U"].map { |v| Uri.new(type: "src", content: v) }
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
module Bib
|
|
5
|
+
module Converter
|
|
6
|
+
module Endnote
|
|
7
|
+
class ToEndnote
|
|
8
|
+
# @param item [Relaton::Bib::ItemData]
|
|
9
|
+
def initialize(item)
|
|
10
|
+
@item = item
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @return [String] one Refer record (no trailing blank line)
|
|
14
|
+
def to_s
|
|
15
|
+
lines = []
|
|
16
|
+
add_authors(lines)
|
|
17
|
+
add_field(lines, "%T", primary_title)
|
|
18
|
+
add_field(lines, "%D", published_year)
|
|
19
|
+
add_field(lines, "%@", @item.edition&.to_s)
|
|
20
|
+
add_field(lines, "%I", publisher_name)
|
|
21
|
+
add_journal(lines)
|
|
22
|
+
add_series(lines)
|
|
23
|
+
Array(@item.keyword).each { |k| add_field(lines, "%K", k.vocab.content.to_s) }
|
|
24
|
+
add_field(lines, "%U", source_uri)
|
|
25
|
+
lines.join("\n") + "\n"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def add_field(lines, tag, value)
|
|
31
|
+
lines << "#{tag} #{value}" if value && !value.empty?
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# The same authorish/publisher split the RIS renderer makes.
|
|
35
|
+
def add_authors(lines)
|
|
36
|
+
Array(@item.contributor).each do |c|
|
|
37
|
+
roles = Array(c.role).map(&:type).compact
|
|
38
|
+
authorish = (roles & %w[author performer editor]).any?
|
|
39
|
+
if authorish && c.person
|
|
40
|
+
out = person_display_name(c.person.name)
|
|
41
|
+
add_field(lines, "%A", out) unless out.empty?
|
|
42
|
+
elsif authorish && c.organization
|
|
43
|
+
out = org_name(c.organization)
|
|
44
|
+
add_field(lines, "%A", out) unless out.empty?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def person_display_name(name)
|
|
50
|
+
return "" unless name
|
|
51
|
+
|
|
52
|
+
fore = Array(name.forename).map { |f| f.respond_to?(:content) ? f.content.to_s : f.to_s }.join(" ")
|
|
53
|
+
sur = name.surname.respond_to?(:content) ? name.surname.content.to_s : name.surname.to_s
|
|
54
|
+
complete = name.completename.respond_to?(:content) ? name.completename.content.to_s : name.completename.to_s
|
|
55
|
+
return "#{sur}, #{fore}" unless fore.empty? || sur.empty?
|
|
56
|
+
return sur unless sur.empty?
|
|
57
|
+
|
|
58
|
+
complete
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def org_name(org)
|
|
62
|
+
name = Array(org.name).map { |n| n.respond_to?(:content) ? n.content.to_s : n.to_s }.find(&:itself)
|
|
63
|
+
name || org.abbreviation.to_s
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def publisher_name
|
|
67
|
+
pub = Array(@item.contributor).find do |c|
|
|
68
|
+
Array(c.role).map(&:type).include?("publisher") && c.organization
|
|
69
|
+
end
|
|
70
|
+
pub && org_name(pub.organization)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# %J is the journal series; %S a plain series. An item carries at
|
|
74
|
+
# most one of each in this mapping.
|
|
75
|
+
def add_journal(lines)
|
|
76
|
+
journal = Array(@item.series).find { |s| s.type == "journal" }
|
|
77
|
+
add_field(lines, "%J", series_title(journal)) if journal
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def add_series(lines)
|
|
81
|
+
series = Array(@item.series).reject { |s| s.type == "journal" }.first
|
|
82
|
+
add_field(lines, "%S", series_title(series)) if series
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def series_title(series)
|
|
86
|
+
Array(series.title).map { |t| t.respond_to?(:content) ? t.content.to_s : t.to_s }.find(&:itself)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def primary_title
|
|
90
|
+
Titles.of(@item)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def published_year
|
|
94
|
+
date = Array(@item.date).find { |d| %w[published issued].include?(d.type.to_s) } || @item.date.first
|
|
95
|
+
value = date && (date.at || date.from || date.to)
|
|
96
|
+
value.to_s[/\d{4}/]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def source_uri
|
|
100
|
+
Array(@item.source).map { |s| s.respond_to?(:content) ? s.content.to_s : s.to_s }
|
|
101
|
+
.find { |u| u.start_with?("http") }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "endnote/from_endnote"
|
|
4
|
+
require_relative "endnote/to_endnote"
|
|
5
|
+
|
|
6
|
+
module Relaton
|
|
7
|
+
module Bib
|
|
8
|
+
module Converter
|
|
9
|
+
module Endnote
|
|
10
|
+
# Refer-format field tags (the EndNote "tagged format"): one
|
|
11
|
+
# `%X value` line per field, records separated by a blank line.
|
|
12
|
+
TAGS = {
|
|
13
|
+
author: "%A", title: "%T", date: "%D", publisher: "%I",
|
|
14
|
+
edition: "%@", keyword: "%K", url: "%U", journal: "%J",
|
|
15
|
+
series: "%S",
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
# ItemData -> Refer string
|
|
19
|
+
def self.from_item(item)
|
|
20
|
+
ToEndnote.new(item).to_s
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Refer string -> Hash{String=>ItemData}
|
|
24
|
+
def self.to_item(refer_str)
|
|
25
|
+
FromEndnote.parse(refer_str)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|