Skip to content

Commit

Permalink
WIP - to be unpacked/revised later
Browse files Browse the repository at this point in the history
  • Loading branch information
dazza-codes committed Oct 3, 2017
1 parent 2a91993 commit d8876a1
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 90 deletions.
4 changes: 2 additions & 2 deletions lib/wos_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def auth
wsdl: AUTH_WSDL,
headers: { 'Authorization' => "Basic #{@auth_code}", 'SOAPAction' => [''] },
env_namespace: :soapenv,
log: true,
log: false,
log_level: @log_level,
pretty_print_xml: true
)
Expand All @@ -39,7 +39,7 @@ def search
wsdl: SEARCH_WSDL,
headers: { 'Cookie' => "SID=\"#{session_id}\"", 'SOAPAction' => '' },
env_namespace: :soapenv,
log: true,
log: false,
log_level: @log_level,
pretty_print_xml: true
)
Expand Down
3 changes: 2 additions & 1 deletion lib/wos_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ def retrieve_additional_records(response, response_type, retrieve_operation = :r
iterations = record_total / MAX_RECORDS
iterations -= 1 if (record_total % MAX_RECORDS).zero?
[*1..iterations].each do |i|
first_record = (MAX_RECORDS * i) + 1
message = {
queryId: query_id,
retrieveParameters: retrieve_parameters(first_record: MAX_RECORDS * i)
retrieveParameters: retrieve_parameters(first_record: first_record)
}
response_i = wos_client.search.call(retrieve_operation, message: message)
records_i = records(response_i, "#{retrieve_operation}_response".to_sym)
Expand Down
25 changes: 14 additions & 11 deletions lib/wos_records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@

# Utilities for working with Web of Science records
class WosRecords
include Enumerable
extend Forwardable
include Enumerable

# @return [Integer] WOS record count
def_delegators :rec_nodes, :count

# @return xml [String] WOS records in XML
def_delegators :doc, :to_xml

# @return doc [Nokogiri::XML::Document] WOS records document
attr_reader :doc

# @param records [String] records in XML
# @param encoded_records [String] records in HTML encoding
def initialize(records: nil, encoded_records: nil)
@records = records
@encoded_records = encoded_records
@records = decode_records if records.nil? && !encoded_records.nil?
end

# # @return [Integer]
# alias count rec_nodes.count

# @return doc [Nokogiri::XML::Document] WOS records document
def doc
@doc ||= Nokogiri::XML(records) { |config| config.strict.noblanks }
@doc = Nokogiri::XML(@records) { |config| config.strict.noblanks }
end

def each
Expand Down Expand Up @@ -56,10 +53,16 @@ def duplicate_records(record_setB)
# @param record_setB [WosRecords]
# @return records [WosRecords] merged set of records
def merge_records(record_setB)
rec_nodesB = record_setB.rec_nodes - duplicate_records(record_setB)
# create a new set of merged records, use a philosophy of immutability

# binding.pry
# TODO: why is this changing the record_setB????

dup_uids = duplicate_uids(record_setB)
merge_nodes = record_setB.rec_nodes.dup
merge_nodes.reject { |rec| dup_uids.include? record_uid(rec) } unless dup_uids.empty?
merge_doc = doc.dup
merge_doc.at('records').add_child(rec_nodesB)
merge_doc.at('records').add_child(merge_nodes)
WosRecords.new(records: merge_doc.to_xml)
end

Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/wos_client/wos_merge_records.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<records xmlns="http://scientific.thomsonreuters.com/schema/wok5.4/public/FullRecord">
<REC r_id_disclaimer="ResearcherID data provided by Clarivate Analytics"><UID>WOS:A1972N549400003</UID><static_data><summary><EWUID><WUID coll_id="WOS"></WUID><edition value="WOS.SSCI"></edition><edition value="WOS.SCI"></edition></EWUID><pub_info issue="5" pubtype="Journal" sortdate="1972-01-01" has_abstract="N" coverdate="1972" vol="33" pubyear="1972"><page end="413" page_count="1" begin="413">413-413</page></pub_info><titles count="6"><title type="source">COLLEGE & RESEARCH LIBRARIES</title><title type="source_abbrev">COLL RES LIBR</title><title type="abbrev_iso">Coll. Res. Libr.</title><title type="abbrev_11">COLL RES LI</title><title type="abbrev_29">COLL RES LIBR</title><title type="item">LIBRARY MANAGEMENT - BEHAVIOR-BASED PERSONNEL SYSTEMS (BBPS) - FRAMEWORK FOR ANALYSIS - KEMPER,RE</title></titles><names count="1"><name daisng_id="19669717" seq_no="1" role="author"><display_name>WEBER, DC</display_name><full_name>WEBER, DC</full_name><wos_standard>WEBER, DC</wos_standard><first_name>DC</first_name><last_name>WEBER</last_name></name></names><doctypes count="1"><doctype>Book Review</doctype></doctypes><publishers><publisher><address_spec addr_no="1"><full_address>50 E HURON ST, CHICAGO, IL 60611</full_address><city>CHICAGO</city></address_spec><names count="1"><name addr_no="1" role="publisher" seq_no="1"><display_name>ASSOC COLL RESEARCH LIBRARIES</display_name><full_name>ASSOC COLL RESEARCH LIBRARIES</full_name></name></names></publisher></publishers></summary><fullrecord_metadata><languages count="1"><language type="primary">English</language></languages><normalized_languages count="1"><language type="primary">English</language></normalized_languages><normalized_doctypes count="1"><doctype>Review</doctype></normalized_doctypes><refs count="1"></refs><addresses count="1"><address_name><address_spec addr_no="1"><full_address>STANFORD UNIV,STANFORD,CA 94305</full_address><organizations count="2"><organization>STANFORD UNIV</organization><organization pref="Y">Stanford University</organization></organizations><city>STANFORD</city><state>CA</state><country>USA</country><zip location="AP">94305</zip></address_spec></address_name></addresses><category_info><headings count="1"><heading>Science & Technology</heading></headings><subheadings count="1"><subheading>Technology</subheading></subheadings><subjects count="3"><subject ascatype="traditional" code="NU">Information Science & Library Science</subject><subject ascatype="extended">Information Science & Library Science</subject><subject ascatype="traditional" code="NU">INFORMATION SCIENCE & LIBRARY SCIENCE</subject></subjects></category_info></fullrecord_metadata><item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="itemType_wos"><ids avail="Y">N5494</ids><bib_id>33 (5): 413-413 1972</bib_id></item></static_data><dynamic_data><citation_related><tc_list><silo_tc coll_id="WOS" local_count="0"></silo_tc></tc_list></citation_related><cluster_related><identifiers><identifier value="0010-0870" type="issn"></identifier></identifiers></cluster_related></dynamic_data></REC>
<REC r_id_disclaimer="ResearcherID data provided by Clarivate Analytics"><UID>WOS:A1976BW18000001</UID><static_data><summary><EWUID><WUID coll_id="WOS"></WUID><edition value="WOS.SSCI"></edition><edition value="WOS.SCI"></edition></EWUID><pub_info coverdate="1976" has_abstract="N" issue="3" pubtype="Journal" pubyear="1976" sortdate="1976-01-01" vol="37"><page begin="205" end="221" page_count="17">205-221</page></pub_info><titles count="6"><title type="source">COLLEGE & RESEARCH LIBRARIES</title><title type="source_abbrev">COLL RES LIBR</title><title type="abbrev_iso">Coll. Res. Libr.</title><title type="abbrev_11">COLL RES LI</title><title type="abbrev_29">COLL RES LIBR</title><title type="item">CENTURY OF COOPERATIVE PROGRAMS AMONG ACADEMIC-LIBRARIES</title></titles><names count="1"><name daisng_id="19670132" seq_no="1" role="author"><display_name>WEBER, DC</display_name><full_name>WEBER, DC</full_name><wos_standard>WEBER, DC</wos_standard><first_name>DC</first_name><last_name>WEBER</last_name></name></names><doctypes count="1"><doctype>Article</doctype></doctypes><publishers><publisher><address_spec addr_no="1"><full_address>50 E HURON ST, CHICAGO, IL 60611</full_address><city>CHICAGO</city></address_spec><names count="1"><name addr_no="1" role="publisher" seq_no="1"><display_name>ASSOC COLL RESEARCH LIBRARIES</display_name><full_name>ASSOC COLL RESEARCH LIBRARIES</full_name></name></names></publisher></publishers></summary><fullrecord_metadata><languages count="1"><language type="primary">English</language></languages><normalized_languages count="1"><language type="primary">English</language></normalized_languages><normalized_doctypes count="1"><doctype>Article</doctype></normalized_doctypes><refs count="41"></refs><addresses count="1"><address_name><address_spec addr_no="1"><full_address>STANFORD UNIV LIB,STANFORD,CA 94305</full_address><organizations count="2"><organization>STANFORD UNIV LIB</organization><organization pref="Y">Stanford University</organization></organizations><city>STANFORD</city><state>CA</state><country>USA</country><zip location="AP">94305</zip></address_spec></address_name></addresses><category_info><headings count="1"><heading>Science & Technology</heading></headings><subheadings count="1"><subheading>Technology</subheading></subheadings><subjects count="3"><subject ascatype="traditional" code="NU">Information Science & Library Science</subject><subject ascatype="extended">Information Science & Library Science</subject><subject ascatype="traditional" code="NU">INFORMATION SCIENCE & LIBRARY SCIENCE</subject></subjects></category_info></fullrecord_metadata><item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" coll_id="WOS" xsi:type="itemType_wos"><ids avail="Y">BW180</ids><bib_id>37 (3): 205-221 1976</bib_id></item></static_data><dynamic_data><citation_related><tc_list><silo_tc coll_id="WOS" local_count="12"></silo_tc></tc_list></citation_related><cluster_related><identifiers><identifier type="issn" value="0010-0870"></identifier></identifiers></cluster_related></dynamic_data></REC>
</records>
Loading

0 comments on commit d8876a1

Please sign in to comment.