Class: Isi

Inherits:
Service show all
Includes:
MetadataHelper
Defined in:
app/service_adaptors/isi.rb

Overview

Uses ISI Web of Science to generates links to “cited by” and “similar” articles.

REQUIREMENTS: You must be an ISI customer if you want these links to actually work for your users. Off-campus users should be sent through EZProxy, see the EZProxy plug-in.

You need to register for the the Thomson ‘Links Article Match Retrieval’ (LAMR) service api, which is used here. To register, see: wokinfo.com/products_tools/products/related/amr/

You can register by IP address, so no auth key is needed once your registration goes through – or fill out ‘username’ and ‘password’ config elements in service setup, and they will be used.

If you later need to change the IP addresses entitled to use this API, use scientific.thomson.com/scientific/techsupport/cpe/form.html. to request a change.

File support/outage tickets at ip-science.thomsonreuters.com/support/

Note, as of 13 april 09, there’s a bug in ISI where journal titles including ampersands cause an error. We will catch those errors and output a ‘warning’ instead of an ‘error’, since it’s a known problem.

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

#group, #name, #priority, #request, #service_id, #status, #task, #url

Instance Method Summary collapse

Methods included from MetadataHelper

#get_doi, #get_epage, #get_gpo_item_nums, #get_identifier, #get_isbn, #get_issn, #get_lccn, #get_month, #get_oclcnum, #get_pmid, #get_search_creator, #get_search_terms, #get_search_title, #get_spage, #get_sudoc, #get_top_level_creator, #get_year, #normalize_lccn, #normalize_title, #raw_search_title, title_is_serial?

Methods included from MarcHelper

#add_856_links, #edition_statement, #get_title, #get_years, #gmd_values, #service_type_for_856, #should_skip_856_link?, #strip_gmd

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate

Constructor Details

#initialize(config) ⇒ Isi

Returns a new instance of Isi.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/service_adaptors/isi.rb', line 40

def initialize(config)
  #defaults
  @wos_app_name = "Umlaut"
  @display_name = "Web of Science\xc2\xae" # trademark symbol
  @api_url = "https://ws.isiknowledge.com/cps/xrpc"
  @include_cited_by = true
  @include_similar = true
  
  @credits = {
    @display_name => "http://apps.webofknowledge.com"
  }
  
  super(config)
end

Instance Method Details

#add_responses(request, response_xml) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'app/service_adaptors/isi.rb', line 224

def add_responses(request, response_xml)

  results = response_xml.at('map[@name ="cite_id"] map[@name="WOS"]')
  unless (results)
    error_message = "#{self.id}: "
    error_message << 'Unexpected ISI response. The ISI response was not reported as an error, but did not contain a <map name="WOS"> inside a <map name="cite_id"> as we expected it to:'
    error_message << "\n ISI XML request:\n#{gen_lamr_request(request)}\n"
    error_message << "\n ISI http response status: #{isi_response.code}\n"
    error_message << "\n ISI http response body:\n#{isi_response.body}\n"
    Rails.logger.error(error_message)
  end

  
  # cited by
  count = results.at('val[@name="timesCited"]')
  count = count ? count.inner_text.to_i : 0    
  
  cited_by_url = results.at('val[@name="citingArticlesURL"]')
  cited_by_url = cited_by_url.inner_text if cited_by_url

  if (@include_cited_by && count > 0 && cited_by_url )
    label = ServiceTypeValue[:cited_by].display_name_pluralize.downcase.capitalize    
    if count && count == 1
      label = ServiceTypeValue[:cited_by].display_name.downcase.capitalize
    end
    
    request.add_service_response(:service=>self, 
      :display_text => "#{count} #{label}", 
      :count=> count, 
      :url => cited_by_url,
      :debug_info => "url: " + cited_by_url,
      :service_type_value => :cited_by)
  end
  
  # similar
  
  similar_url = results.at('val[@name ="relatedRecordsURL"]')
  similar_url = similar_url.inner_text if similar_url

  if (@include_similar && similar_url )
      request.add_service_response( :service=>self, 
        :display_text => " #{ServiceTypeValue[:similar].display_name_pluralize.downcase.capitalize}", 
        :url => similar_url,
        :debug_info => "url: " + similar_url,
        :service_type_value => :similar)
  end
  
end

#do_lamr_request(xml) ⇒ Object



214
215
216
217
218
219
220
221
222
# File 'app/service_adaptors/isi.rb', line 214

