dronefly-garden / dronefly

Red Discord Bot V3 cogs for naturalists.
Other
16 stars 3 forks source link

inat taxon: Show alternate names when matched #16

Closed synrg closed 5 years ago

synrg commented 5 years ago

When an alternate name is matched, show the name and where it came from in the response, e.g.

[p]inat taxon subspecies common teal

Currently this returns the subspecies "Anas crecca crecca (Eurasian Green-winged Teal)" and the API result for that entry has matched_term: "Eurasian Green-winged Teal", i.e. it doesn't contain the word "common".

Why it matches is evident when you go to the web page for it: https://www.inaturalist.org/taxa/132873

In the taxon names section there is a line for "English" "Common Teal".

Since there is no API call for this, the name that was matched can only be obtained by either scraping the page or else using the same unpublished web endpoint that it does:

https://www.inaturalist.org/taxon_names.json?per_page=200&taxon_id=132873

Since by this point the command has already narrowed it down to a single record, and we'd only need this if the "best match" is against a name that isn't retrieved from the /v1/taxa API call (i.e. corner cases), it is justifiable to attempt this call, and if it succeeds, use the first matching name as the "Matched:" value in the response.

synrg commented 5 years ago

I have asked on the iNat forums about this issue: https://forum.inaturalist.org/t/handling-matches-on-name-fields-not-returned-in-api-v1-taxa-response/6935

synrg commented 5 years ago

This is closed by pleary's fix in response to my forum post:

The matched term we were using was a match, but not necessarily the best match. In the example you linked to the matched term contained Teal, but there was a better match that contained both Common and Teal. I made a change that will hopefully address that if you’d like to try again.