Skip to content

Commit

Permalink
Add Export spec, JSON fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
mdholloway committed Jan 4, 2025
1 parent 9cd61d3 commit 3bdb4e7
Show file tree
Hide file tree
Showing 10 changed files with 1,101 additions and 47 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# rspec failure tracking
.rspec_status

*.json
*.json.gz
*.gem
/*.json
/*.json.gz
/*.gem

Gemfile.lock
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Metrics/PerceivedComplexity:
Style/SafeNavigationChainLength:
Enabled: false
RSpec/ExampleLength:
Max: 10
Max: 12
RSpec/MultipleExpectations:
Enabled: false
12 changes: 3 additions & 9 deletions spec/digital_scriptorium/ds_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ module DigitalScriptorium
include WikibaseRepresentable::Representers

RSpec.describe DsItem do
let(:holding_json) do
'{"id":"Q102","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q2"},"type":"wikibase-entityid"}}}],"P1":[{"mainsnak":{"datavalue":{"value":"DS 1","type":"string"}}}]}}'
end
let(:manuscript_json) do
'{"id":"Q101","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q1"},"type":"wikibase-entityid"}}}],"P2":[{"mainsnak":{"datavalue":{"value":{"id":"Q102"},"type":"wikibase-entityid"}}}]}}'
end
let(:record_json) do
'{"id":"Q103","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q3"},"type":"wikibase-entityid"}}}],"P3":[{"mainsnak":{"datavalue":{"value":{"id":"Q101"},"type":"wikibase-entityid"}}}]}}'
end
let(:holding_json) { File.read(File.expand_path('../fixtures/holding.json', __dir__)) }
let(:manuscript_json) { File.read(File.expand_path('../fixtures/manuscript.json', __dir__)) }
let(:record_json) { File.read(File.expand_path('../fixtures/record.json', __dir__)) }

it 'correctly reports if it is a holding' do
item = ItemRepresenter.new(described_class.new).from_json(holding_json)
Expand Down
12 changes: 3 additions & 9 deletions spec/digital_scriptorium/ds_meta_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ module DigitalScriptorium
include WikibaseRepresentable::Representers

RSpec.describe DsMeta do
let(:holding_json) do
'{"id":"Q102","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q2"},"type":"wikibase-entityid"}}}],"P1":[{"mainsnak":{"datavalue":{"value":"DS 1","type":"string"}}}]}}'
end
let(:manuscript_json) do
'{"id":"Q101","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q1"},"type":"wikibase-entityid"}}}],"P2":[{"mainsnak":{"datavalue":{"value":{"id":"Q102"},"type":"wikibase-entityid"}}}]}}'
end
let(:record_json) do
'{"id":"Q103","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q3"},"type":"wikibase-entityid"}}}],"P3":[{"mainsnak":{"datavalue":{"value":{"id":"Q101"},"type":"wikibase-entityid"}}}]}}'
end
let(:holding_json) { File.read(File.expand_path('../fixtures/holding.json', __dir__)) }
let(:manuscript_json) { File.read(File.expand_path('../fixtures/manuscript.json', __dir__)) }
let(:record_json) { File.read(File.expand_path('../fixtures/record.json', __dir__)) }

it 'initializes from linked records in export' do
holding = ItemRepresenter.new(DsItem.new).from_json(holding_json)
Expand Down
30 changes: 5 additions & 25 deletions spec/digital_scriptorium/export_representer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,11 @@ module DigitalScriptorium
include WikibaseRepresentable::Representers

RSpec.describe ExportRepresenter do
let(:holding_json) do
'{"type":"item","id":"Q102","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q2"},"type":"wikibase-entityid"}}}],"P1":[{"mainsnak":{"datavalue":{"value":"DS 1","type":"string"}}}]}}'
end
let(:manuscript_json) do
'{"type":"item","id":"Q101","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q1"},"type":"wikibase-entityid"}}}],"P2":[{"mainsnak":{"datavalue":{"value":{"id":"Q102"},"type":"wikibase-entityid"}}}]}}'
end
let(:record_json) do
'{"type":"item","id":"Q103","claims":{"P16":[{"mainsnak":{"datavalue":{"value":{"id":"Q3"},"type":"wikibase-entityid"}}}],"P3":[{"mainsnak":{"datavalue":{"value":{"id":"Q101"},"type":"wikibase-entityid"}}}]}}'
end
let(:property_json) do
'{"type":"property","id":"P16","datatype":"wikibase-item","labels":{"en":{"language":"en","value":"instance of"}}}'
end
let(:export_json) do
"[#{holding_json},#{manuscript_json},#{record_json},#{property_json}]"
end
let(:holding_json) { File.read(File.expand_path('../fixtures/holding.json', __dir__)) }
let(:manuscript_json) { File.read(File.expand_path('../fixtures/manuscript.json', __dir__)) }
let(:record_json) { File.read(File.expand_path('../fixtures/record.json', __dir__)) }
let(:property_json) { File.read(File.expand_path('../fixtures/instance_of.json', __dir__)) }
let(:export_json) { "[#{holding_json},#{manuscript_json},#{record_json},#{property_json}]" }

it 'deserializes a Wikibase export from JSON' do
export = described_class.new(Export.new).from_json(export_json)
Expand All @@ -31,15 +21,5 @@ module DigitalScriptorium
expect(export[2]).to be_instance_of DsItem
expect(export[3]).to be_instance_of Property
end

it 'transforms a Wikibase export to a Hash' do
export = described_class.new(Export.new).from_json(export_json)
expect(export.to_hash).to eq({
'Q102' => ItemRepresenter.new(DsItem.new).from_json(holding_json),
'Q101' => ItemRepresenter.new(DsItem.new).from_json(manuscript_json),
'Q103' => ItemRepresenter.new(DsItem.new).from_json(record_json),
'P16' => PropertyRepresenter.new(Property.new).from_json(property_json)
})
end
end
end
31 changes: 31 additions & 0 deletions spec/digital_scriptorium/export_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'wikibase_representable'

module DigitalScriptorium
include WikibaseRepresentable::Model
include WikibaseRepresentable::Representers

RSpec.describe Export do
let(:holding_json) { File.read(File.expand_path('../fixtures/holding.json', __dir__)) }
let(:manuscript_json) { File.read(File.expand_path('../fixtures/manuscript.json', __dir__)) }
let(:record_json) { File.read(File.expand_path('../fixtures/record.json', __dir__)) }
let(:property_json) { File.read(File.expand_path('../fixtures/instance_of.json', __dir__)) }

it 'transforms a Wikibase export to a Hash' do
export = described_class.new
holding = ItemRepresenter.new(DsItem.new).from_json(holding_json)
manuscript = ItemRepresenter.new(DsItem.new).from_json(manuscript_json)
record = ItemRepresenter.new(DsItem.new).from_json(record_json)
property = PropertyRepresenter.new(Property.new).from_json(property_json)
export << holding << manuscript << record << property

expect(export.to_hash).to eq({
'Q542' => holding,
'Q543' => manuscript,
'Q544' => record,
'P16' => property
})
end
end
end
167 changes: 167 additions & 0 deletions spec/fixtures/holding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
{
"type": "item",
"id": "Q542",
"labels": {
"en": {
"language": "en",
"value": "Holding: University of Pennsylvania"
}
},
"descriptions": {
"en": {
"language": "en",
"value": "Holding of metadata collected by UPenn from University of Pennsylvania (9949945603503681, Oversize LJS 110)"
}
},
"aliases": [],
"claims": {
"P16": [
{
"mainsnak": {
"snaktype": "value",
"property": "P16",
"hash": "4dd159a209ed411a4f50592de9ee831893162774",
"datavalue": {
"value": {
"entity-type": "item",
"numeric-id": 2,
"id": "Q2"
},
"type": "wikibase-entityid"
}
},
"type": "statement",
"id": "Q542$6BB273DA-1E75-45FB-99DB-952A3AD3C61F",
"rank": "normal"
}
],
"P38": [
{
"mainsnak": {
"snaktype": "value",
"property": "P38",
"hash": "b6ce8b7be90c47d6e95667f5cb3b857a5c72cd6b",
"datavalue": {
"value": {
"time": "+2022-12-23T00:00:00Z",
"timezone": 0,
"before": 0,
"after": 0,
"precision": 11,
"calendarmodel": "http://www.wikidata.org/entity/Q1985727"
},
"type": "time"
}
},
"type": "statement",
"id": "Q542$EBB62690-BAA8-4223-8900-00DAF2DC7859",
"rank": "normal"
}
],
"P5": [
{
"mainsnak": {
"snaktype": "value",
"property": "P5",
"hash": "9374610faba500b29dedf759055e43198e98cded",
"datavalue": {
"value": "University of Pennsylvania",
"type": "string"
}
},
"type": "statement",
"qualifiers": {
"P4": [
{
"snaktype": "value",
"property": "P4",
"hash": "9a1bca9ae683999ce197133cd1e265a01825363c",
"datavalue": {
"value": {
"entity-type": "item",
"numeric-id": 374,
"id": "Q374"
},
"type": "wikibase-entityid"
}
}
]
},
"qualifiers-order": [
"P4"
],
"id": "Q542$B0FDFE38-AAA8-4F33-AFC6-D486673EB44E",
"rank": "normal"
}
],
"P6": [
{
"mainsnak": {
"snaktype": "value",
"property": "P6",
"hash": "7d915bfe178137b727c89aedc21b9470aa87b484",
"datavalue": {
"value": {
"entity-type": "item",
"numeric-id": 4,
"id": "Q4"
},
"type": "wikibase-entityid"
}
},
"type": "statement",
"id": "Q542$A2575F13-07E2-43CD-900C-0C5E9832CD64",
"rank": "normal"
}
],
"P7": [
{
"mainsnak": {
"snaktype": "value",
"property": "P7",
"hash": "66786f395ee93dd9adaa79494093596e700d8c60",
"datavalue": {
"value": "9949945603503681",
"type": "string"
}
},
"type": "statement",
"id": "Q542$AB8B602B-7A79-4CDD-9CFD-F0136EE635EC",
"rank": "normal"
}
],
"P8": [
{
"mainsnak": {
"snaktype": "value",
"property": "P8",
"hash": "9fd44b4cc9821c7bab3b7a68f9a3af3a132da32e",
"datavalue": {
"value": "Oversize LJS 110",
"type": "string"
}
},
"type": "statement",
"id": "Q542$C046FA26-2BC9-4B62-8A1B-8251861DEFEF",
"rank": "normal"
}
],
"P9": [
{
"mainsnak": {
"snaktype": "value",
"property": "P9",
"hash": "1f6b3c24699842b0f1cff5b5349144fcf0734f17",
"datavalue": {
"value": "https://franklin.library.upenn.edu/catalog/FRANKLIN_9949945603503681",
"type": "string"
}
},
"type": "statement",
"id": "Q542$9853212B-9FE4-4C16-8C76-C2BCEB703714",
"rank": "normal"
}
]
},
"sitelinks": []
}
50 changes: 50 additions & 0 deletions spec/fixtures/instance_of.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"type": "property",
"datatype": "wikibase-item",
"id": "P16",
"labels": {
"en": {
"language": "en",
"value": "instance of"
}
},
"descriptions": {
"en": {
"language": "en",
"value": "that class of which this subject is a particular example and member"
}
},
"aliases": [],
"claims": {
"P45": [
{
"mainsnak": {
"snaktype": "value",
"property": "P45",
"hash": "b97268ae16cea1cf5fde1a532bd4a6b633c836f1",
"datavalue": {
"value": "http://www.wikidata.org/entity/P31",
"type": "string"
}
},
"type": "statement",
"id": "P16$04eacd5d-42b5-63bb-4de3-1743285c91eb",
"rank": "normal"
},
{
"mainsnak": {
"snaktype": "value",
"property": "P45",
"hash": "79ed4ac5097dd275584b1b2c37c30f123290be20",
"datavalue": {
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
"type": "string"
}
},
"type": "statement",
"id": "P16$6b149b6f-4ae7-f63d-4fa6-0ca017f60613",
"rank": "normal"
}
]
}
}
Loading

0 comments on commit 3bdb4e7

Please sign in to comment.