openurl 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +47 -0
- data/lib/openurl.rb +7 -0
- data/lib/openurl/context_object.rb +364 -284
- data/lib/openurl/context_object_entity.rb +131 -124
- data/lib/openurl/metadata_formats/book.rb +36 -0
- data/lib/openurl/metadata_formats/dissertation.rb +36 -0
- data/lib/openurl/metadata_formats/dublin_core.rb +114 -0
- data/lib/openurl/metadata_formats/journal.rb +36 -0
- data/lib/openurl/metadata_formats/marc.rb +70 -0
- data/lib/openurl/metadata_formats/patent.rb +152 -0
- data/lib/openurl/metadata_formats/scholarly_common.rb +198 -0
- data/lib/openurl/metadata_formats/scholarly_service_type.rb +41 -0
- data/lib/openurl/transport.rb +9 -4
- data/test/context_object_entity_test.rb +41 -0
- data/test/context_object_test.rb +509 -0
- data/test/data/dc_ctx.xml +27 -0
- data/test/data/marc_ctx.xml +101 -0
- data/test/data/metalib_sap2_post_params.yml +1 -0
- data/test/data/scholarly_au_ctx.xml +1 -0
- data/test/data/yu.xml +50 -0
- data/test/test.yml +25 -0
- metadata +70 -35
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# scholarly_service_type.rb
|
3
|
+
#
|
4
|
+
# Created on Nov 1, 2007, 10:35:28 AM
|
5
|
+
#
|
6
|
+
# To change this template, choose Tools | Templates
|
7
|
+
# and open the template in the editor.
|
8
|
+
|
9
|
+
module OpenURL
|
10
|
+
class ScholarlyServiceType < ContextObjectEntity
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
@format = 'sch_svc'
|
14
|
+
@metadata_keys = ['abstract','citation','fulltext','holdings','ill','any']
|
15
|
+
@xml_ns = "info:ofi/fmt:xml:xsd:sch_svc"
|
16
|
+
@kev_ns = "info:ofi/fmt:kev:mtx:sch_svc"
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(metadata, value=nil)
|
20
|
+
meta = metadata.to_s.sub(/=$/,'')
|
21
|
+
raise ArgumentError, "#{meta.to_s} is not a valid #{self.class} metadata field." unless @metadata_keys.index(meta)
|
22
|
+
if metadata.to_s.match(/=$/)
|
23
|
+
self.set_metadata(meta, value)
|
24
|
+
else
|
25
|
+
return self.metadata[meta]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class ScholarlyServiceTypeFactory < ContextObjectEntityFactory
|
33
|
+
@@identifiers = ["info:ofi/fmt:kev:mtx:sch_svc","info:ofi/fmt:xml:xsd:sch_svc"]
|
34
|
+
def self.identifiers
|
35
|
+
return @@identifiers
|
36
|
+
end
|
37
|
+
def self.create()
|
38
|
+
return OpenURL::ScholarlyServiceType.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/openurl/transport.rb
CHANGED
@@ -65,13 +65,18 @@ module OpenURL
|
|
65
65
|
# via GET, so pass the index of the desired context object (defaults to the
|
66
66
|
# first)
|
67
67
|
|
68
|
-
def get(idx=0)
|
68
|
+
def get(idx=0)
|
69
|
+
self.parse_response(@client.get( self.get_path(idx) ))
|
70
|
+
end
|
71
|
+
|
72
|
+
# useful for debugging to have this factored out
|
73
|
+
def get_path(idx=0)
|
69
74
|
extra = ""
|
70
75
|
@extra_args.each do | key, val |
|
71
76
|
extra << "&#{key}=#{val}"
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
77
|
+
end
|
78
|
+
return "#{@uri.path}?#{@context_objects[idx].kev}#{extra}"
|
79
|
+
end
|
75
80
|
|
76
81
|
# Sends an inline transport request. YOu can specify which HTTP method
|
77
82
|
# to use. Since you can only send one context object per inline request,
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
class ContextObjectEntityTest < Test::Unit::TestCase
|
3
|
+
|
4
|
+
def test_normalize_identifiers
|
5
|
+
|
6
|
+
# some ones that shouldn't be changed by normalization
|
7
|
+
["https://catalog.library.jhu.edu/bib/1",
|
8
|
+
"http://dx.doi.org/foo",
|
9
|
+
"info:isbn/foo",
|
10
|
+
"urn:isbn:0395363411"].each do |id|
|
11
|
+
assert_equal id, init_and_return_id(id)
|
12
|
+
end
|
13
|
+
|
14
|
+
# some ones that SHOULD be altered by normalization
|
15
|
+
# some info ones
|
16
|
+
|
17
|
+
|
18
|
+
assert_equal "info:doi/10.1126/science.275.5304.1320", init_and_return_id("doi:10.1126/science.275.5304.1320")
|
19
|
+
|
20
|
+
assert_equal "info:pmid/9036860", init_and_return_id("pmid:9036860")
|
21
|
+
|
22
|
+
assert_equal "info:sici/1046-8188(199501)13:1%3C69:FTTHBI%3E2.0.TX;2-4", init_and_return_id("sici:1046-8188(199501)13:1%3C69:FTTHBI%3E2.0.TX;2-4")
|
23
|
+
|
24
|
+
assert_equal "info:oclcnum/53393962", init_and_return_id("oclcnum:53393962")
|
25
|
+
|
26
|
+
assert_equal "info:lccn/12345", init_and_return_id("lccn:12345")
|
27
|
+
|
28
|
+
# some urn ones
|
29
|
+
|
30
|
+
assert_equal "urn:isbn:0395363411", init_and_return_id("isbn:0395363411")
|
31
|
+
|
32
|
+
assert_equal "urn:issn:1534-0481", init_and_return_id("issn:1534-0481")
|
33
|
+
end
|
34
|
+
|
35
|
+
def init_and_return_id(id)
|
36
|
+
entity = OpenURL::ContextObjectEntity.new
|
37
|
+
entity.add_identifier(id)
|
38
|
+
return entity.identifiers.first
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,509 @@
|
|
1
|
+
class ContextObjectTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_create_ctx
|
4
|
+
require 'cgi'
|
5
|
+
ctx = OpenURL::ContextObject.new
|
6
|
+
ctx.referent.set_format('journal')
|
7
|
+
assert_equal(ctx.referent.format, 'journal')
|
8
|
+
# Set some referent metadata
|
9
|
+
ctx.referent.set_metadata('jtitle', 'Ariadne')
|
10
|
+
assert_equal(ctx.referent.metadata['jtitle'], 'Ariadne')
|
11
|
+
# Overwrite the title
|
12
|
+
ctx.referent.set_metadata('jtitle', 'Nature')
|
13
|
+
assert_equal(ctx.referent.metadata['jtitle'], 'Nature')
|
14
|
+
# Set some identifiers
|
15
|
+
ctx.referent.add_identifier('doi:10.1038/nature06100')
|
16
|
+
assert_equal(ctx.referent.identifier, "info:doi/10.1038/nature06100")
|
17
|
+
assert_equal(ctx.referent.identifiers, ["info:doi/10.1038/nature06100"])
|
18
|
+
ctx.referent.add_identifier('info:pmid/17728715')
|
19
|
+
assert_equal(ctx.referent.identifiers, ["info:doi/10.1038/nature06100", 'info:pmid/17728715'])
|
20
|
+
assert_equal(ctx.referent.identifier, "info:doi/10.1038/nature06100")
|
21
|
+
ctx.referrer.add_identifier('info:sid/google')
|
22
|
+
assert_equal(ctx.referrer.identifier, "info:sid/google")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_load_kev
|
26
|
+
require 'yaml'
|
27
|
+
data = YAML.load_file('test/test.yml')
|
28
|
+
ctx = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev"])
|
29
|
+
self.test_kev_values(ctx)
|
30
|
+
ctx = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev_hybrid"])
|
31
|
+
self.test_kev_hybrid_values(ctx)
|
32
|
+
ctx = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev_0_1"])
|
33
|
+
self.test_kev_01_values(ctx)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_old_sid_translation
|
37
|
+
params = {"sid" => "elsevier", "isbn" => "dummy"}
|
38
|
+
ctx = OpenURL::ContextObject.new_from_form_vars(params)
|
39
|
+
|
40
|
+
assert_equal "info:sid/elsevier", ctx.referrer.identifiers.first, "translate 0.1 style sid into sort-of-legal 1.0 style rfr_id with info:sid URI"
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_load_xml
|
44
|
+
require 'yaml'
|
45
|
+
data = YAML.load_file('test/test.yml')
|
46
|
+
xml = File.new(data["context_objects"]["xml_doc"]).read
|
47
|
+
ctx = OpenURL::ContextObject.new_from_xml(xml)
|
48
|
+
self.test_xml_values(ctx)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_load_form_vals
|
52
|
+
require 'yaml'
|
53
|
+
require 'cgi'
|
54
|
+
data = YAML.load_file('test/test.yml')
|
55
|
+
cgi = CGI.parse(data["context_objects"]["kev"])
|
56
|
+
ctx = OpenURL::ContextObject.new_from_form_vars(cgi)
|
57
|
+
self.test_kev_values(ctx)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_load_metalib_form_params
|
61
|
+
require 'yaml'
|
62
|
+
require 'cgi'
|
63
|
+
data = YAML.load_file('test/test.yml')
|
64
|
+
params = data["context_objects"]["metalib_sap2_form_vars"]
|
65
|
+
|
66
|
+
ctx = OpenURL::ContextObject.new_from_form_vars(params)
|
67
|
+
rft_metadata = ctx.referent.metadata
|
68
|
+
|
69
|
+
assert_equal("Cooper Jr", rft_metadata["aulast"])
|
70
|
+
assert_equal("William E", rft_metadata["aufirst"])
|
71
|
+
assert_equal("Escape responses of cryptic frogs (Anura: Brachycephalidae: Craugastor) to simulated terrestrial and aerial predators.", rft_metadata["atitle"])
|
72
|
+
assert_equal("Behaviour", rft_metadata["stitle"])
|
73
|
+
assert_equal("2008", rft_metadata["date"])
|
74
|
+
assert_equal("145", rft_metadata["volume"])
|
75
|
+
|
76
|
+
# And test the even WORSELY damaged metalib form vars
|
77
|
+
params = data["context_objects"]["metalib_sap2_form_vars_worse"]
|
78
|
+
ctx = OpenURL::ContextObject.new_from_form_vars(params)
|
79
|
+
rft_metadata = ctx.referent.metadata
|
80
|
+
|
81
|
+
assert_equal("N Engl J Med", rft_metadata["title"])
|
82
|
+
assert_equal("2008", rft_metadata["date"])
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_load_cgi_style_metalib_form_params
|
86
|
+
require 'yaml'
|
87
|
+
require 'cgi'
|
88
|
+
|
89
|
+
data = YAML.load_file('test/test.yml')
|
90
|
+
params = data["context_objects"]["cgi_style_metalib_form_params"]
|
91
|
+
|
92
|
+
ctx = OpenURL::ContextObject.new_from_form_vars(params)
|
93
|
+
rft_metadata = ctx.referent.metadata
|
94
|
+
|
95
|
+
assert_equal("Abushahba", rft_metadata["aulast"])
|
96
|
+
assert_equal("Effect of grafting materials on osseointegration of dental implants surrounded by circumferential bone defects. An experimental study in the dog.", rft_metadata["atitle"])
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_oai_dc
|
100
|
+
require 'yaml'
|
101
|
+
data = YAML.load_file('test/test.yml')
|
102
|
+
xml = File.new(data["context_objects"]["oai_dc_ctx"]).read
|
103
|
+
ctx = OpenURL::ContextObject.new_from_xml(xml)
|
104
|
+
self.test_oai_dc_values(ctx)
|
105
|
+
ctx2 = OpenURL::ContextObject.new_from_xml(ctx.xml)
|
106
|
+
self.test_oai_dc_values(ctx2)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_marc
|
110
|
+
require 'yaml'
|
111
|
+
data = YAML.load_file('test/test.yml')
|
112
|
+
xml = File.new(data["context_objects"]["marc_21_ctx"]).read
|
113
|
+
ctx = OpenURL::ContextObject.new_from_xml(xml)
|
114
|
+
self.test_marc_values(ctx)
|
115
|
+
ctx2 = OpenURL::ContextObject.new_from_xml(ctx.xml)
|
116
|
+
self.test_marc_values(ctx2)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Had problems importing a record with an 'au' metadata author.
|
120
|
+
# Fixed it, so adding a test for it.
|
121
|
+
def test_au
|
122
|
+
require 'yaml'
|
123
|
+
data = YAML.load_file('test/test.yml')
|
124
|
+
xml = File.new(data['context_objects']['scholarly_au_ctx']).read
|
125
|
+
ctx = OpenURL::ContextObject.new_from_xml(xml)
|
126
|
+
|
127
|
+
assert_equal( ctx.referent.metadata["title"], "The adventures of Tom Sawyer")
|
128
|
+
assert_equal( ctx.referent.metadata["au"], "Twain, Mark")
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_xml_output
|
132
|
+
require 'yaml'
|
133
|
+
require 'rexml/document'
|
134
|
+
data = YAML.load_file('test/test.yml')
|
135
|
+
ctx = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev"])
|
136
|
+
doc = REXML::Document.new(ctx.xml)
|
137
|
+
root = doc.root
|
138
|
+
assert_equal(root.name, "context-objects")
|
139
|
+
assert_equal(root.prefix, "ctx")
|
140
|
+
assert_equal(root.namespace('ctx'), "info:ofi/fmt:xml:xsd:ctx")
|
141
|
+
assert_equal(root.namespace('xsi'), "http://www.w3.org/2001/XMLSchema-instance")
|
142
|
+
xml_schema = root.attribute('schemaLocation')
|
143
|
+
assert_equal(xml_schema.value, "info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx")
|
144
|
+
assert_equal(xml_schema.prefix, "xsi")
|
145
|
+
assert_equal(xml_schema.namespace, root.namespace(xml_schema.prefix))
|
146
|
+
ctx_obj = root.elements["ctx:context-object"]
|
147
|
+
assert(ctx_obj.is_a?(REXML::Element))
|
148
|
+
assert_equal(ctx_obj.attributes['timestamp'], '2003-04-11T10:08:30TZD')
|
149
|
+
assert_equal(ctx_obj.attributes['version'], 'Z39.88-2004')
|
150
|
+
assert_equal(ctx_obj.attributes['identifier'], '10_8')
|
151
|
+
rft = ctx_obj.elements["ctx:referent"]
|
152
|
+
assert(rft.is_a?(REXML::Element))
|
153
|
+
mbv = rft.elements['ctx:metadata-by-val']
|
154
|
+
assert(mbv.is_a?(REXML::Element))
|
155
|
+
fmt = mbv.elements['ctx:format']
|
156
|
+
assert(fmt.is_a?(REXML::Element))
|
157
|
+
assert_equal(fmt.get_text.value, "info:ofi/fmt:xml:xsd:book")
|
158
|
+
metadata = mbv.elements['ctx:metadata']
|
159
|
+
assert(metadata.is_a?(REXML::Element))
|
160
|
+
book = metadata.elements['rft:book']
|
161
|
+
assert(book.is_a?(REXML::Element))
|
162
|
+
assert_equal(book.namespace('rft'), "info:ofi/fmt:xml:xsd:book")
|
163
|
+
assert_equal(book.attribute('schemaLocation').value, "info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book")
|
164
|
+
authors_cont = book.elements['rft:authors']
|
165
|
+
assert(authors_cont.is_a?(REXML::Element))
|
166
|
+
author_cont = authors_cont.elements['rft:author']
|
167
|
+
assert(author_cont.is_a?(REXML::Element))
|
168
|
+
assert_equal(author_cont.elements['rft:aulast'].get_text.value, "Vergnaud")
|
169
|
+
assert_equal(author_cont.elements['rft:auinit'].get_text.value, "J.-R")
|
170
|
+
btitle = book.elements['rft:btitle']
|
171
|
+
assert(btitle.is_a?(REXML::Element))
|
172
|
+
assert_equal(btitle.get_text.value, "Dépendances et niveaux de représentation en syntaxe")
|
173
|
+
genre = book.elements['rft:genre']
|
174
|
+
assert(genre.is_a?(REXML::Element))
|
175
|
+
assert_equal(genre.get_text.value, "book")
|
176
|
+
date = book.elements['rft:date']
|
177
|
+
assert(date.is_a?(REXML::Element))
|
178
|
+
assert_equal(date.get_text.value, "1985")
|
179
|
+
pub = book.elements['rft:pub']
|
180
|
+
assert(pub.is_a?(REXML::Element))
|
181
|
+
assert_equal(pub.get_text.value, "Benjamins")
|
182
|
+
place = book.elements['rft:place']
|
183
|
+
assert(place.is_a?(REXML::Element))
|
184
|
+
assert_equal(place.get_text.value, "Amsterdam, Philadelphia")
|
185
|
+
|
186
|
+
rfe = ctx_obj.elements["ctx:referring-entity"]
|
187
|
+
assert(rfe.is_a?(REXML::Element))
|
188
|
+
mbv = rfe.elements['ctx:metadata-by-val']
|
189
|
+
assert(mbv.is_a?(REXML::Element))
|
190
|
+
fmt = mbv.elements['ctx:format']
|
191
|
+
assert(fmt.is_a?(REXML::Element))
|
192
|
+
assert_equal(fmt.get_text.value, "info:ofi/fmt:xml:xsd:book")
|
193
|
+
metadata = mbv.elements['ctx:metadata']
|
194
|
+
assert(metadata.is_a?(REXML::Element))
|
195
|
+
book = metadata.elements['rfe:book']
|
196
|
+
assert(book.is_a?(REXML::Element))
|
197
|
+
assert_equal(book.namespace('rfe'), "info:ofi/fmt:xml:xsd:book")
|
198
|
+
assert_equal(book.attribute('schemaLocation').value, "info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book")
|
199
|
+
authors_cont = book.elements['rfe:authors']
|
200
|
+
assert(authors_cont.is_a?(REXML::Element))
|
201
|
+
author_cont = authors_cont.elements['rfe:author']
|
202
|
+
assert(author_cont.is_a?(REXML::Element))
|
203
|
+
assert_equal(author_cont.elements['rfe:aulast'].get_text.value, "Chomsky")
|
204
|
+
assert_equal(author_cont.elements['rfe:auinit'].get_text.value, "N")
|
205
|
+
btitle = book.elements['rfe:btitle']
|
206
|
+
assert(btitle.is_a?(REXML::Element))
|
207
|
+
assert_equal(btitle.get_text.value, "Minimalist Program")
|
208
|
+
genre = book.elements['rfe:genre']
|
209
|
+
assert(genre.is_a?(REXML::Element))
|
210
|
+
assert_equal(genre.get_text.value, "book")
|
211
|
+
date = book.elements['rfe:date']
|
212
|
+
assert(date.is_a?(REXML::Element))
|
213
|
+
assert_equal(date.get_text.value, "1995")
|
214
|
+
pub = book.elements['rfe:pub']
|
215
|
+
assert(pub.is_a?(REXML::Element))
|
216
|
+
assert_equal(pub.get_text.value, "The MIT Press")
|
217
|
+
place = book.elements['rfe:place']
|
218
|
+
assert(place.is_a?(REXML::Element))
|
219
|
+
assert_equal(place.get_text.value, "Cambridge, Mass")
|
220
|
+
place = book.elements['rfe:place']
|
221
|
+
assert(place.is_a?(REXML::Element))
|
222
|
+
assert_equal(place.get_text.value, "Cambridge, Mass")
|
223
|
+
isbn = book.elements['rfe:isbn']
|
224
|
+
assert(isbn.is_a?(REXML::Element))
|
225
|
+
assert_equal(isbn.get_text.value, "0262531283")
|
226
|
+
id = rfe.elements['ctx:identifier']
|
227
|
+
assert(id.is_a?(REXML::Element))
|
228
|
+
assert_equal(id.get_text.value, "urn:isbn:0262531283")
|
229
|
+
|
230
|
+
rfr = ctx_obj.elements["ctx:referrer"]
|
231
|
+
assert(rfr.is_a?(REXML::Element))
|
232
|
+
id = rfr.elements['ctx:identifier']
|
233
|
+
assert(id.is_a?(REXML::Element))
|
234
|
+
assert_equal(id.get_text.value, "info:sid/ebookco.com:bookreader")
|
235
|
+
|
236
|
+
svc = ctx_obj.elements["ctx:service-type"]
|
237
|
+
assert(svc.is_a?(REXML::Element))
|
238
|
+
mbv = svc.elements['ctx:metadata-by-val']
|
239
|
+
assert(mbv.is_a?(REXML::Element))
|
240
|
+
fmt = mbv.elements['ctx:format']
|
241
|
+
assert(fmt.is_a?(REXML::Element))
|
242
|
+
assert_equal(fmt.get_text.value, "info:ofi/fmt:xml:xsd:sch_svc")
|
243
|
+
metadata = mbv.elements['ctx:metadata']
|
244
|
+
assert(metadata.is_a?(REXML::Element))
|
245
|
+
abstract = metadata.elements['svc:abstract']
|
246
|
+
assert(abstract.is_a?(REXML::Element))
|
247
|
+
assert_equal(abstract.namespace('svc'), "info:ofi/fmt:xml:xsd:sch_svc")
|
248
|
+
|
249
|
+
assert_equal(abstract.get_text.value, "yes")
|
250
|
+
#assert_match("svc_val_fmt=#{CGI.escape("info:ofi/fmt:kev:mtx:sch_svc")}", ctx.kev)
|
251
|
+
#assert_match("svc.abstract=yes", ctx.kev)
|
252
|
+
|
253
|
+
#xml = File.new(data["context_objects"]["xml_doc"]).read
|
254
|
+
#ctx = OpenURL::ContextObject.new_from_xml(xml)
|
255
|
+
#self.test_xml_values(ctx)
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
# deep_copy and import_context_object should NOT result in
|
260
|
+
# any shared objects between the two co's.
|
261
|
+
def test_no_shared_objects_on_copy
|
262
|
+
require 'yaml'
|
263
|
+
data = YAML.load_file('test/test.yml')
|
264
|
+
ctx_orig = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev"])
|
265
|
+
|
266
|
+
ctx_deep_copied = ctx_orig.deep_copy
|
267
|
+
|
268
|
+
test_not_shared_objects( ctx_orig, ctx_deep_copied )
|
269
|
+
|
270
|
+
ctx_with_imported_data =
|
271
|
+
OpenURL::ContextObject.new_from_context_object( ctx_orig )
|
272
|
+
|
273
|
+
test_not_shared_objects( ctx_orig, ctx_with_imported_data )
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
# Make sure ctx1 and ctx2 don't share the same data objects.
|
279
|
+
# If they did, a change to one would change the other.
|
280
|
+
def test_not_shared_objects(ctx1, ctx2)
|
281
|
+
assert_not_equal( ctx1.referent.object_id, ctx2.referent.object_id );
|
282
|
+
assert_not_equal( ctx1.referent.metadata.object_id, ctx2.referent.metadata.object_id )
|
283
|
+
|
284
|
+
original_ref_title = ctx1.referent.metadata['title']
|
285
|
+
new_title = "new test title"
|
286
|
+
# just ensure new uniqueness
|
287
|
+
new_title += original_ref_title if original_ref_title
|
288
|
+
|
289
|
+
ctx1.referent.set_metadata('title', new_title)
|
290
|
+
|
291
|
+
# That better not have changed ctx2
|
292
|
+
|
293
|
+
assert_not_equal( new_title, ctx2.referent.metadata['title'])
|
294
|
+
|
295
|
+
# Now fix first title back to what it was originally, to have no
|
296
|
+
# side-effects
|
297
|
+
ctx1.referent.set_metadata('title', original_ref_title )
|
298
|
+
end
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
def test_to_hash
|
303
|
+
require 'yaml'
|
304
|
+
kev = YAML.load_file('test/test.yml')["context_objects"]["kev"]
|
305
|
+
|
306
|
+
ctx = OpenURL::ContextObject.new_from_kev(kev)
|
307
|
+
rft_metadata = ctx.referent.metadata
|
308
|
+
rfe_metadata = ctx.referringEntity.metadata
|
309
|
+
hash = ctx.to_hash
|
310
|
+
|
311
|
+
["btitle", "genre", "aulast", "auinit", "date", "pub", "place"].each do | rft_key|
|
312
|
+
assert_equal( hash["rft." + rft_key], rft_metadata[rft_key])
|
313
|
+
end
|
314
|
+
|
315
|
+
["btitle", "genre", "aulast", "date", "pub", "place", "isbn"].each do |rfe_key|
|
316
|
+
assert_equal( hash ["rfe." + rfe_key], rfe_metadata[rfe_key])
|
317
|
+
end
|
318
|
+
|
319
|
+
assert_equal("yes", hash["svc.abstract"] )
|
320
|
+
|
321
|
+
# ids end up as arrays
|
322
|
+
assert ( hash["rfr_id"].include?('info:sid/ebookco.com:bookreader'))
|
323
|
+
assert( hash["rfe_id"].include?("urn:isbn:0262531283") )
|
324
|
+
|
325
|
+
# Don't understand what this is supposed to be, not sure if this is right.
|
326
|
+
assert_equal( "info:ofi/fmt:kev:mtx:book", hash["rft_val_fmt"])
|
327
|
+
assert_equal("info:ofi/fmt:kev:mtx:book", hash["rfe_val_fmt"])
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
assert_equal("info:ofi\/fmt:kev:mtx:ctx", hash["url_ctx_fmt"])
|
332
|
+
assert_equal("2003-04-11T10:08:30TZD", hash["ctx_tim"])
|
333
|
+
# Don't understand what this one means.
|
334
|
+
assert_equal("10_8", hash["ctx_id"])
|
335
|
+
assert_match("Z39.88-2004", hash["ctx_ver"])
|
336
|
+
assert_match("info:ofi/enc:UTF-8", hash["ctx_enc"])
|
337
|
+
end
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
def test_kev
|
342
|
+
require 'yaml'
|
343
|
+
data = YAML.load_file('test/test.yml')
|
344
|
+
ctx = OpenURL::ContextObject.new_from_kev(data["context_objects"]["kev"])
|
345
|
+
# Make sure the KEV output is displaying things properly
|
346
|
+
assert_match(/ctx_ver=Z39\.88\-2004/,ctx.kev)
|
347
|
+
assert_match("rft.btitle=#{CGI.escape("Dépendances et niveaux de représentation en syntaxe")}",ctx.kev)
|
348
|
+
assert_match("rfe.btitle=#{CGI.escape("Minimalist Program")}",ctx.kev)
|
349
|
+
assert_match("rft.genre=book",ctx.kev)
|
350
|
+
assert_match("rfe.genre=book",ctx.kev)
|
351
|
+
assert_match("rft.aulast=Vergnaud",ctx.kev)
|
352
|
+
assert_match("rfe.aulast=Chomsky",ctx.kev)
|
353
|
+
assert_match("rft.auinit=J.-R",ctx.kev)
|
354
|
+
assert_match("rfe.auinit=N",ctx.kev)
|
355
|
+
assert_match("rft.date=1985",ctx.kev)
|
356
|
+
assert_match("rfe.date=1995",ctx.kev)
|
357
|
+
assert_match("rft.pub=Benjamins",ctx.kev)
|
358
|
+
assert_match("rfe.pub=The+MIT+Press",ctx.kev)
|
359
|
+
assert_match("rft.place=Amsterdam%2C+Philadelphia",ctx.kev)
|
360
|
+
assert_match("rfe.place=Cambridge%2C+Mass",ctx.kev)
|
361
|
+
assert_match("rfe_id=#{CGI.escape('urn:isbn:0262531283')}", ctx.kev)
|
362
|
+
assert_match("rfe.isbn=0262531283", ctx.kev)
|
363
|
+
assert_match("rfr_id=#{CGI.escape('info:sid/ebookco.com:bookreader')}", ctx.kev)
|
364
|
+
assert_match("rft_val_fmt=#{CGI.escape("info:ofi/fmt:kev:mtx:book")}", ctx.kev)
|
365
|
+
assert_match("rfe_val_fmt=#{CGI.escape("info:ofi/fmt:kev:mtx:book")}", ctx.kev)
|
366
|
+
assert_match("svc_val_fmt=#{CGI.escape("info:ofi/fmt:kev:mtx:sch_svc")}", ctx.kev)
|
367
|
+
assert_match("svc.abstract=yes", ctx.kev)
|
368
|
+
assert_match("url_ctx_fmt=#{CGI.escape("info:ofi\/fmt:kev:mtx:ctx")}", ctx.kev)
|
369
|
+
assert_match("ctx_tim=#{CGI.escape("2003-04-11T10:08:30TZD")}",ctx.kev)
|
370
|
+
assert_match("ctx_id=10_8",ctx.kev)
|
371
|
+
assert_match("ctx_ver=Z39.88-2004",ctx.kev)
|
372
|
+
assert_match("ctx_enc=#{CGI.escape("info:ofi/enc:UTF-8")}", ctx.kev)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_kev_values(ctx)
|
376
|
+
assert_equal(ctx.referent.format, 'book')
|
377
|
+
assert_equal(ctx.referent.class, OpenURL::Book)
|
378
|
+
assert_equal(ctx.referent.metadata['btitle'], "Dépendances et niveaux de représentation en syntaxe")
|
379
|
+
assert_equal(ctx.referent.metadata['genre'], 'book')
|
380
|
+
assert_equal(ctx.referent.metadata['aulast'], 'Vergnaud')
|
381
|
+
assert_equal(ctx.referent.metadata['auinit'], 'J.-R')
|
382
|
+
assert_equal(ctx.referent.metadata['date'], '1985')
|
383
|
+
assert_equal(ctx.referent.metadata['pub'], 'Benjamins')
|
384
|
+
assert_equal(ctx.referent.metadata['place'], "Amsterdam, Philadelphia")
|
385
|
+
assert_equal(ctx.referringEntity.identifier, 'urn:isbn:0262531283')
|
386
|
+
assert_equal(ctx.referringEntity.identifiers[0], 'urn:isbn:0262531283')
|
387
|
+
assert_equal(ctx.referringEntity.format, 'book')
|
388
|
+
assert_equal(ctx.referringEntity.class, OpenURL::Book)
|
389
|
+
assert_equal(ctx.referringEntity.metadata['genre'], 'book')
|
390
|
+
assert_equal(ctx.referringEntity.metadata['aulast'], 'Chomsky')
|
391
|
+
assert_equal(ctx.referringEntity.metadata['auinit'], 'N')
|
392
|
+
assert_equal(ctx.referringEntity.metadata['btitle'], 'Minimalist Program')
|
393
|
+
assert_equal(ctx.referringEntity.metadata['isbn'], '0262531283')
|
394
|
+
assert_equal(ctx.referringEntity.metadata['date'], '1995')
|
395
|
+
assert_equal(ctx.referringEntity.metadata['pub'], 'The MIT Press')
|
396
|
+
assert_equal(ctx.referringEntity.metadata['place'], 'Cambridge, Mass')
|
397
|
+
assert_equal(ctx.serviceType[0].format, 'sch_svc')
|
398
|
+
assert_equal(ctx.serviceType[0].metadata['abstract'], 'yes')
|
399
|
+
assert_equal(ctx.referrer.identifier, 'info:sid/ebookco.com:bookreader')
|
400
|
+
assert_equal(ctx.referrer.identifiers[0], 'info:sid/ebookco.com:bookreader')
|
401
|
+
|
402
|
+
# Check administrative values
|
403
|
+
assert_equal(ctx.admin["ctx_tim"]["value"], "2003-04-11T10:08:30TZD")
|
404
|
+
assert_equal(ctx.admin["ctx_id"]["value"], "10_8")
|
405
|
+
assert_equal(ctx.admin["ctx_enc"]["value"], "info:ofi/enc:UTF-8")
|
406
|
+
assert_equal(ctx.admin["ctx_ver"]["value"], "Z39.88-2004")
|
407
|
+
end
|
408
|
+
|
409
|
+
def test_kev_hybrid_values(ctx)
|
410
|
+
assert(ctx.referrer.identifiers.index('info:sid/myid.com:mydb').is_a?(Fixnum))
|
411
|
+
assert(ctx.referent.identifiers.index('info:doi/10.1126/science.275.5304.1320').is_a?(Fixnum))
|
412
|
+
assert(ctx.referent.identifiers.index('info:pmid/9036860').is_a?(Fixnum))
|
413
|
+
assert_match(/info:doi\/10\.1126\/science\.275\.5304\.1320|info:pmid\/9036860/, ctx.referent.identifier)
|
414
|
+
assert_equal(ctx.referent.format, 'journal')
|
415
|
+
assert_equal(ctx.referent.metadata['atitle'], "Isolation of a common receptor for coxsackie B")
|
416
|
+
assert_equal(ctx.referent.metadata['jtitle'], "Science")
|
417
|
+
assert_equal(ctx.referent.metadata['genre'], 'article')
|
418
|
+
assert_equal(ctx.referent.metadata['aulast'], 'Bergelson')
|
419
|
+
assert_equal(ctx.referent.metadata['auinit'], 'J')
|
420
|
+
assert_equal(ctx.referent.metadata['date'], '1997')
|
421
|
+
assert_equal(ctx.referent.metadata['volume'], '275')
|
422
|
+
assert_equal(ctx.referent.metadata['spage'], '1320')
|
423
|
+
assert_equal(ctx.referent.metadata['epage'], '1323')
|
424
|
+
|
425
|
+
# Check administrative values
|
426
|
+
assert_equal(ctx.admin["ctx_enc"]["value"], "info:ofi/enc:UTF-8")
|
427
|
+
assert_equal(ctx.admin["ctx_ver"]["value"], "Z39.88-2004")
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_kev_01_values(ctx)
|
431
|
+
assert(ctx.referrer.identifiers.index('info:sid/myid:mydb').is_a?(Fixnum))
|
432
|
+
assert(ctx.referent.identifiers.index('info:doi/10.1126/science.275.5304.1320').is_a?(Fixnum))
|
433
|
+
assert(ctx.referent.identifiers.index('info:pmid/9036860').is_a?(Fixnum))
|
434
|
+
assert_match(/info:doi\/10\.1126\/science\.275\.5304\.1320|info:pmid\/9036860/, ctx.referent.identifier)
|
435
|
+
assert_equal(ctx.referent.format, 'journal')
|
436
|
+
assert_equal(ctx.referent.metadata['atitle'], "Isolation of a common receptor for coxsackie B")
|
437
|
+
assert_equal(ctx.referent.metadata['title'], "Science")
|
438
|
+
assert_equal(ctx.referent.metadata['genre'], 'article')
|
439
|
+
assert_equal(ctx.referent.metadata['aulast'], 'Bergelson')
|
440
|
+
assert_equal(ctx.referent.metadata['auinit'], 'J')
|
441
|
+
assert_equal(ctx.referent.metadata['date'], '1997')
|
442
|
+
assert_equal(ctx.referent.metadata['volume'], '275')
|
443
|
+
assert_equal(ctx.referent.metadata['spage'], '1320')
|
444
|
+
assert_equal(ctx.referent.metadata['epage'], '1323')
|
445
|
+
|
446
|
+
# Check administrative values
|
447
|
+
assert_equal(ctx.admin["ctx_enc"]["value"], "info:ofi/enc:UTF-8")
|
448
|
+
assert_equal(ctx.admin["ctx_ver"]["value"], "Z39.88-2004")
|
449
|
+
end
|
450
|
+
|
451
|
+
def test_xml_values(ctx)
|
452
|
+
assert(ctx.referent.is_a?(OpenURL::Journal))
|
453
|
+
assert(ctx.referrer.identifiers.index('info:sid/metalib.com:PUBMED').is_a?(Fixnum))
|
454
|
+
assert(ctx.referent.identifiers.index('info:doi/10.1364/OL.29.000017').is_a?(Fixnum))
|
455
|
+
assert(ctx.referent.identifiers.index('info:pmid/14719646').is_a?(Fixnum))
|
456
|
+
assert_match(/info:doi\/10\.1364\/OL\.29\.000017|info:pmid\/14719646/, ctx.referent.identifier)
|
457
|
+
assert(ctx.referringEntity.identifiers.index('info:doi/10.1063/1.1968421').is_a?(Fixnum))
|
458
|
+
assert_equal(ctx.referent.format, 'journal')
|
459
|
+
assert_equal(ctx.referent.metadata['atitle'], "Temperature dependence of Brillouin frequency, power, and bandwidth in panda, bow-tie, and tiger polarization-maintaining fibers.")
|
460
|
+
assert_equal(ctx.referent.metadata['stitle'], "Opt Lett")
|
461
|
+
assert_equal(ctx.referent.metadata['jtitle'], "Optics letters")
|
462
|
+
assert_equal(ctx.referent.metadata['issn'], "0146-9592")
|
463
|
+
assert_equal(ctx.referent.metadata['aulast'], 'Yu')
|
464
|
+
assert_equal(ctx.referent.metadata['aufirst'], 'Qinrong')
|
465
|
+
assert_equal(ctx.referent.metadata['date'], '2004-12-31')
|
466
|
+
assert_equal(ctx.referent.metadata['volume'], '29')
|
467
|
+
assert_equal(ctx.referent.metadata['issue'], '1')
|
468
|
+
assert_equal(ctx.referent.metadata['pages'], '17/18')
|
469
|
+
assert_equal(ctx.referent.metadata['spage'], '17')
|
470
|
+
assert_equal(ctx.referent.metadata['epage'], '9')
|
471
|
+
assert_equal(ctx.referent.authors.length, 3)
|
472
|
+
assert_equal(ctx.referent.authors[1].aulast, "Bao")
|
473
|
+
assert_equal(ctx.referent.authors[2].aulast, "Chen")
|
474
|
+
assert_equal(ctx.referent.reference["format"], "http://www.metalib.com/by_ref_info.xsd")
|
475
|
+
assert_equal(ctx.referent.reference["location"], "http://www.metalib.com/V?func=get_doc&doc_number=00261648")
|
476
|
+
# Check administrative values
|
477
|
+
assert_equal(ctx.admin["ctx_tim"]["value"], "2004-01-16T12:13:00Z")
|
478
|
+
assert_equal(ctx.admin["ctx_id"]["value"], "123")
|
479
|
+
assert_equal(ctx.admin["ctx_enc"]["value"], "info:ofi/enc:UTF-8")
|
480
|
+
assert_equal(ctx.admin["ctx_ver"]["value"], "Z39.88-2004")
|
481
|
+
end
|
482
|
+
|
483
|
+
def test_oai_dc_values(ctx)
|
484
|
+
assert(ctx.referent.is_a?(OpenURL::DublinCore))
|
485
|
+
assert_equal(ctx.referent.identifier, "info:doi/10.1086/508789")
|
486
|
+
assert_equal(ctx.referent.metadata["title"], ["Resurrection and Appropriation: Reputational Trajectories, Memory Work, and the Political Use of Historical Figures"])
|
487
|
+
assert_equal(ctx.referent.metadata["creator"], ["Robert S. Jansen"])
|
488
|
+
assert_equal(ctx.referent.publisher, ["The University of Chicago Press"])
|
489
|
+
assert_equal(ctx.referent.date, ["2007-02-27T13:27:58Z"])
|
490
|
+
assert_equal(ctx.referent.rights, ["© 2007 by The University of Chicago. All rights reserved."])
|
491
|
+
assert_equal(ctx.referent.description, ["<P>The Zapatistas and Sandinistas both invoked historical figures in their rhetoric, but they did so in very different ways. This variation is explained by a model of path-dependent memory work that is sensitive to how previous memory struggles enable and constrain subsequent uses of historical figures. Specifically, previous struggles produce distinct reputational trajectories that condition the potential utility of different modes of memory work. The cases illustrate two reputational trajectories, which are situated within a broader field of mnemonic possibilities. This article offers a provisional baseline for comparing contested memory projects and supplies a framework for analyzing the opportunities and constraints by which reputational trajectories condition memory work. It builds on a recent processual emphasis in the collective memory literature and suggests that the contentious politics literature needs to historicize its conception of culture and take seriously the operation of constraints on symbolic work.</P>", "10.1086/508789"])
|
492
|
+
assert_equal(ctx.referent.source, ["American Journal of Sociology, Volume 112 (2007), P. 953-1007"])
|
493
|
+
assert_equal(ctx.referent.metadata["identifier"], ["http://www.journals.uchicago.edu/cgi-bin/resolve?id=doi:10.1086/508789"])
|
494
|
+
assert_equal(ctx.referent.metadata["format"], ["application/html/pdf"])
|
495
|
+
assert_equal(ctx.referent.metadata["lang"], ["English"])
|
496
|
+
assert_equal(ctx.referent.metadata["type"], ["journal article"])
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_marc_values(ctx)
|
500
|
+
assert(ctx.referent.is_a?(OpenURL::Marc))
|
501
|
+
assert(ctx.referent.marc.is_a?(MARC::Record))
|
502
|
+
assert_equal(ctx.referent.marc.leader, "01142cam 2200301 a 4500")
|
503
|
+
assert_equal(ctx.referent.marc['001'].value.strip, "92005291")
|
504
|
+
end
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
end
|
509
|
+
|