Class: GoogleScholarLink
- Defined in:
- app/service_adaptors/google_scholar_link.rb
Overview
Generates a LINK to search google scholar for the requested article. G.Scholar has no API, all we can do is link out.
Will only generate link for citations that appear article-level and have author and title.
You probably want to only execute if there is no found fulltext, by configuring in umlaut_services.yml with:
preempted_by:
existing_type: fulltext
It will only be preempted by fulltext created in earlier waves of service execution, service order ‘priority’ matters.
optional config: service_type, defaults to ‘highlighted_link’, but maybe
you want it actually under 'fulltext' or something.
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
- #construct_query(request) ⇒ Object
- #handle(request) ⇒ Object
-
#initialize(config) ⇒ GoogleScholarLink
constructor
A new instance of GoogleScholarLink.
- #service_types_generated ⇒ Object
- #should_link_out_to?(request) ⇒ Boolean
Methods inherited from Service
#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_url, #translate
Constructor Details
#initialize(config) ⇒ GoogleScholarLink
Returns a new instance of GoogleScholarLink.
21 22 23 24 25 26 |
# File 'app/service_adaptors/google_scholar_link.rb', line 21 def initialize(config) @service_type = "highlighted_link" @display_name = "Google Scholar" super(config) end |
Instance Method Details
#construct_query(request) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/service_adaptors/google_scholar_link.rb', line 52 def construct_query(request) = request.referent. title_query = "allintitle: \"#{["atitle"]}\"" = (["aulast"] || ["au"]).strip.split(/\s+|[[:punct:]]+/). reject {|term| term.length <= 3}. collect { |term| "author:#{term}" }.join(" ") "#{title_query} #{}" end |
#handle(request) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/service_adaptors/google_scholar_link.rb', line 33 def handle(request) return request.dispatched(self, true) unless should_link_out_to?(request) link = "http://scholar.google.com/scholar?q=#{CGI.escape construct_query(request)}" request.add_service_response( :service => self, :display_text => "Look for article on Google Scholar", :display_text_i18n => "display_text", :url => link, :service_type_value => @service_type, :notes => "This article <b>may</b> be available on the public web, look for links labelled <span class='gscholar_example'>[html]</span> or <span class='gscholar_example'>[pdf]</span>".html_safe, :notes_i18n => "notes_html" ) return request.dispatched(self, true) end |
#service_types_generated ⇒ Object
28 29 30 |
# File 'app/service_adaptors/google_scholar_link.rb', line 28 def service_types_generated [ServiceTypeValue[@service_type]] end |
#should_link_out_to?(request) ⇒ Boolean
64 65 66 67 68 69 70 71 |
# File 'app/service_adaptors/google_scholar_link.rb', line 64 def should_link_out_to?(request) return false unless (! request.title_level_citation?) = request.referent. ["atitle"] && (["au"] || ["aulast"]) end |