######################################################
###          2017 prodcom list definition          ###
######################################################

dsource register "PRD_2017"                                     \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRD_2017_20200617_185035.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRD_2017                                 \
    dataSourceName  "PRD_2017"                                  \
    "columns"       4                                           \
    "1"             "{Code}"                                    \
    "1.datatype"    "string"                                    \
    "2"             "{Description}"                             \
    "2.datatype"    "string"                                    \
    "3"             "{Parent}"                                  \
    "3.datatype"    "string"                                    \
    "3.if-empty"    "absent"                                    \
    "4"             "{Level}"                                   \
    "4.datatype"    "string"

# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy


######################################################
###          2016 prodcom list definition          ###
######################################################

dsource register "PRD_2016"                                     \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRD_2016_20200617_185122.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRD_2016                                 \
    dataSourceName  "PRD_2016"                                  \
    "columns"       4                                           \
    "1"             "{Code}"                                    \
    "1.datatype"    "string"                                    \
    "2"             "{Description}"                             \
    "2.datatype"    "string"                                    \
    "3"             "{Parent}"                                  \
    "3.datatype"    "string"                                    \
    "3.if-empty"    "absent"                                    \
    "4"             "{Level}"                                   \
    "4.datatype"    "string"

# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy


######################################################
###        Prodcom Correspondence 2017 - 2016      ###
######################################################

dsource register "PRC_2017_2016"                                \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRC_2017_2016.csv"                \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRC_2017_2016                            \
    dataSourceName  "PRC_2017_2016"                             \
    "columns"       2                                           \
    "1"             "{PRC2017}"                                 \
    "1.datatype"    "string"                                    \
    "1.if-empty"    "absent"                                    \
    "2"             "{PRC2016}"                                 \
    "2.datatype"    "string"                                    \
    "2.if-empty"    "absent"

    # 1 This is the PRC ClassificationCodes for 2017-2018
    # 1 if blank the corresponding code was deleted
    # 2 This is the PRC ClassificationCodes for 2016
    # 2 if blank the corresponding code was added


######################################################
###             2017 CN list definition            ###
######################################################

dsource register "CT_2017"                                      \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/HSCodeandDescription_2017.csv"    \
    header  true                                                \
    quote   '"'

tupletable create ufrd:CT_2017                                  \
    dataSourceName  "CT_2017"                                   \
    "columns"       4                                           \
    "1"             "{Code}"                                    \
    "1.datatype"    "string"                                    \
    "2"             "{Description}"                             \
    "2.datatype"    "string"                                    \
    "3"             "{Parent Code}"                             \
    "3.datatype"    "string"                                    \
    "3.if-empty"    "absent"                                    \
    "4"             "{Level}"                                   \
    "4.datatype"    "string"

# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy


######################################################
###                 2018 PRODCOM Data              ###
######################################################

dsource register "PRODCOM2018DATA"                              \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRODCOM2018DATA.csv"              \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRODCOM2018DATA                          \
    dataSourceName  "PRODCOM2018DATA"                           \
    "columns"       4                                           \
    "1"             "{ID}"                                      \
    "1.datatype"    "string"                                    \
    "2"             "{PRCCODE}"                                 \
    "2.datatype"    "string"                                    \
    "3"             "{PRODQNT}"                                 \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "absent"                                    \
    "4"             "{QNTUNIT}"                                 \
    "4.datatype"    "string"	                                \
    "4.if-empty"    "default"	                                \
    "4.default"     "unknown"

    # 1 ID generated for unique observations
    # 2 This is the ClassificationCode and related to 1. by `objectDefinedBy`
    # 3 MeasurementValue (of measurement of observation) - the measurement is implicit here. If blank then the value was witheld (but is not 0 necessarily)
    # 4 Unit of Measure


######################################################
###                 2017 PRODCOM Data              ###
######################################################

dsource register "PRODCOM2017DATA"                              \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRODCOM2017DATA.csv"              \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRODCOM2017DATA                          \
    dataSourceName  "PRODCOM2017DATA"                           \
    "columns"       4                                           \
    "1"             "{ID}"                                      \
    "1.datatype"    "string"                                    \
    "2"             "{PRCCODE}"                                 \
    "2.datatype"    "string"                                    \
    "3"             "{PRODQNT}"                                 \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "absent"                                    \
    "4"             "{QNTUNIT}"                                 \
    "4.datatype"    "string"	                                \
    "4.if-empty"    "default"	                                \
    "4.default"     "unknown"

    # 1 ID generated for unique observations
    # 2 This is the ClassificationCode and related to 1. by `objectDefinedBy`
    # 3 MeasurementValue (of measurement of observation) - the measurement is implicit here. If blank then the value was witheld (but is not 0 necessarily)
    # 4 Unit of Measure


######################################################
###                 2016 PRODCOM Data              ###
######################################################

dsource register "PRODCOM2016DATA"                              \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/PRODCOM2016DATA.csv"              \
    header  true                                                \
    quote   '"'

tupletable create ufrd:PRODCOM2016DATA                          \
    dataSourceName  "PRODCOM2016DATA"                           \
    "columns"       4                                           \
    "1"             "{ID}"                                      \
    "1.datatype"    "string"                                    \
    "2"             "{PRCCODE}"                                 \
    "2.datatype"    "string"                                    \
    "3"             "{PRODQNT}"                                 \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "absent"                                    \
    "4"             "{QNTUNIT}"                                 \
    "4.datatype"    "string"	                                \
    "4.if-empty"    "default"	                                \
    "4.default"     "unknown"

    # 1 ID generated for unique observations
    # 2 This is the ClassificationCode and related to 1. by `objectDefinedBy`
    # 3 MeasurementValue (of measurement of observation) - the measurement is implicit here. If blank then the value was witheld (but is not 0 necessarily)
    # 4 Unit of Measure


