Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#17] Add mapping of measurements #37

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 172 additions & 2 deletions transformations/abcd2bioschemas/abcd2bioschemas-xml.xslt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ exclude-result-prefixes="xsl md panxslt set">
<xsl:variable name="biostratigraphic" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Stratigraphy/abcd:BiostratigraphicTerms/abcd:BiostratigraphicTerm/abcd:Term"></xsl:variable>
<xsl:variable name="taxon_name" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Identifications/abcd:Identification/abcd:Result/abcd:TaxonIdentified/abcd:ScientificName/abcd:FullScientificNameString"></xsl:variable>
<xsl:variable name="higher_taxon" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Identifications/abcd:Identification/abcd:Result/abcd:TaxonIdentified/abcd:HigherTaxa/abcd:HigherTaxon/abcd:HigherTaxonName"></xsl:variable>

<xsl:variable name="altitude" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Altitude"></xsl:variable>
<xsl:variable name="biotope_measure" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Biotope/abcd:MeasurementsOrFacts"></xsl:variable>
<xsl:variable name="depth" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Depth"></xsl:variable>
<xsl:variable name="height" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Height"></xsl:variable>
<xsl:variable name="site_measure" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:SiteMeasurementsOrFacts"></xsl:variable>
<xsl:variable name="unit_measure" select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:MeasurementsOrFacts"></xsl:variable>



Expand Down Expand Up @@ -411,9 +416,174 @@ exclude-result-prefixes="xsl md panxslt set">
<name><xsl:value-of select="$dataset_contributors"/></name>
</contributor>
</xsl:if>

<!-- variableMeasured -->
<!-- Altitude -->
<xsl:variable name="minAltitude">
<xsl:for-each select="$altitude/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and (not(../abcd:UnitOfMeasurement) or ../abcd:UnitOfMeasurement = 'm')]">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxAltitude">
<xsl:for-each select="$altitude/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and (not(../abcd:UnitOfMeasurement) or ../abcd:UnitOfMeasurement = 'm')]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<variableMeasured type="PropertyValue">
<name>Elevation</name>
<propertyID>https://schema.org/elevation</propertyID>
<xsl:choose>
<xsl:when test="$minAltitude = $maxAltitude">
<value xsi:type="xs:double"><xsl:value-of select="$minAltitude"/></value>
<unitText>m</unitText>
</xsl:when>
<xsl:otherwise>
<minValue xsi:type="xs:double"><xsl:value-of select="$minAltitude"/></minValue>
<xsl:if test="$maxAltitude"><maxValue xsi:type="xs:double"><xsl:value-of select="$maxAltitude"/></maxValue></xsl:if>
<unitText>m</unitText>
</xsl:otherwise>
</xsl:choose>
</variableMeasured>

<!-- Depth -->
<xsl:variable name="minDepth">
<xsl:for-each select="$depth/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and (not(../abcd:UnitOfMeasurement) or ../abcd:UnitOfMeasurement = 'm')]">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxDepth">
<xsl:for-each select="$depth/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and (not(../abcd:UnitOfMeasurement) or ../abcd:UnitOfMeasurement = 'm')]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<variableMeasured type="PropertyValue">
<name>Depth</name>
<propertyID>https://schema.org/depth</propertyID>
<xsl:choose>
<xsl:when test="$minDepth = $maxDepth">
<value xsi:type="xs:double"><xsl:value-of select="$minDepth"/></value>
<unitText>m</unitText>
</xsl:when>
<xsl:otherwise>
<minValue xsi:type="xs:double"><xsl:value-of select="$minDepth"/></minValue>
<xsl:if test="$maxDepth"><maxValue xsi:type="xs:double"><xsl:value-of select="$maxDepth"/></maxValue></xsl:if>
<unitText>m</unitText>
</xsl:otherwise>
</xsl:choose>
</variableMeasured>

