Skip to content

Commit

Permalink
Merge 3a52feb into e6e48f2
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Dec 7, 2018
2 parents e6e48f2 + 3a52feb commit cc7a535
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/services/qa/linked_data/graph_service.rb
Expand Up @@ -19,8 +19,8 @@ def load_graph(url:)
# @param remove_blanknode_subjects [Boolean] will remove any statement whose subject is a blanknode, if true
# @returns [RDF::Graph] a new instance of graph with statements not matching the filters removed
def filter(graph:, language: nil, remove_blanknode_subjects: false)
return unless graph.present?
return unless language.present? || remove_blanknode_subjects
return graph unless graph.present?
return graph unless language.present? || remove_blanknode_subjects
filtered_graph = graph
language = normalize_language(language)
filtered_graph.each do |st|
Expand Down
2 changes: 1 addition & 1 deletion lib/qa/authorities/linked_data/search_query.rb
Expand Up @@ -37,7 +37,7 @@ def search(query, language: nil, replacements: {}, subauth: nil)

def load_graph(url:, language:)
@graph = Qa::LinkedData::GraphService.load_graph(url: url)
@graph = Qa::LinkedData::GraphService.filter(graph: @graph, language: language) unless language.blank?
@graph = Qa::LinkedData::GraphService.filter(graph: @graph, language: language, remove_blanknode_subjects: true)
end

def parse_search_authority_response
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/linked_data_terms_controller_spec.rb
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'json'

describe Qa::LinkedDataTermsController, type: :controller do
before do
Expand Down Expand Up @@ -166,6 +167,21 @@
expect(response).to be_successful
end
end

context '3 search results with blank nodes removed' do
before do
stub_request(:get, 'http://experimental.worldcat.org/fast/search?maximumRecords=5&query=cql.any%20all%20%22ezra%22&sortKeys=usage')
.to_return(status: 200, body: webmock_fixture('lod_search_with_blanknode_subjects.nt'), headers: { 'Content-Type' => 'application/n-triples' })
end
it 'succeeds' do
get :search, params: { q: 'ezra', vocab: 'OCLC_FAST', maximumRecords: '5' }
expect(response).to be_successful
results = JSON.parse(response.body)
blank_nodes = results.select { |r| r['uri'].start_with?('_:b') }
expect(blank_nodes.size).to eq 0
expect(results.size).to eq 3
end
end
end

context 'in OCLC_FAST authority and personal_name subauthority' do
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/lod_search_with_blanknode_subjects.nt
@@ -1,12 +1,18 @@
<http://id.worldcat.org/fast/530369> <http://purl.org/dc/terms/identifier> "530369" .
<http://id.worldcat.org/fast/530369> <http://schema.org/name> "Cornell University" .
<http://id.worldcat.org/fast/530369> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University" .
<http://id.worldcat.org/fast/530369> <http://schema.org/sameAs> _:b0 .
_:b0 <http://www.w3.org/2000/01/rdf-schema#label> "Cornell University" .
_:b0 <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell University" .
<http://id.worldcat.org/fast/5140> <http://purl.org/dc/terms/identifier> "5140" .
<http://id.worldcat.org/fast/5140> <http://schema.org/name> "Cornell, Joseph" .
<http://id.worldcat.org/fast/5140> <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell, Joseph" .
<http://id.worldcat.org/fast/5140> <http://schema.org/sameAs> _:b1 .
_:b1 <http://www.w3.org/2000/01/rdf-schema#label> "Cornell, Joseph" .
_:b1 <http://www.w3.org/2004/02/skos/core#prefLabel> "Cornell, Joseph" .
<http://id.worldcat.org/fast/557490> <http://purl.org/dc/terms/identifier> "557490" .
<http://id.worldcat.org/fast/557490> <http://schema.org/name> "New York State School of Industrial and Labor Relations" .
<http://id.worldcat.org/fast/557490> <http://www.w3.org/2004/02/skos/core#prefLabel> "New York State School of Industrial and Labor Relations" .
<http://id.worldcat.org/fast/557490> <http://schema.org/sameAs> _:b2 .
_:b2 <http://www.w3.org/2000/01/rdf-schema#label> "New York State School of Industrial and Labor Relations" .
_:b2 <http://www.w3.org/2004/02/skos/core#prefLabel> "New York State School of Industrial and Labor Relations" .
4 changes: 2 additions & 2 deletions spec/services/linked_data/graph_service_spec.rb
Expand Up @@ -188,8 +188,8 @@
end

it 'removes statements where the subject is a blanknode' do
expect(graph.size).to be 12
expect(subject.size).to be 9
expect(graph.size).to be 18
expect(subject.size).to be 12
end
end
end
Expand Down

0 comments on commit cc7a535

Please sign in to comment.