######################################################
###               2018 COMTRADE Imports            ###
######################################################

dsource register "ct2018imports"                                \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/ct-2018-imports.csv"              \
    header  true                                                \
    quote   '"'

tupletable create ufrd:ct2018imports                            \
    dataSourceName  "ct2018imports"                             \
    "columns"       3                                           \
    "1"             "{ID}"                                      \
    "1.datatype"    "string"                                    \
    "2"             "{Commodity Code}"                          \
    "2.datatype"    "string"                                    \
    "3"             "{Netweight (kg)}"                          \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "absent"

    # 1 ID generated for unique observations
    # 2 This is the ClassificationCode and related to 1. by `objectDefinedBy`
    # 3 MeasurementValue (of measurement of observation) - the measurement is implicit here. If blank then the value was witheld (but is not 0 necessarily)


######################################################
###               2018 COMTRADE Exports            ###
######################################################

dsource register "ct2018exports"                                \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/ct-2018-exports.csv"              \
    header  true                                                \
    quote   '"'

tupletable create ufrd:ct2018exports                            \
    dataSourceName  "ct2018exports"                             \
    "columns"       3                                           \
    "1"             "{ID}"                                      \
    "1.datatype"    "string"                                    \
    "2"             "{Commodity Code}"                          \
    "2.datatype"    "string"                                    \
    "3"             "{Netweight (kg)}"                          \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "absent"

    # 1 ID generated for unique observations
    # 2 This is the ClassificationCode and related to 1. by `objectDefinedBy`
    # 3 MeasurementValue (of measurement of observation) - the measurement is implicit here. If blank then the value was witheld (but is not 0 necessarily)


######################################################
### Connect CODE to OBJECT using the CN speadsheet ###
######################################################

# Object Definitions (2017 PRC)

dsource register "ObjectDefinitions"                            \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/Object_table_for_ontoloy.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:ObjectDefinitions                        \
    dataSourceName  "ObjectDefinitions"                         \
    "columns"       3                                           \
    "1"             "{ObjectType}"                              \
    "1.datatype"    "string"                                    \
    "2"             "{Code}"                                    \
    "2.datatype"    "string"                                    \
    "3"             "{PRC}"                                     \
    "3.datatype"    "string"                                    \
    "3.if-empty"    "absent"

    # 1 String of Object Type
    # 2 IRI of CN ClassificationCodeObject
    # 3 IRI of PRC ClassificationCodeObject


#############################
### Metric and Unit Table ###
#############################

# Metrics Units Table (2017 PRC)

dsource register "MetricUnits"	                                \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/metrics_units.csv"		        \
    header  true                                                \
    quote   '"'

tupletable create ufrd:MetricUnits	                            \
    dataSourceName  "MetricUnits"	                            \
    "columns"       3                                           \
    "1"             "{Metric}"	                                \
    "1.datatype"    "string"                                    \
    "2"             "{UnitOfMeasure}"                           \
    "2.datatype"    "string"                                    \
    "3"             "{Conversion}"                              \
    "3.datatype"    "xsd:decimal"                               \
    "3.if-empty"    "default"                                   \
    "3.default"     "1.0"

    # 1 Metric of measure
    # 2 Unit of measure given in data
    # 3 Conversion to standard units

######################################################
###          UNFCCC Emissions By Category          ###
######################################################

dsource register "UNFCCC"                       \
    type    delimitedFile                       \
    file    "$(dir.root)/data/unfcc_processed_USA_ghg.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:UNFCCC                                 \
    dataSourceName  "UNFCCC"                                  \
    "columns"       7                                           \
    "1"             "{ID}"                                    \
    "1.datatype"    "string"                                       \
    "2"             "{Source}"                                    \
    "2.datatype"    "string"                                    \
    "3"             "{GHG}"                             \
    "3.datatype"    "string"                                    \
    "4"             "{Value}"                                  \
    "4.datatype"    "string"                                    \
    "4.if-empty"    "absent"                                    \
    "5"             "{Unit}"                                   \
    "5.datatype"    "string"                                    \
    "6"             "{Year}"                                   \
    "6.datatype"    "string"                                     \
    "7"             "{Region}"                                   \
    "7.datatype"    "string" 


# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy

######################################################
###          UNFCCC Category Hierarchies           ###
######################################################

dsource register "UNFCCC Process Hierarchy"                                       \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/unfcc_process_hierarchy.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:UNFCCCPH                                  \
    dataSourceName  "UNFCCC Process Hierarchy"                          \
    "columns"       2                                           \
    "1"             "{Parent}"                                  \
    "1.datatype"    "string"                                    \
    "2"             "{Child}"                                   \
    "2.datatype"    "string"


# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy

######################################################
###          UNFCCC Category Hierarchies           ###
######################################################

dsource register "UNFCCC Object Hierarchy"                                       \
    type    delimitedFile                                       \
    file    "$(dir.root)/data/unfcc_object_hierarchy.csv"     \
    header  true                                                \
    quote   '"'

tupletable create ufrd:UNFCCCOH                                  \
    dataSourceName  "UNFCCC Object Hierarchy"                          \
    "columns"       2                                           \
    "1"             "{Parent}"                                  \
    "1.datatype"    "string"                                    \
    "2"             "{Child}"                                   \
    "2.datatype"    "string"


# 1 This is the classification code, with dots removed in advance
# 2 This is the classification description
# 3 This is the parent code for the classification code, with dots removed in advance
# 4 This is the level of the classification code in the hierarchy
