arx 1.0.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +138 -17
- data/LICENSE +1 -1
- data/README.md +153 -45
- data/Rakefile +1 -1
- data/arx.gemspec +7 -5
- data/lib/arx.rb +29 -7
- data/lib/arx/categories.rb +30 -0
- data/lib/arx/cleaner.rb +2 -0
- data/lib/arx/entities/author.rb +48 -1
- data/lib/arx/entities/category.rb +46 -1
- data/lib/arx/entities/link.rb +1 -0
- data/lib/arx/entities/paper.rb +104 -13
- data/lib/arx/inspector.rb +2 -0
- data/lib/arx/query/query.rb +76 -18
- data/lib/arx/query/validate.rb +13 -0
- data/lib/arx/version.rb +1 -1
- metadata +51 -17
data/lib/arx/inspector.rb
CHANGED
@@ -2,6 +2,7 @@ module Arx
|
|
2
2
|
|
3
3
|
# Restricts +inspect+ to dump a whitelist of methods on an object.
|
4
4
|
# It will always provide `object_id` at a minimum.
|
5
|
+
#
|
5
6
|
# @private
|
6
7
|
module Inspector
|
7
8
|
|
@@ -24,6 +25,7 @@ module Arx
|
|
24
25
|
end
|
25
26
|
|
26
27
|
# Defines helper +inspector_fields+ instance variable & method, and +inspector+ instance method on the target object.
|
28
|
+
#
|
27
29
|
# @param [Object] source An arbitrary object (the object that +includes+ the +Inspector+ module).
|
28
30
|
def included(source)
|
29
31
|
inspected << source
|
data/lib/arx/query/query.rb
CHANGED
@@ -12,7 +12,9 @@ module Arx
|
|
12
12
|
search_query: 'search_query',
|
13
13
|
id_list: 'id_list',
|
14
14
|
sort_by: 'sortBy',
|
15
|
-
sort_order: 'sortOrder'
|
15
|
+
sort_order: 'sortOrder',
|
16
|
+
start: 'start',
|
17
|
+
max_results: 'max_results',
|
16
18
|
}
|
17
19
|
|
18
20
|
# Logical connectives supported by the arXiv search API.
|
@@ -23,24 +25,27 @@ module Arx
|
|
23
25
|
}
|
24
26
|
|
25
27
|
# Supported fields for the search queries made to the arXiv search API.
|
28
|
+
#
|
26
29
|
# @see https://arxiv.org/help/prep arXiv metadata fields
|
27
30
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual (query details)
|
28
31
|
FIELDS = {
|
29
|
-
title: 'ti',
|
30
|
-
author: 'au',
|
31
|
-
abstract: 'abs',
|
32
|
-
comment: 'co',
|
33
|
-
journal: 'jr',
|
34
|
-
category: 'cat',
|
35
|
-
report: 'rn',
|
36
|
-
|
32
|
+
title: 'ti', # Title
|
33
|
+
author: 'au', # Author
|
34
|
+
abstract: 'abs', # Abstract
|
35
|
+
comment: 'co', # Comment
|
36
|
+
journal: 'jr', # Journal reference
|
37
|
+
category: 'cat', # Subject category
|
38
|
+
report: 'rn', # Report number
|
39
|
+
updated_at: 'lastUpdatedDate', # Last updated date
|
40
|
+
submitted_at: 'submittedDate', # Submission date
|
41
|
+
all: 'all' # All (of the above)
|
37
42
|
}
|
38
43
|
|
39
44
|
# Supported criteria for the +sortBy+ parameter.
|
40
45
|
SORT_BY = {
|
41
46
|
relevance: 'relevance',
|
42
|
-
|
43
|
-
|
47
|
+
updated_at: 'lastUpdatedDate',
|
48
|
+
submitted_at: 'submittedDate'
|
44
49
|
}
|
45
50
|
|
46
51
|
# Supported criteria for the +sortOrder+ parameter.
|
@@ -54,8 +59,10 @@ module Arx
|
|
54
59
|
# @param ids [Array<String>] The IDs of the arXiv papers to restrict the query to.
|
55
60
|
# @param sort_by [Symbol] The sorting criteria for the returned results (see {SORT_BY}).
|
56
61
|
# @param sort_order [Symbol] The sorting order for the returned results (see {SORT_ORDER}).
|
62
|
+
# @param start [Integer] The index of the first returned result.
|
63
|
+
# @param max_results [Integer] The number of results returned by the query
|
57
64
|
# @return [Query] The initialized query object.
|
58
|
-
def initialize(*ids, sort_by: :relevance, sort_order: :descending)
|
65
|
+
def initialize(*ids, sort_by: :relevance, sort_order: :descending, start: 0, max_results: 10)
|
59
66
|
@query = String.new
|
60
67
|
|
61
68
|
Validate.sort_by sort_by, permitted: SORT_BY.keys
|
@@ -64,9 +71,12 @@ module Arx
|
|
64
71
|
Validate.sort_order sort_order, permitted: SORT_ORDER.keys
|
65
72
|
@query << "&#{PARAMS[:sort_order]}=#{SORT_ORDER[sort_order]}"
|
66
73
|
|
74
|
+
Validate.paging start, max_results
|
75
|
+
@query << "&#{PARAMS[:start]}=#{start}&#{PARAMS[:max_results]}=#{max_results}"
|
76
|
+
|
67
77
|
ids.flatten!
|
68
78
|
unless ids.empty?
|
69
|
-
ids.map!
|
79
|
+
ids.map! {|id| Cleaner.extract_id(id, version: true)}
|
70
80
|
@query << "&#{PARAMS[:id_list]}=#{ids * ','}"
|
71
81
|
end
|
72
82
|
|
@@ -75,16 +85,19 @@ module Arx
|
|
75
85
|
|
76
86
|
# @!method and
|
77
87
|
# Logical conjunction (+AND+) of subqueries.
|
88
|
+
#
|
78
89
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
79
90
|
# @return [self]
|
80
91
|
|
81
92
|
# @!method and_not
|
82
93
|
# Logical negated conjunction (+ANDNOT+) of subqueries.
|
94
|
+
#
|
83
95
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
84
96
|
# @return [self]
|
85
97
|
|
86
98
|
# @!method or
|
87
99
|
# Logical disjunction (+OR+) of subqueries.
|
100
|
+
#
|
88
101
|
# @see https://arxiv.org/help/api/user-manual#query_details arXiv user manual
|
89
102
|
# @return [self]
|
90
103
|
|
@@ -94,6 +107,7 @@ module Arx
|
|
94
107
|
|
95
108
|
# @!method title(*values, exact: true, connective: :and)
|
96
109
|
# Search for papers by {https://arxiv.org/help/prep#title title}.
|
110
|
+
#
|
97
111
|
# @param values [Array<String>] Title(s) of papers to search for.
|
98
112
|
# @param exact [Boolean] Whether to search for an exact match of the title(s).
|
99
113
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -101,6 +115,7 @@ module Arx
|
|
101
115
|
|
102
116
|
# @!method author(*values, exact: true, connective: :and)
|
103
117
|
# Search for papers by {https://arxiv.org/help/prep#author author}.
|
118
|
+
#
|
104
119
|
# @param values [Array<String>] Author(s) of papers to search for.
|
105
120
|
# @param exact [Boolean] Whether to search for an exact match of the author's name(s).
|
106
121
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -108,6 +123,7 @@ module Arx
|
|
108
123
|
|
109
124
|
# @!method abstract(*values, exact: true, connective: :and)
|
110
125
|
# Search for papers by {https://arxiv.org/help/prep#abstract abstract}.
|
126
|
+
#
|
111
127
|
# @param values [Array<String>] Abstract(s) of papers to search for.
|
112
128
|
# @param exact [Boolean] Whether to search for an exact match of the abstract(s).
|
113
129
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -115,6 +131,7 @@ module Arx
|
|
115
131
|
|
116
132
|
# @!method comment(*values, exact: true, connective: :and)
|
117
133
|
# Search for papers by {https://arxiv.org/help/prep#comments comment}.
|
134
|
+
#
|
118
135
|
# @param values [Array<String>] Comment(s) of papers to search for.
|
119
136
|
# @param exact [Boolean] Whether to search for an exact match of the comment(s).
|
120
137
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -122,6 +139,7 @@ module Arx
|
|
122
139
|
|
123
140
|
# @!method journal(*values, exact: true, connective: :and)
|
124
141
|
# Search for papers by {https://arxiv.org/help/prep#journal journal reference}.
|
142
|
+
#
|
125
143
|
# @param values [Array<String>] Journal reference(s) of papers to search for.
|
126
144
|
# @param exact [Boolean] Whether to search for an exact match of the journal refernece(s).
|
127
145
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
@@ -129,25 +147,43 @@ module Arx
|
|
129
147
|
|
130
148
|
# @!method category(*values, connective: :and)
|
131
149
|
# Search for papers by {https://arxiv.org/help/prep#category category}.
|
150
|
+
#
|
132
151
|
# @param values [Array<String>] Category(s) of papers to search for.
|
133
152
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
134
153
|
# @return [self]
|
135
154
|
|
136
155
|
# @!method report(*values, connective: :and)
|
137
156
|
# Search for papers by {https://arxiv.org/help/prep#report report number}.
|
157
|
+
#
|
138
158
|
# @param values [Array<String>] Report number(s) of papers to search for.
|
139
159
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
140
160
|
# @return [self]
|
141
161
|
|
162
|
+
# @!method updated_at(*values, connective: :and)
|
163
|
+
# Search for papers by lastUpdatedDate.
|
164
|
+
#
|
165
|
+
# @param values [Array<String>] lastUpdatedDate (string or range) of papers to search for.
|
166
|
+
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
167
|
+
# @return [self]
|
168
|
+
|
169
|
+
# @!method submitted_at(*values, connective: :and)
|
170
|
+
# Search for papers by submittedDate.
|
171
|
+
#
|
172
|
+
# @param values [Array<String>] submittedDate (string or range) of papers to search for.
|
173
|
+
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
174
|
+
# @return [self]
|
175
|
+
|
142
176
|
# @!method all(*values, exact: true, connective: :and)
|
143
177
|
# Search for papers by all fields (see {FIELDS}).
|
178
|
+
#
|
144
179
|
# @param values [Array<String>] Field value(s) of papers to search for.
|
145
180
|
# @param exact [Boolean] Whether to search for an exact match of the comment(s).
|
146
181
|
# @param connective [Symbol] The logical connective to use (see {CONNECTIVES}). Only applies if there are multiple values.
|
147
182
|
# @return [self]
|
148
183
|
|
149
184
|
FIELDS.each do |name, field|
|
150
|
-
|
185
|
+
_exact = ![:updated_at, :submitted_at].include?(name)
|
186
|
+
define_method(name) do |*values, exact: _exact, connective: :and|
|
151
187
|
return if values.empty?
|
152
188
|
|
153
189
|
values.flatten!
|
@@ -173,6 +209,20 @@ module Arx
|
|
173
209
|
end
|
174
210
|
end
|
175
211
|
|
212
|
+
# Creates a nested subquery (grouped statements with parentheses).
|
213
|
+
#
|
214
|
+
# @return [self]
|
215
|
+
def group
|
216
|
+
add_connective :and unless end_with_connective?
|
217
|
+
@query << (search_query? ? '+' : "&#{PARAMS[:search_query]}=")
|
218
|
+
|
219
|
+
@query << CGI.escape('(')
|
220
|
+
yield
|
221
|
+
@query << CGI.escape(')')
|
222
|
+
|
223
|
+
self
|
224
|
+
end
|
225
|
+
|
176
226
|
# Returns the query string.
|
177
227
|
#
|
178
228
|
# @return [String]
|
@@ -189,7 +239,7 @@ module Arx
|
|
189
239
|
# @return [self]
|
190
240
|
def add_connective(connective)
|
191
241
|
if search_query?
|
192
|
-
@query << "+#{CONNECTIVES[connective]}" unless
|
242
|
+
@query << "+#{CONNECTIVES[connective]}" unless end_with_connective? || start_of_group?
|
193
243
|
end
|
194
244
|
self
|
195
245
|
end
|
@@ -198,9 +248,10 @@ module Arx
|
|
198
248
|
#
|
199
249
|
# @param subquery [String] The subquery to add.
|
200
250
|
def add_subquery(subquery)
|
251
|
+
add_connective :and unless end_with_connective?
|
252
|
+
|
201
253
|
if search_query?
|
202
|
-
|
203
|
-
@query << "+#{subquery}"
|
254
|
+
@query << (start_of_group? ? "#{subquery}" : "+#{subquery}")
|
204
255
|
else
|
205
256
|
@query << "&#{PARAMS[:search_query]}=#{subquery}"
|
206
257
|
end
|
@@ -218,10 +269,17 @@ module Arx
|
|
218
269
|
#
|
219
270
|
# @see CONNECTIVES
|
220
271
|
# @return [Boolean]
|
221
|
-
def
|
272
|
+
def end_with_connective?
|
222
273
|
CONNECTIVES.values.any? &@query.method(:end_with?)
|
223
274
|
end
|
224
275
|
|
276
|
+
# Whether the query string ends in a start-of-group character '('.
|
277
|
+
#
|
278
|
+
# @return [Boolean]
|
279
|
+
def start_of_group?
|
280
|
+
@query.end_with? CGI.escape('(')
|
281
|
+
end
|
282
|
+
|
225
283
|
# Parenthesizes a string with CGI-escaped parentheses.
|
226
284
|
#
|
227
285
|
# @param string [String] The string to parenthesize.
|
data/lib/arx/query/validate.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Arx
|
2
2
|
|
3
3
|
# Validations for arXiv search query fields and identifier schemes.
|
4
|
+
#
|
4
5
|
# @private
|
5
6
|
module Validate
|
6
7
|
class << self
|
@@ -28,6 +29,18 @@ module Arx
|
|
28
29
|
raise ArgumentError.new("Expected `sort_order` to be one of #{permitted}, got: #{value}") unless permitted.include? value
|
29
30
|
end
|
30
31
|
|
32
|
+
# Validates the paging fields of the query string: +start+ and +max_results+.
|
33
|
+
#
|
34
|
+
# @param start [Integer] The start value to validate.
|
35
|
+
# @param max_results [Integer] The max_results value to validate.
|
36
|
+
# @raise
|
37
|
+
# [TypeError] If the value of +start+ is not an +Integer+.
|
38
|
+
# [TypeError] If the value of +max_results+ is not an +Integer+.
|
39
|
+
def paging(start, max_results)
|
40
|
+
raise TypeError.new("Expected `start` to be an Integer, got: #{start.class}") unless start.is_a? Integer
|
41
|
+
raise TypeError.new("Expected `max_results` to be an Integer, got: #{max_results.class}") unless max_results.is_a? Integer
|
42
|
+
end
|
43
|
+
|
31
44
|
# Validates a list of arXiv paper identifiers.
|
32
45
|
#
|
33
46
|
# @param ids [Array<String>] The identifiers to validate.
|
data/lib/arx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Onuonga
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -42,44 +42,44 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: thor
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.20.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.20.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,9 +94,43 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.7'
|
97
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.8.23
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.8.23
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.9'
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.9.10
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - "~>"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0.9'
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.9.10
|
131
|
+
description:
|
98
132
|
email:
|
99
|
-
- ed@
|
133
|
+
- ed@eonu.net
|
100
134
|
executables: []
|
101
135
|
extensions: []
|
102
136
|
extra_rdoc_files: []
|
@@ -128,13 +162,13 @@ metadata:
|
|
128
162
|
documentation_uri: https://www.rubydoc.info/github/eonu/arx/master/toplevel
|
129
163
|
bug_tracker_uri: https://github.com/eonu/arx/issues
|
130
164
|
changelog_uri: https://github.com/eonu/arx/blob/master/CHANGELOG.md
|
131
|
-
post_install_message:
|
165
|
+
post_install_message:
|
132
166
|
rdoc_options: []
|
133
167
|
require_paths:
|
134
168
|
- lib
|
135
169
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
170
|
requirements:
|
137
|
-
- - "
|
171
|
+
- - ">="
|
138
172
|
- !ruby/object:Gem::Version
|
139
173
|
version: '2.5'
|
140
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -143,8 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
177
|
- !ruby/object:Gem::Version
|
144
178
|
version: '0'
|
145
179
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
180
|
+
rubygems_version: 3.1.2
|
181
|
+
signing_key:
|
148
182
|
specification_version: 4
|
149
183
|
summary: A Ruby interface for querying academic papers on the arXiv search API.
|
150
184
|
test_files: []
|