<!-- Biotope -->
<xsl:variable name="parameters">
<xsl:for-each select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:Biotope/abcd:MeasurementsOrFacts/abcd:MeasurementOrFact/abcd:MeasurementOrFactAtomised/abcd:Parameter[not(.=preceding::*)]">
<parameter><xsl:value-of select="."/></parameter>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="$parameters/parameter">
<test><xsl:value-of select="."/></test>
<xsl:variable name="param" select="."/>
<xsl:variable name="minValue">
<xsl:for-each select="$biotope_measure/abcd:MeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxValue">
<xsl:for-each select="$biotope_measure/abcd:MeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<variableMeasured type="PropertyValue">
<name><xsl:value-of select="$param"/></name>
<xsl:choose>
<xsl:when test="$minValue = $maxValue">
<value xsi:type="xs:double"><xsl:value-of select="$minValue"/></value>
</xsl:when>
<xsl:otherwise>
<minValue xsi:type="xs:double"><xsl:value-of select="$minValue"/></minValue>
<maxValue xsi:type="xs:double"><xsl:value-of select="$maxValue"/></maxValue>
</xsl:otherwise>
</xsl:choose>
</variableMeasured>
</xsl:for-each>

<!-- Unit measurements -->
<xsl:variable name="parameters">
<xsl:for-each select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:MeasurementsOrFacts/abcd:MeasurementOrFact/abcd:MeasurementOrFactAtomised/abcd:Parameter[not(.=preceding::*)]">
<parameter><xsl:value-of select="."/></parameter>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="$parameters/parameter">
<xsl:variable name="param" select="."/>
<xsl:variable name="minValue">
<xsl:for-each select="$unit_measure/abcd:MeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxValue">
<xsl:for-each select="$unit_measure/abcd:MeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<variableMeasured type="PropertyValue">
<name><xsl:value-of select="$param"/></name>
<xsl:choose>
<xsl:when test="$minValue = $maxValue">
<value xsi:type="xs:double"><xsl:value-of select="$minValue"/></value>
</xsl:when>
<xsl:otherwise>
<minValue xsi:type="xs:double"><xsl:value-of select="$minValue"/></minValue>
<maxValue xsi:type="xs:double"><xsl:value-of select="$maxValue"/></maxValue>
</xsl:otherwise>
</xsl:choose>
</variableMeasured>
</xsl:for-each>

<!-- Site measurements -->
<xsl:variable name="parameters">
<xsl:for-each select="/abcd:DataSets/abcd:DataSet/abcd:Units/abcd:Unit/abcd:Gathering/abcd:SiteMeasurementsOrFacts/abcd:SiteMeasurementOrFact/abcd:MeasurementOrFactAtomised/abcd:Parameter[not(.=preceding::*)]">
<parameter><xsl:value-of select="."/></parameter>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="$parameters/parameter">
<xsl:variable name="param" select="."/>
<xsl:variable name="minValue">
<xsl:for-each select="$site_measure/abcd:SiteMeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="ascending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxValue">
<xsl:for-each select="$site_measure/abcd:SiteMeasurementOrFact[abcd:MeasurementOrFactAtomised/abcd:Parameter=$param]/abcd:MeasurementOrFactAtomised/*[(self::abcd:LowerValue or self::abcd:UpperValue) and number(.)]">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
</xsl:for-each>
</xsl:variable>
<variableMeasured type="PropertyValue">
<name><xsl:value-of select="$param"/></name>
<xsl:choose>
<xsl:when test="$minValue = $maxValue">
<value xsi:type="xs:double"><xsl:value-of select="$minValue"/></value>
</xsl:when>
<xsl:otherwise>
<minValue xsi:type="xs:double"><xsl:value-of select="$minValue"/></minValue>
<maxValue xsi:type="xs:double"><xsl:value-of select="$maxValue"/></maxValue>
</xsl:otherwise>
</xsl:choose>
</variableMeasured>
</xsl:for-each>

<!-- TODO:
- Gathering Agents as contributors?
- variableMeasured
- variableMeasured:
- Identify variants with multiple values in the same element (e.g. in LowerValue)
- Add examples
-->
</jsonld>
</xsl:template>
Expand Down
Loading