def do_lamr_request(xml)
  uri = URI.parse(@api_url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if (uri.scheme == 'https')

  headers = {'Content-Type' => 'application/xml'}
  
  return http.post(uri.request_uri, xml, headers)
end

#gen_lamr_request(request) ⇒ Object

produces XML to be posted to Thomson ‘Links Article Match Retrieval’ service api.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'app/service_adaptors/isi.rb', line 121

def gen_lamr_request(request)
  output = ""
  
  builder = Builder::XmlMarkup.new(:target => output, :indent => 2)
  builder.instruct!(:xml, :encoding => "UTF-8")    

  builder.request(:xmlns => "http://www.isinet.com/xrpc41", :src => "app.id=Umlaut") do
    builder.fn(:name => "LinksAMR.retrieve") do
      builder.list do
        # first map is authentication info. empty 'map' element if we are IP authenticated.
        if @username && @password
          builder.map do
            builder.val(@username, :name => "username")
            builder.val(@password, :name => "password")
          end
        else
          builder.map
        end


        # specify what we're requesting
        builder.map do
          builder.list(:name=>"WOS") do
            builder.val("timesCited")
            builder.val("ut")
            builder.val("doi")
            builder.val("sourceURL")
            builder.val("citingArticlesURL")
            builder.val("relatedRecordsURL")
          end
        end
        # specify our query
        builder.map do
          builder.map(:name => "cite_id") do
            # Here's the tricky part, depends on what we've got.
             = request.referent.

            # DOI
            if ( doi = get_doi(request.referent))
              builder.val(doi, :name => "doi")
            end

            if ( pmid = get_pmid(request.referent))
              builder.val(pmid, :name => "pmid")
            end

            # Journal title is crucial for ISI -- ISSN alone is
            # not enough, weirdly!
            if ( ! ['jtitle'].blank? )
              builder.val(['jtitle'], :name => "stitle" )
            else
              builder.val(['title'], :name => 'stitle' )
            end
            
            # ISSN, not actually used much by ISI, but can't hurt. 
            if ( issn = request.referent.issn )
              # ISSN _needs_ a hyphen for WoS, bah!
              unless issn.match( /\-/ )
                issn = issn[0,4] + '-' + issn[4,7]
              end
              builder.val(issn, :name => "issn")
            end

            # article title often helpful. 
            unless ( ['atitle'].blank?)
              builder.val( ['atitle'], :name => "atitle")
            end
            # year
            unless ( ['date'].blank?)
              #first four digits are year
              builder.val( ["date"][0,4], :name => "year" )
            end

            # Vol/issue/page.  Oddly, issue isn't used very strongly
            # by ISI, but can't hurt. 
            unless ( ['volume'].blank? )
              builder.val(['volume'], :name => 'vol')
            end
            unless ( ['issue'].blank? )
              builder.val( ['issue'] , :name => 'issue')
            end
            unless ( ['spage'].blank? )
              builder.val(['spage'], :name => 'spage ')
            end
            
          end
        end          
      end
    end
  end
  return output
end

#handle(request) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/service_adaptors/isi.rb', line 55

def handle(request)
  
  unless ( sufficient_metadata?(request.referent))
     return request.dispatched(self, true)
  end
  
  xml = gen_lamr_request(request)
  
  isi_response = do_lamr_request(xml)
  
  
  begin
    #raise if it's an error HTTP response
    isi_response.value
  
    response_xml = Nokogiri::XML(isi_response.body)    
    # Check for errors.
    if (error = (response_xml.at('val[@name = "error"]') || response_xml.at("error") || response_xml.at('null[@name = "error"]')))
      raise IsiResponseException.new("ISI service reported error: #{error.inner_text}")      
    end

    add_responses( request, response_xml )
  rescue IsiResponseException => e
    # Is this the known problem with ampersands?
    # if so, output a warning, but report success not exception,
    # because this is a known condition.
     = request.referent.
    if ( (["title"] && ["title"].include?('&')) ||
         (["jtitle"] && ['jtitle'].include?('&')))
      Rails.logger.warn("ISI LAMR still exhibiting ampersand problems: #{e.message} ; OpenURL: ?#{request.to_context_object.kev}")
      return request.dispatched(self, true)
    else    
      # Log the error, return exception condition. 

      error_parts = []
      error_parts << "ISI URI: #{@api_url}"
      error_parts << "Request XML: #{xml}"
      error_parts << "ISI Response body: #{response_xml}"


      Rails.logger.error("#{e.message} ; " + error_parts.join("\n     ") )
      return request.dispatched(self, false, e)
    end
  end
  
  return request.dispatched(self, true)
end

#service_types_generatedObject



36
37
38
# File 'app/service_adaptors/isi.rb', line 36

def service_types_generated
  return [ServiceTypeValue[:cited_by]]
end

#sufficient_metadata?(referent) ⇒ Boolean

A DOI is always sufficient. Otherwise, it gets complicated because the ISI service is kind of picky in weird ways. ISSN alone is not enough, we need jtitle. Once you have jtitle, Vol/issue/start page are often enough, but article title really helps, and jtitle+atitle+year is often enough too.

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/service_adaptors/isi.rb', line 107

def sufficient_metadata?(referent)
   = referent.
  return get_doi(referent) || get_pmid(referent) ||
      (  ( ['jtitle'] || 
           ['title'] )   &&           
         (! (['atitle'].blank? ||
            ['date'].blank?
            ) ||
          ! ( ['volume'].blank? || ['issue'].blank? ||
              ['spage'].blank?))
      )    
end