1

Topic: Creating a Simple Taxon Dictionary

Morning all.

I'm trying to create a simple 'de-normalised' taxon dictionary containing just recommended taxon list items that we will then take out of Recorder into our Postgres database to do spatial work with. This taxon dictionary will be joined to a simple de-normalised list of records, and a taxon groups table, therefore keeping the Postgres structure as simple as possible.

I am using the following script that seems to work fine - but I'm just a little nervous that I may have missed something and would be grateful if someone with a better understanding of R6 could cast their eye over it.

Here is the script (including the create table code in case someone wants to have a shot at running it).

Many thanks,
Steve

-- *****************************************************************************************************
-- Taxon dictionary table.
CREATE TABLE [dbo].[denormal_taxon_dict] (
  [rtvk] [varchar](16)  COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [rtlik] [varchar](16)  COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [actual_name] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [common_name] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [preferred_name] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [taxon_family] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [taxon_order] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [taxon_group_key] [varchar](16)  COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
  [taxon_group_name] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
--GO
;
-- *****************************************************************************************************
-- Clear all the tables.
TRUNCATE TABLE [dbo].[denormal_taxon_dict];
;
-- *****************************************************************************************************
-- Insert into denormal_taxon_dict
INSERT INTO  [dbo].[denormal_taxon_dict]
(
  rtvk,
  rtlik,
  actual_name,
  common_name,
  preferred_name,
  taxon_family,
  taxon_order,
  taxon_group_key,
  taxon_group_name
)
SELECT DISTINCT
NS.RECOMMENDED_TAXON_VERSION_KEY,
NS.RECOMMENDED_TAXON_LIST_ITEM_KEY,
ITN.ACTUAL_NAME,
ITN.COMMON_NAME,
ITN.PREFERRED_NAME,
ITN_FAMILY.PREFERRED_NAME AS FAMILY,
ITN_ORDER.PREFERRED_NAME AS "ORDER",
--TV.TAXON_VERSION_KEY,
--TV.OUTPUT_GROUP_KEY,
TG.TAXON_GROUP_KEY,
TG.TAXON_GROUP_NAME

FROM dbo.NAMESERVER NS
--FAMILY
INNER JOIN dbo.INDEX_TAXON_GROUP ITG_FAMILY ON NS.RECOMMENDED_TAXON_LIST_ITEM_KEY = ITG_FAMILY.CONTAINED_LIST_ITEM_KEY
INNER JOIN dbo.TAXON_LIST_ITEM TLI2 ON TLI2.TAXON_LIST_ITEM_KEY = ITG_FAMILY.Taxon_List_Item_Key AND TLI2.TAXON_RANK_KEY = 'NBNSYS0000000018'--12-order;18-family
LEFT JOIN INDEX_TAXON_NAME ITN_FAMILY ON ITN_FAMILY.TAXON_LIST_ITEM_KEY = ITG_FAMILY.TAXON_LIST_ITEM_KEY

--ORDER
INNER JOIN dbo.INDEX_TAXON_GROUP ITG_ORDER ON NS.RECOMMENDED_TAXON_LIST_ITEM_KEY = ITG_ORDER.CONTAINED_LIST_ITEM_KEY
INNER JOIN dbo.TAXON_LIST_ITEM TLI3 ON TLI3.TAXON_LIST_ITEM_KEY = ITG_ORDER.Taxon_List_Item_Key AND TLI3.TAXON_RANK_KEY = 'NBNSYS0000000012'--12-order;18-family
LEFT JOIN INDEX_TAXON_NAME ITN_ORDER ON ITN_ORDER.TAXON_LIST_ITEM_KEY = ITG_ORDER.TAXON_LIST_ITEM_KEY

--EVERYTHING ELSE
LEFT JOIN dbo.TAXON_LIST_ITEM TLI ON NS.RECOMMENDED_TAXON_LIST_ITEM_KEY = TLI.TAXON_LIST_ITEM_KEY
LEFT JOIN dbo.INDEX_TAXON_NAME ITN ON TLI.TAXON_LIST_ITEM_KEY = ITN.TAXON_LIST_ITEM_KEY
LEFT JOIN dbo.TAXON_VERSION TV ON NS.RECOMMENDED_TAXON_VERSION_KEY = TV.TAXON_VERSION_KEY
LEFT JOIN dbo.TAXON_GROUP TG ON TV.OUTPUT_GROUP_KEY = TG.TAXON_GROUP_KEY
ORDER BY ITN.ACTUAL_NAME;

-- *****************************************************************************************************

=====================================================
Steve Goddard - IT Officer
Biodiversity Information Service for Powys & Brecon Beacons National Park
T: 01874 610881 - E: steve[at]b-i-s.org - W: www.b-i-s.org

2

Re: Creating a Simple Taxon Dictionary

It is now much easier to get the Order and Family for RTLIK and it is more accurate as well. See table Index_taxon_Hierarchy.  I have written the following which may help, but needs checking, because it appears to  missing some records. 

Select ITN.Taxon_List_Item_Key,  TLI.Taxon_Version_Key,  ITN.Actual_Name, ITN.Common_Name,TV.Output_Group_Key,T.Item_name,T1.Item_Name, TG.Taxon_Group_Name  from
Index_Taxon_Name ITN  INNER JOIN Taxon_List_Item TLI ON TLI.Taxon_List_item_Key = ITN.Taxon_List_Item_Key
INNER JOIN Taxon_Version TV ON TV.Taxon_Version_Key = TLI.Taxon_Version_Key
INNER JOIN Taxon_Group TG ON TG.Taxon_Group_Key =  TV.OUtput_Group_Key
INNER  JOIN Index_Taxon_Hierarchy ITH ON ITH.Recommended_Taxon_Version_Key =  TV.Taxon_Version_Key AND ITH.Hierarchy_Type = 'F '
INNER JOIN Taxon_Version TV2 ON TV2.Taxon_Version_Key = ITH.Hierarchy_taxon_Version_Key
INNER JOIN Taxon T ON T.Taxon_Key = TV2.Taxon_Key
INNER  JOIN Index_Taxon_Hierarchy ITH2 ON ITH2.Recommended_Taxon_Version_Key =  TV.Taxon_Version_Key AND ITH2.Hierarchy_Type = 'O '
INNER JOIN Taxon_Version TV3 ON TV3.Taxon_Version_Key = ITH2.Hierarchy_taxon_Version_Key
INNER JOIN Taxon T1 ON T1.Taxon_Key = TV3.Taxon_Key

WHERE ITN.Recommended_Taxon_List_Item_Key = ITN.Taxon_List_Item_Key
ORDER BY ITN.Actual_name

Mike Weideli

3

Re: Creating a Simple Taxon Dictionary

Thank you very much Mike - that looks great.

The old query returned 94,748 records in 17 seconds.
The new one returns 103,635 records in 3 seconds!

What makes you think there are records missing?

Steve

=====================================================
Steve Goddard - IT Officer
Biodiversity Information Service for Powys & Brecon Beacons National Park
T: 01874 610881 - E: steve[at]b-i-s.org - W: www.b-i-s.org

4

Re: Creating a Simple Taxon Dictionary

I checked it my running select count(*) from from Index_Taxon_name where Taxon_List_Item_Key = Recommended_Taxon_List_Item_Key and the number of records this returns is slightly greater. I know that some will be down to user added taxa, but this doesn't seem to account for all of them.  I think my original query is Ok as I know there are some common names without scientific names and I suspect these don't get included, but to be totally sure it would be necessary to identify exactly what is causing the difference .

Mike Weideli

5

Re: Creating a Simple Taxon Dictionary

Thanks Mike - I'll run with this for the moment - when I have more time i'll try and analyse what records we have that don't find a match in this table.

Steve

=====================================================
Steve Goddard - IT Officer
Biodiversity Information Service for Powys & Brecon Beacons National Park
T: 01874 610881 - E: steve[at]b-i-s.org - W: www.b-i-s.org