From 1fb1cd2555add8f1a5dfdf72f1a8ce8a0c3c7e0c Mon Sep 17 00:00:00 2001 From: Owen Date: Mon, 16 Dec 2024 11:00:45 +0100 Subject: [PATCH] response parser with tests --- config/config.exs | 1 - config/runtime.exs | 1 + lib/plantid_discord_bot/plantnet/parser.ex | 69 ++++ test/plantid_discord_bot_test.exs | 4 +- test/plantnet/parser_test.exs | 29 ++ test/test_helper.exs | 427 ++++++++++++++------- 6 files changed, 388 insertions(+), 143 deletions(-) create mode 100644 lib/plantid_discord_bot/plantnet/parser.ex create mode 100644 test/plantnet/parser_test.exs diff --git a/config/config.exs b/config/config.exs index e6974c4..ac806c5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,7 +1,6 @@ import Config config :plantid_discord_bot, - start_time: DateTime.utc_now(), image_folder: "priv/static" import_config "#{config_env()}.exs" diff --git a/config/runtime.exs b/config/runtime.exs index aebc49a..f935fb3 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,6 +1,7 @@ import Config config :plantid_discord_bot, + start_time: DateTime.utc_now(), guild_ids: [1_002_507_312_159_797_318], plantnet_api_key: System.get_env("PLANTNET_API_KEY"), plantnet_api_base_url: "https://my-api.plantnet.org/v2", diff --git a/lib/plantid_discord_bot/plantnet/parser.ex b/lib/plantid_discord_bot/plantnet/parser.ex new file mode 100644 index 0000000..b1ae9b0 --- /dev/null +++ b/lib/plantid_discord_bot/plantnet/parser.ex @@ -0,0 +1,69 @@ +defmodule PlantIdDiscordBot.PlantNet.Parser do + @moduledoc """ + Parses the response from the PlantNet API. + """ + + @gbif_base_url "https://www.gbif.org/species" + @pfaf_base_url "https://pfaf.org/user/Plant.aspx?LatinName=" + @powo_base_url "https://powo.science.kew.org/taxon" + @score_threshold 0.3 + + @doc """ + Parses the response from the PlantNet API into a map. + """ + @spec parse(String.t()) :: map() + def parse(response), do: Jason.decode!(response) + + @doc """ + Filters the data by score. Data is a parsed response from the PlantNet API. + """ + @spec filter_by_score(map()) :: map() + def filter_by_score(data) do + updated_results = + data["results"] + |> Enum.filter(&(&1["score"] > @score_threshold)) + + Map.put(data, "results", updated_results) + end + + @doc """ + Adds external URLs to the data. Data is a parsed response from the PlantNet API. + """ + @spec add_external_urls(map()) :: map() + def add_external_urls(data) do + updated_results = + data["results"] + |> generate_gbif_url() + |> generate_pfaf_url() + |> generate_powo_url() + + Map.put(data, "results", updated_results) + end + + @spec generate_gbif_url(map()) :: map() + defp generate_gbif_url(data) do + Enum.map(data, fn result -> + gbif_id = result["gbif"]["id"] + if gbif_id, do: Map.put(result, "gbif_url", "#{@gbif_base_url}/#{gbif_id}"), else: result + end) + end + + @spec generate_pfaf_url(map()) :: map() + defp generate_pfaf_url(data) do + Enum.map(data, fn result -> + pfaf_slug = String.replace(result["species"]["scientificNameWithoutAuthor"], " ", "+") + + if pfaf_slug, + do: Map.put(result, "pfaf_url", "#{@pfaf_base_url}/#{pfaf_slug}"), + else: result + end) + end + + @spec generate_powo_url(map()) :: map() + defp generate_powo_url(data) do + Enum.map(data, fn result -> + powo_id = result["powo"]["id"] + if powo_id, do: Map.put(result, "powo_url", "#{@powo_base_url}/#{powo_id}"), else: result + end) + end +end diff --git a/test/plantid_discord_bot_test.exs b/test/plantid_discord_bot_test.exs index 054f82d..0719fe6 100644 --- a/test/plantid_discord_bot_test.exs +++ b/test/plantid_discord_bot_test.exs @@ -1,4 +1,4 @@ -defmodule PlantIdDiscordBotTest do +defmodule PlantIdDiscordBotTest.Consumer do use ExUnit.Case - doctest PlantIdDiscordBot + doctest PlantIdDiscordBot.Consumer end diff --git a/test/plantnet/parser_test.exs b/test/plantnet/parser_test.exs new file mode 100644 index 0000000..0399991 --- /dev/null +++ b/test/plantnet/parser_test.exs @@ -0,0 +1,29 @@ +defmodule PlantIdDiscordBotTest.PlantNet.Parser do + alias PlantIdDiscordBot.PlantNet.Parser + use ExUnit.Case + + doctest PlantIdDiscordBot.PlantNet.Parser + + test "parse" do + result = + PlantNetFixtures.raw_response() + |> Parser.parse() + + assert result == PlantNetFixtures.parsed_response() + end + + test "filter by score" do + result = + PlantNetFixtures.parsed_response() |> Parser.filter_by_score() + + assert result == PlantNetFixtures.parsed_response_filtered_by_score() + end + + test "add_external_urls" do + result = + PlantNetFixtures.parsed_response_filtered_by_score() + |> Parser.add_external_urls() + + assert result == PlantNetFixtures.parsed_response_with_urls() + end +end diff --git a/test/test_helper.exs b/test/test_helper.exs index 40bed13..4c95c98 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,143 +1,290 @@ -# ExUnit.start() +ExUnit.start() -# defmodule PlantNetFixtures do -# def raw_response, do: plantnet_raw_response -# def parsed_response, do: plantnet_parsed_response -# end +defmodule PlantNetFixtures do + @plantnet_raw_response "{\"query\":{\"project\":\"all\",\"images\":[\"https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg\",\"https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg\"],\"organs\":[\"auto\",\"auto\"],\"includeRelatedImages\":false,\"noReject\":false},\"language\":\"en\",\"preferedReferential\":\"k-world-flora\",\"bestMatch\":\"Prunus cerasifera Ehrh.\",\"results\":[{\"score\":0.87871,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus cerasifera\",\"scientificNameAuthorship\":\"Ehrh.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Cherry plum, myrobalan\",\"Cherry Plum\",\"Purple-leaf Plum\"],\"scientificName\":\"Prunus cerasifera Ehrh.\"},\"gbif\":{\"id\":\"3021730\"},\"powo\":{\"id\":\"729568-1\"},\"iucn\":{\"id\":\"172162\",\"category\":\"DD\"}},{\"score\":0.31668,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus × cistena\",\"scientificNameAuthorship\":\"N.E.Hansen ex Koehne\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Dwarf red-leaf plum\",\"Purple-leaf sand cherry\",\"Purple-leaved sand cherry\"],\"scientificName\":\"Prunus × cistena N.E.Hansen ex Koehne\"},\"gbif\":{\"id\":\"3022465\"},\"powo\":{\"id\":\"2959315-4\"}},{\"score\":0.01801,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus sargentii\",\"scientificNameAuthorship\":\"Rehder\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Sargent's cherry\",\"Northern Japanese hill cherry\",\"Sargent’s cherry\"],\"scientificName\":\"Prunus sargentii Rehder\"},\"gbif\":{\"id\":\"3020955\"},\"powo\":{\"id\":\"730239-1\"},\"iucn\":{\"id\":\"64127603\",\"category\":\"LC\"}},{\"score\":0.00896,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus × yedoensis\",\"scientificNameAuthorship\":\"Matsum.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Yoshino cherry\",\"Hybrid cherry\",\"Korean flowering cherry\"],\"scientificName\":\"Prunus × yedoensis Matsum.\"},\"gbif\":{\"id\":\"3021335\"},\"powo\":{\"id\":\"30119904-2\"}},{\"score\":0.00518,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus serrulata\",\"scientificNameAuthorship\":\"Lindl.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Japanese flowering cherry\",\"Japanese flowering cherry Kwanzan\",\"Tibetan Cherry\"],\"scientificName\":\"Prunus serrulata Lindl.\"},\"gbif\":{\"id\":\"3022609\"},\"powo\":{\"id\":\"730268-1\"},\"iucn\":{\"id\":\"217170511\",\"category\":\"LC\"}}],\"version\":\"2024-11-19 (7.3)\",\"remainingIdentificationRequests\":488}" -# plantnet_raw_response = -# "{\"query\":{\"project\":\"all\",\"images\":[\"https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg\",\"https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg\"],\"organs\":[\"auto\",\"auto\"],\"includeRelatedImages\":false,\"noReject\":false},\"language\":\"en\",\"preferedReferential\":\"k-world-flora\",\"bestMatch\":\"Prunus cerasifera Ehrh.\",\"results\":[{\"score\":0.87871,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus cerasifera\",\"scientificNameAuthorship\":\"Ehrh.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Cherry plum, myrobalan\",\"Cherry Plum\",\"Purple-leaf Plum\"],\"scientificName\":\"Prunus cerasifera Ehrh.\"},\"gbif\":{\"id\":\"3021730\"},\"powo\":{\"id\":\"729568-1\"},\"iucn\":{\"id\":\"172162\",\"category\":\"DD\"}},{\"score\":0.31668,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus × cistena\",\"scientificNameAuthorship\":\"N.E.Hansen ex Koehne\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Dwarf red-leaf plum\",\"Purple-leaf sand cherry\",\"Purple-leaved sand cherry\"],\"scientificName\":\"Prunus × cistena N.E.Hansen ex Koehne\"},\"gbif\":{\"id\":\"3022465\"},\"powo\":{\"id\":\"2959315-4\"}},{\"score\":0.01801,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus sargentii\",\"scientificNameAuthorship\":\"Rehder\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Sargent's cherry\",\"Northern Japanese hill cherry\",\"Sargent’s cherry\"],\"scientificName\":\"Prunus sargentii Rehder\"},\"gbif\":{\"id\":\"3020955\"},\"powo\":{\"id\":\"730239-1\"},\"iucn\":{\"id\":\"64127603\",\"category\":\"LC\"}},{\"score\":0.00896,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus × yedoensis\",\"scientificNameAuthorship\":\"Matsum.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Yoshino cherry\",\"Hybrid cherry\",\"Korean flowering cherry\"],\"scientificName\":\"Prunus × yedoensis Matsum.\"},\"gbif\":{\"id\":\"3021335\"},\"powo\":{\"id\":\"30119904-2\"}},{\"score\":0.00518,\"species\":{\"scientificNameWithoutAuthor\":\"Prunus serrulata\",\"scientificNameAuthorship\":\"Lindl.\",\"genus\":{\"scientificNameWithoutAuthor\":\"Prunus\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Prunus\"},\"family\":{\"scientificNameWithoutAuthor\":\"Rosaceae\",\"scientificNameAuthorship\":\"\",\"scientificName\":\"Rosaceae\"},\"commonNames\":[\"Japanese flowering cherry\",\"Japanese flowering cherry Kwanzan\",\"Tibetan Cherry\"],\"scientificName\":\"Prunus serrulata Lindl.\"},\"gbif\":{\"id\":\"3022609\"},\"powo\":{\"id\":\"730268-1\"},\"iucn\":{\"id\":\"217170511\",\"category\":\"LC\"}}],\"version\":\"2024-11-19 (7.3)\",\"remainingIdentificationRequests\":488}" + @plantnet_parsed_response %{ + "bestMatch" => "Prunus cerasifera Ehrh.", + "language" => "en", + "preferedReferential" => "k-world-flora", + "query" => %{ + "images" => [ + "https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg", + "https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg" + ], + "includeRelatedImages" => false, + "noReject" => false, + "organs" => ["auto", "auto"], + "project" => "all" + }, + "remainingIdentificationRequests" => 488, + "results" => [ + %{ + "gbif" => %{"id" => "3021730"}, + "iucn" => %{"category" => "DD", "id" => "172162"}, + "powo" => %{"id" => "729568-1"}, + "score" => 0.87871, + "species" => %{ + "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus cerasifera Ehrh.", + "scientificNameAuthorship" => "Ehrh.", + "scientificNameWithoutAuthor" => "Prunus cerasifera" + } + }, + %{ + "gbif" => %{"id" => "3022465"}, + "powo" => %{"id" => "2959315-4"}, + "score" => 0.31668, + "species" => %{ + "commonNames" => [ + "Dwarf red-leaf plum", + "Purple-leaf sand cherry", + "Purple-leaved sand cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", + "scientificNameAuthorship" => "N.E.Hansen ex Koehne", + "scientificNameWithoutAuthor" => "Prunus × cistena" + } + }, + %{ + "gbif" => %{"id" => "3020955"}, + "iucn" => %{"category" => "LC", "id" => "64127603"}, + "powo" => %{"id" => "730239-1"}, + "score" => 0.01801, + "species" => %{ + "commonNames" => [ + "Sargent's cherry", + "Northern Japanese hill cherry", + "Sargent’s cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus sargentii Rehder", + "scientificNameAuthorship" => "Rehder", + "scientificNameWithoutAuthor" => "Prunus sargentii" + } + }, + %{ + "gbif" => %{"id" => "3021335"}, + "powo" => %{"id" => "30119904-2"}, + "score" => 0.00896, + "species" => %{ + "commonNames" => ["Yoshino cherry", "Hybrid cherry", "Korean flowering cherry"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × yedoensis Matsum.", + "scientificNameAuthorship" => "Matsum.", + "scientificNameWithoutAuthor" => "Prunus × yedoensis" + } + }, + %{ + "gbif" => %{"id" => "3022609"}, + "iucn" => %{"category" => "LC", "id" => "217170511"}, + "powo" => %{"id" => "730268-1"}, + "score" => 0.00518, + "species" => %{ + "commonNames" => [ + "Japanese flowering cherry", + "Japanese flowering cherry Kwanzan", + "Tibetan Cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus serrulata Lindl.", + "scientificNameAuthorship" => "Lindl.", + "scientificNameWithoutAuthor" => "Prunus serrulata" + } + } + ], + "version" => "2024-11-19 (7.3)" + } -# plantnet_parsed_response = [ -# %{ -# "gbif" => %{"id" => "3021730"}, -# "gbif_url" => "https://www.gbif.org/species/3021730", -# "iucn" => %{"category" => "DD", "id" => "172162"}, -# "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera", -# "powo" => %{"id" => "729568-1"}, -# "powo_url" => "https://powo.science.kew.org/taxon/729568-1", -# "score" => 0.87871, -# "species" => %{ -# "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], -# "family" => %{ -# "scientificName" => "Rosaceae", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Rosaceae" -# }, -# "genus" => %{ -# "scientificName" => "Prunus", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Prunus" -# }, -# "scientificName" => "Prunus cerasifera Ehrh.", -# "scientificNameAuthorship" => "Ehrh.", -# "scientificNameWithoutAuthor" => "Prunus cerasifera" -# } -# }, -# %{ -# "gbif" => %{"id" => "3022465"}, -# "gbif_url" => "https://www.gbif.org/species/3022465", -# "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+×+cistena", -# "powo" => %{"id" => "2959315-4"}, -# "powo_url" => "https://powo.science.kew.org/taxon/2959315-4", -# "score" => 0.31668, -# "species" => %{ -# "commonNames" => [ -# "Dwarf red-leaf plum", -# "Purple-leaf sand cherry", -# "Purple-leaved sand cherry" -# ], -# "family" => %{ -# "scientificName" => "Rosaceae", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Rosaceae" -# }, -# "genus" => %{ -# "scientificName" => "Prunus", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Prunus" -# }, -# "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", -# "scientificNameAuthorship" => "N.E.Hansen ex Koehne", -# "scientificNameWithoutAuthor" => "Prunus × cistena" -# } -# }, -# %{ -# "gbif" => %{"id" => "3020955"}, -# "gbif_url" => "https://www.gbif.org/species/3020955", -# "iucn" => %{"category" => "LC", "id" => "64127603"}, -# "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+sargentii", -# "powo" => %{"id" => "730239-1"}, -# "powo_url" => "https://powo.science.kew.org/taxon/730239-1", -# "score" => 0.01801, -# "species" => %{ -# "commonNames" => ["Sargent's cherry", "Northern Japanese hill cherry", "Sargent’s cherry"], -# "family" => %{ -# "scientificName" => "Rosaceae", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Rosaceae" -# }, -# "genus" => %{ -# "scientificName" => "Prunus", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Prunus" -# }, -# "scientificName" => "Prunus sargentii Rehder", -# "scientificNameAuthorship" => "Rehder", -# "scientificNameWithoutAuthor" => "Prunus sargentii" -# } -# }, -# %{ -# "gbif" => %{"id" => "3021335"}, -# "gbif_url" => "https://www.gbif.org/species/3021335", -# "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+×+yedoensis", -# "powo" => %{"id" => "30119904-2"}, -# "powo_url" => "https://powo.science.kew.org/taxon/30119904-2", -# "score" => 0.00896, -# "species" => %{ -# "commonNames" => ["Yoshino cherry", "Hybrid cherry", "Korean flowering cherry"], -# "family" => %{ -# "scientificName" => "Rosaceae", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Rosaceae" -# }, -# "genus" => %{ -# "scientificName" => "Prunus", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Prunus" -# }, -# "scientificName" => "Prunus × yedoensis Matsum.", -# "scientificNameAuthorship" => "Matsum.", -# "scientificNameWithoutAuthor" => "Prunus × yedoensis" -# } -# }, -# %{ -# "gbif" => %{"id" => "3022609"}, -# "gbif_url" => "https://www.gbif.org/species/3022609", -# "iucn" => %{"category" => "LC", "id" => "217170511"}, -# "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+serrulata", -# "powo" => %{"id" => "730268-1"}, -# "powo_url" => "https://powo.science.kew.org/taxon/730268-1", -# "score" => 0.00518, -# "species" => %{ -# "commonNames" => [ -# "Japanese flowering cherry", -# "Japanese flowering cherry Kwanzan", -# "Tibetan Cherry" -# ], -# "family" => %{ -# "scientificName" => "Rosaceae", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Rosaceae" -# }, -# "genus" => %{ -# "scientificName" => "Prunus", -# "scientificNameAuthorship" => "", -# "scientificNameWithoutAuthor" => "Prunus" -# }, -# "scientificName" => "Prunus serrulata Lindl.", -# "scientificNameAuthorship" => "Lindl.", -# "scientificNameWithoutAuthor" => "Prunus serrulata" -# } -# } -# ] + @plantnet_parsed_response_filtered_by_score %{ + "bestMatch" => "Prunus cerasifera Ehrh.", + "language" => "en", + "preferedReferential" => "k-world-flora", + "query" => %{ + "images" => [ + "https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg", + "https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg" + ], + "includeRelatedImages" => false, + "noReject" => false, + "organs" => ["auto", "auto"], + "project" => "all" + }, + "remainingIdentificationRequests" => 488, + "results" => [ + %{ + "gbif" => %{"id" => "3021730"}, + "iucn" => %{"category" => "DD", "id" => "172162"}, + "powo" => %{"id" => "729568-1"}, + "score" => 0.87871, + "species" => %{ + "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus cerasifera Ehrh.", + "scientificNameAuthorship" => "Ehrh.", + "scientificNameWithoutAuthor" => "Prunus cerasifera" + } + }, + %{ + "gbif" => %{"id" => "3022465"}, + "powo" => %{"id" => "2959315-4"}, + "score" => 0.31668, + "species" => %{ + "commonNames" => [ + "Dwarf red-leaf plum", + "Purple-leaf sand cherry", + "Purple-leaved sand cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", + "scientificNameAuthorship" => "N.E.Hansen ex Koehne", + "scientificNameWithoutAuthor" => "Prunus × cistena" + } + } + ], + "version" => "2024-11-19 (7.3)" + } + + @plantnet_parsed_response_with_urls %{ + "bestMatch" => "Prunus cerasifera Ehrh.", + "language" => "en", + "preferedReferential" => "k-world-flora", + "query" => %{ + "images" => [ + "https://upload.wikimedia.org/wikipedia/commons/f/ff/Prunus_cerasifera_A.jpg", + "https://le-jardin-de-pascal.com/2195113-large_default/prunus-cerasifera-atropurpurea-prunier-myrobolan-nigra.jpg" + ], + "includeRelatedImages" => false, + "noReject" => false, + "organs" => ["auto", "auto"], + "project" => "all" + }, + "remainingIdentificationRequests" => 488, + "results" => [ + %{ + "gbif" => %{"id" => "3021730"}, + "gbif_url" => "https://www.gbif.org/species/3021730", + "iucn" => %{"category" => "DD", "id" => "172162"}, + "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+cerasifera", + "powo" => %{"id" => "729568-1"}, + "powo_url" => "https://powo.science.kew.org/taxon/729568-1", + "score" => 0.87871, + "species" => %{ + "commonNames" => ["Cherry plum, myrobalan", "Cherry Plum", "Purple-leaf Plum"], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus cerasifera Ehrh.", + "scientificNameAuthorship" => "Ehrh.", + "scientificNameWithoutAuthor" => "Prunus cerasifera" + } + }, + %{ + "gbif" => %{"id" => "3022465"}, + "gbif_url" => "https://www.gbif.org/species/3022465", + "pfaf_url" => "https://pfaf.org/user/Plant.aspx?LatinName=/Prunus+×+cistena", + "powo" => %{"id" => "2959315-4"}, + "powo_url" => "https://powo.science.kew.org/taxon/2959315-4", + "score" => 0.31668, + "species" => %{ + "commonNames" => [ + "Dwarf red-leaf plum", + "Purple-leaf sand cherry", + "Purple-leaved sand cherry" + ], + "family" => %{ + "scientificName" => "Rosaceae", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Rosaceae" + }, + "genus" => %{ + "scientificName" => "Prunus", + "scientificNameAuthorship" => "", + "scientificNameWithoutAuthor" => "Prunus" + }, + "scientificName" => "Prunus × cistena N.E.Hansen ex Koehne", + "scientificNameAuthorship" => "N.E.Hansen ex Koehne", + "scientificNameWithoutAuthor" => "Prunus × cistena" + } + } + ], + "version" => "2024-11-19 (7.3)" + } + + def raw_response, do: @plantnet_raw_response + def parsed_response, do: @plantnet_parsed_response + def parsed_response_filtered_by_score, do: @plantnet_parsed_response_filtered_by_score + def parsed_response_with_urls, do: @plantnet_parsed_response_with_urls +end