diff --git a/app/services/qa/linked_data/graph_service.rb b/app/services/qa/linked_data/graph_service.rb index 141dfb40..88df993d 100644 --- a/app/services/qa/linked_data/graph_service.rb +++ b/app/services/qa/linked_data/graph_service.rb @@ -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| diff --git a/lib/qa/authorities/linked_data/search_query.rb b/lib/qa/authorities/linked_data/search_query.rb index 9da39255..52987e14 100644 --- a/lib/qa/authorities/linked_data/search_query.rb +++ b/lib/qa/authorities/linked_data/search_query.rb @@ -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 diff --git a/spec/controllers/linked_data_terms_controller_spec.rb b/spec/controllers/linked_data_terms_controller_spec.rb index 3614d5dd..d1d202dd 100644 --- a/spec/controllers/linked_data_terms_controller_spec.rb +++ b/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 @@ -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 diff --git a/spec/fixtures/lod_search_with_blanknode_subjects.nt b/spec/fixtures/lod_search_with_blanknode_subjects.nt index 8e958a10..124e3309 100644 --- a/spec/fixtures/lod_search_with_blanknode_subjects.nt +++ b/spec/fixtures/lod_search_with_blanknode_subjects.nt @@ -1,12 +1,18 @@ "530369" . "Cornell University" . + "Cornell University" . _:b0 . _:b0 "Cornell University" . +_:b0 "Cornell University" . "5140" . "Cornell, Joseph" . + "Cornell, Joseph" . _:b1 . _:b1 "Cornell, Joseph" . +_:b1 "Cornell, Joseph" . "557490" . "New York State School of Industrial and Labor Relations" . + "New York State School of Industrial and Labor Relations" . _:b2 . _:b2 "New York State School of Industrial and Labor Relations" . +_:b2 "New York State School of Industrial and Labor Relations" . diff --git a/spec/services/linked_data/graph_service_spec.rb b/spec/services/linked_data/graph_service_spec.rb index 081f8b7d..848f1a74 100644 --- a/spec/services/linked_data/graph_service_spec.rb +++ b/spec/services/linked_data/graph_service_spec.rb @@ -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