Skip to content

Commit

Permalink
Merge pull request #1917 from MushroomObserver/jdc-1884-name-external…
Browse files Browse the repository at this point in the history
…-links

Enhance Name external links
  • Loading branch information
JoeCohen committed Feb 19, 2024
2 parents 0e94b1f + 441227f commit 6644519
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 45 deletions.
78 changes: 71 additions & 7 deletions app/helpers/object_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,64 @@ def name_link(name, str = nil)

# ----- links to names and records at external websites ----------------------

def ascomycete_org_name_url(name)
# omit `group`l their search ORs all of the words
# The site is Euro-centric, omitting many N Amer spp.
# so ORing the words gives more results
"https://ascomycete.org/Search-Results?search=#{name.sensu_stricto}"
end

def gbif_name_search_url(name)
# omit `group`, else there are no hits
# omit quotes around the name in order to get synonyms and cf's
"https://www.gbif.org/species/search?q=#{name.sensu_stricto}"
end

def google_name_search_url(name)
if name.rank == "Group"
# require quoted name ss, optional group/clade/complex for best results
"https://www.google.com/search?q=%2B%22#{name.sensu_stricto}%22+" \
"%28group+OR+Clade+OR+Complex%29&"
else
"https://www.google.com/search?q=%2B%22#{name.sensu_stricto}%22"
end
end

def inat_name_search_url(name)
# omit `group`, else there are no hits
"https://www.inaturalist.org/search?q=#{name.sensu_stricto}"
end

# url for IF record
def index_fungorum_record_url(record_id)
"http://www.indexfungorum.org/Names/NamesRecord.asp?RecordID=#{record_id}"
end

# url for Index Fungorum search. This is a general search.
# IF lacks an entry point that includes the name to be searched.
def index_fungorum_basic_search_url
"http://www.indexfungorum.org/Names/Names.asp"
# Use web search because IF internal search uses js form rather than a url
def index_fungorum_name_web_search_url(name)
# Use DuckDuckGo because the equivalent Google search results stink,
# and Bing shows an annoying ChatBot thing
# See https://github.com/MushroomObserver/mushroom-observer/issues/1884#issuecomment-1950137454
# Quote the name s.s. to get a list of hits that includes the right one.
# NOTE: jdc 2024-02-18
# I want a backslash between "q=" and "site",
# but can't figure the rigth way to do this.
# I can construct a link_to this url
# https://duckduckgo.com/?q=\site%3Aindexfungorum.org+%22Tuber+liui%22
# If I copy it and paste it into a browser address bar
# DuckDuckGo goes straight to the first search result
# It works the same if I right click on the displayed link,
# select Copy Link Address, and paste it into the address bar.
# BUT if I click on the link displayed in MO, it doesn't work.
"https://duckduckgo.com/?q=site%3Aindexfungorum.org+" \
"%22#{name.sensu_stricto}%22"
end

def mushroomexpert_name_web_search_url(name)
# Use DuckDuckGo see https://github.com/MushroomObserver/mushroom-observer/issues/1884#issuecomment-1950137454
# quote name sensu stricto to get right # of results.
"https://duckduckgo.com/?q=site%3Amushroomexpert.com+" \
"%22#{name.sensu_stricto}%22&ia=web"
end

# url for MB record by number
Expand All @@ -79,7 +128,7 @@ def mycobank_record_url(record_id)
# url for MycoBank name search for text_name
def mycobank_name_search_url(name)
"#{mycobank_basic_search_url}/field/Taxon%20name/#{
name.text_name.gsub(" ", "%20")
name.sensu_stricto.gsub(" ", "%20")
}"
end

Expand All @@ -92,9 +141,18 @@ def mycobank_host
end

# url for name search on MyCoPortal
# use name s.s., else group names get no results, even though
# on the MyCoPortal website search page, I can include "group"
# and all the hits will include group if hits exist
def mycoportal_url(name)
"http://mycoportal.org/portal/taxa/index.php?taxauthid=1&taxon=" \
"#{name.text_name.tr(" ", "+")}"
"#{name.sensu_stricto}"
end

