Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
Fixes problem where array value was producing multiple SPARQL insert …
Browse files Browse the repository at this point in the history
…statements.
  • Loading branch information
justinlittman committed Jan 18, 2019
1 parent eeba42f commit 2e56a15
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 43 deletions.
4 changes: 2 additions & 2 deletions lib/rialto/etl/writers/sparql_statement_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def serialize_hash(hash, graph_name = nil)
else
[subject, RDF::URI.new(field), this_value]
end
statements << handle_delete_fields(subject, field, graph_name, hash)
statements << graph_to_insert(graph, graph_name) if graph.any?
end
statements << handle_delete_fields(subject, field, graph_name, hash)
statements << graph_to_insert(graph, graph_name) if graph.any?
end

statements
Expand Down
99 changes: 58 additions & 41 deletions spec/writers/sparql_statement_writer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,54 +67,71 @@
end

describe '#serialize' do
let(:first_hash) do
{
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'].to_s,
'@graph' => Rialto::Etl::NamedGraphs::STANFORD_PEOPLE_GRAPH.to_s,
'@type' => [RDF::Vocab::FOAF.Person, Rialto::Etl::Vocabs::Stanford.Staff],
Rialto::Etl::Vocabs::VIVO.overview.to_s => 'Justin Littman is a software developer and librarian.',
RDF::Vocab::VCARD.hasEmail.to_s => '[email protected]',
'#advisee' => {
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'].to_s,
describe 'when serializing a hash' do
let(:first_hash) do
{
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'].to_s,
'@graph' => Rialto::Etl::NamedGraphs::STANFORD_PEOPLE_GRAPH.to_s,
'@type' => [RDF::Vocab::FOAF.Person],
RDF::Vocab::VCARD.hasName.to_s => Rialto::Etl::Vocabs::RIALTO_CONTEXT_NAMES['188882']
'@type' => [RDF::Vocab::FOAF.Person, Rialto::Etl::Vocabs::Stanford.Staff],
Rialto::Etl::Vocabs::VIVO.overview.to_s => 'Justin Littman is a software developer and librarian.',
RDF::Vocab::VCARD.hasEmail.to_s => '[email protected]',
'#advisee' => {
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'].to_s,
'@graph' => Rialto::Etl::NamedGraphs::STANFORD_PEOPLE_GRAPH.to_s,
'@type' => [RDF::Vocab::FOAF.Person],
RDF::Vocab::VCARD.hasName.to_s => Rialto::Etl::Vocabs::RIALTO_CONTEXT_NAMES['188882']
}
}
}
end
end

let(:second_hash) do
{
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'].to_s,
'@graph' => Rialto::Etl::NamedGraphs::STANFORD_PEOPLE_GRAPH.to_s,
'@type' => [RDF::Vocab::FOAF.Person, Rialto::Etl::Vocabs::Stanford.Staff],
"!#{RDF::Vocab::VCARD.hasEmail}" => true,
RDF::Vocab::VCARD.hasEmail.to_s => '[email protected]'
}
end
let(:second_hash) do
{
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'].to_s,
'@graph' => Rialto::Etl::NamedGraphs::STANFORD_PEOPLE_GRAPH.to_s,
'@type' => [RDF::Vocab::FOAF.Person, Rialto::Etl::Vocabs::Stanford.Staff],
"!#{RDF::Vocab::VCARD.hasEmail}" => true,
RDF::Vocab::VCARD.hasEmail.to_s => '[email protected]'
}
end

let(:first_statements) { writer.serialize_hash(first_hash) }
let(:first_statements) { writer.serialize_hash(first_hash) }

let(:second_statements) { writer.serialize_hash(second_hash) }

before do
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'], RDF.type, RDF::Vocab::FOAF.Person]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'], RDF.type, Rialto::Etl::Vocabs::Stanford.Staff]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'],
Rialto::Etl::Vocabs::VIVO.overview,
'Justin Littman is a software developer and librarian.']
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'],
RDF::Vocab::VCARD.hasEmail,
'[email protected]']
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'], RDF.type, RDF::Vocab::FOAF.Person]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'],
RDF::Vocab::VCARD.hasName,
Rialto::Etl::Vocabs::RIALTO_CONTEXT_NAMES['188882']]

execute_sparql!(first_statements)
execute_sparql!(second_statements)
end

let(:second_statements) { writer.serialize_hash(second_hash) }
it { is_expected.to have_same_triples(graph) }
end

before do
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'], RDF.type, RDF::Vocab::FOAF.Person]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'], RDF.type, Rialto::Etl::Vocabs::Stanford.Staff]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'],
Rialto::Etl::Vocabs::VIVO.overview,
'Justin Littman is a software developer and librarian.']
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'],
RDF::Vocab::VCARD.hasEmail,
'[email protected]']
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'], RDF.type, RDF::Vocab::FOAF.Person]
graph << [Rialto::Etl::Vocabs::RIALTO_PEOPLE['188882'],
RDF::Vocab::VCARD.hasName,
Rialto::Etl::Vocabs::RIALTO_CONTEXT_NAMES['188882']]
describe 'when serializing a hash with an array' do
let(:hash) do
{
'@id' => Rialto::Etl::Vocabs::RIALTO_PEOPLE['1234'].to_s,
RDF::Vocab::SKOS.altLabel.to_s => ['Justin Littman', 'Littman, Justin']
}
end

execute_sparql!(first_statements)
execute_sparql!(second_statements)
end
let(:statements) { writer.serialize_hash(hash).flatten }

it { is_expected.to have_same_triples(graph) }
it 'produces a single insert for the array' do
expect(statements.length).to be(1)
end
end
end
end

0 comments on commit 2e56a15

Please sign in to comment.