# Use name s.s. because including group gets 0 or few hits;
# i.e., only sequenquenes whose notes or other field include "group"
def ncbi_nucleotide_term_search_url(name)
"https://www.ncbi.nlm.nih.gov/nuccore/?term=#{name.sensu_stricto}"
end

# url of SF page with "official" synonyms by category
Expand All @@ -109,6 +167,12 @@ def species_fungorum_sf_synonymy(record_id)
"http://www.speciesfungorum.org/Names/SynSpecies.asp?RecordID=#{record_id}"
end

def wikipedia_term_search_url(name)
# Use name s.s. because including "group" gets hits that
# don't include name s.s.
"https://en.wikipedia.org/w/index.php?search=#{name.sensu_stricto}"
end

# ----------------------------------------------------------------------------

# Wrap user name in link to show_user.
Expand Down Expand Up @@ -154,7 +218,7 @@ def user_list(title, users = [])
links = users.map { |u| user_link(u, u.legal_name) }
# interpolating would require inefficient #sanitize
# or dangerous #html_safe
title + ": " + links.safe_join(", ")
title + ": " + links.safe_join(", ") # rubocop:disable Style/StringConcatenation
end

# Wrap object's name in link to the object, return nil if no object
Expand Down
56 changes: 45 additions & 11 deletions app/helpers/tabs/names_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ def fungorum_sf_synonymy_tab(name)
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def index_fungorum_basic_search_tab
[:index_fungorum_search.l, index_fungorum_basic_search_url,
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def mycobank_name_search_tab(name)
[:mycobank_search.l, mycobank_name_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
Expand Down Expand Up @@ -135,12 +130,6 @@ def name_edit_classification_tab(name)
{ class: tab_id(__method__.to_s), icon: :edit }]
end

# Show name, obs menu. Also on Obs show, name section
def mycoportal_name_tab(name)
["MyCoPortal", mycoportal_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def eol_name_tab(name)
["EOL", name.eol_url,
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
Expand All @@ -152,6 +141,51 @@ def google_images_for_name_tab(name)
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def ascomycete_org_name_tab(name)
["Ascomycete.org", ascomycete_org_name_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def gbif_name_tab(name)
["GBIF", gbif_name_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def google_name_tab(name)
[:google_name_search.l, google_name_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def inat_name_tab(name)
["iNaturalist", inat_name_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def index_fungorum_name_search_tab(name)
[:index_fungorum_web_search.l, index_fungorum_name_web_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def ncbi_nucleotide_term_tab(name)
["NCBI Nucleotide", ncbi_nucleotide_term_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def mushroomexpert_name_tab(name)
["MushroomExpert", mushroomexpert_name_web_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def mycoportal_name_tab(name)
["MyCoPortal", mycoportal_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def wikipedia_term_tab(name)
["Wikipedia", wikipedia_term_search_url(name),
{ class: tab_id(__method__.to_s), target: :_blank, rel: :noopener }]
end

def occurrence_map_for_name_tab(name)
[:show_name_distribution_map.t,
add_query_param(map_name_path(id: name.id)),
Expand Down
6 changes: 6 additions & 0 deletions app/models/name/format.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module Name::Format
GROUP_ADD_ON_MATCHER = / #{Name::Parse::GROUP_ABBR}/
# When we `include` a module, the way to add class methods is like this:
def self.included(base)
base.extend(ClassMethods)
Expand Down Expand Up @@ -80,6 +81,11 @@ def real_search_name
Name.display_to_real_search(self)
end

def sensu_stricto
# sub(/ #{Name::Parse::GROUP_ABBR}/, "")
text_name.sub(GROUP_ADD_ON_MATCHER, "")
end

# Is this the "unknown" name?
def unknown?
text_name == "Fungi"
Expand Down
4 changes: 2 additions & 2 deletions app/views/controllers/names/show/_nomenclature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ synonym_links = [approve, deprecate].reject(&:nil?).safe_join(" | ")
["#{:ICN_ID.l}:",
tag.em(:show_name_icn_id_missing.l)].safe_join(" ")
end,
tag.p(link_to(*index_fungorum_basic_search_tab)),
tag.p(link_to(*index_fungorum_name_search_tab(name))),
tag.p(link_to(*mycobank_name_search_tab(name)))
].safe_join
elsif name.searchable_in_registry?
[
tag.p(link_to(*index_fungorum_basic_search_tab)),
tag.p(link_to(*index_fungorum_name_search_tab(name))),
tag.p(link_to(*mycobank_basic_search_tab))
].safe_join
end
Expand Down
30 changes: 22 additions & 8 deletions app/views/controllers/names/show/_observations_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ heading_link = icon_link_with_query(*name_tracker_form_tab(@name, @user))

tag.div(class: "row") do

concat(tag.div(class: "col-sm-7 name-section") do
concat(tag.div(class: "col-sm-6 name-section") do
concat(tag.p(:show_observations_of.t))
concat(tag.div(class: "pl-3") do
concat(name_related_taxa_observation_links(@name, @obss))
Expand All @@ -20,15 +20,29 @@ heading_link = icon_link_with_query(*name_tracker_form_tab(@name, @user))
" (#{@has_subtaxa})"].safe_join
end) if @has_subtaxa
end)
concat(tag.div(class: "py-3") do
concat(tag.p(link_to(*occurrence_map_for_name_tab(@name))))
end)
end)

concat(tag.div(class: "col-sm-5 name-section") do
if @name.searchable_in_registry?
concat(tag.p(link_to(*mycoportal_name_tab(@name))))
end
concat(tag.p(link_to(*eol_name_tab(@name)))) if @name.eol_url
concat(tag.p(link_to(*google_images_for_name_tab(@name))))
concat(tag.p(link_to(*occurrence_map_for_name_tab(@name))))
concat(tag.div(class: "col-sm-6 name-section") do
concat(tag.p("#{:research_links.l}:"))
concat(tag.div(class: "pl-3") do
if @name.classification =~ /Phylum: _Ascomycota_/
concat(tag.p(link_to(*ascomycete_org_name_tab(@name))))
end
concat(tag.p(link_to(*eol_name_tab(@name)))) if @name.eol_url
concat(tag.p(link_to(*gbif_name_tab(@name))))
concat(tag.p(link_to(*google_images_for_name_tab(@name))))
concat(tag.p(link_to(*google_name_tab(@name))))
concat(tag.p(link_to(*inat_name_tab(@name))))
if @name.searchable_in_registry?
concat(tag.p(link_to(*mushroomexpert_name_tab(@name))))
concat(tag.p(link_to(*mycoportal_name_tab(@name))))
end
concat(tag.p(link_to(*ncbi_nucleotide_term_tab(@name))))
concat(tag.p(link_to(*wikipedia_term_tab(@name))))
end)
end)

end
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@
show_location: Show [LOCATION]
show_location_description: Show [DESCRIPTION]
about_this_taxon: About this taxon
research_links: Research Links
show_name: About [NAME]
show_name_description: Show [DESCRIPTION]
show_object: Show [TYPE]
Expand Down Expand Up @@ -2128,8 +2129,9 @@
show_name_general_description: "[:form_names_gen_desc]"
show_name_see_more: See More
show_name_icn_id_missing: missing
google_name_search: Google Search
index_fungorum: Index Fungorum
index_fungorum_search: Index Fungorum search
index_fungorum_web_search: Index Fungorum web search
mycobank: MycoBank
mycobank_search: MycoBank search
gsd_species_synonymy: GSD Species Synonymy
Expand Down
Loading

0 comments on commit 6644519

Please sign in to comment.