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

identifier and is_part_of #35

Merged
merged 6 commits into from
Sep 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'nokogiri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'
require_relative 'module_resource_info'
require_relative 'module_metadata_info'

module ADIWG
module Mdtranslator
Expand Down Expand Up @@ -42,6 +43,8 @@ def self.unpack(xMetadata, hResponseObj)

intMetadata[:resourceInfo] = ResourceInformation.unpack(xDataIdentification, hResponseObj)

intMetadata[:metadataInfo] = MetadataInformation.unpack(xMetadata, hResponseObj)

# :distributorInfo
# :associatedResources
# :additionalDocuments
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'nokogiri'
require 'adiwg/mdtranslator/internal/internal_metadata_obj'

module ADIWG
module Mdtranslator
module Readers
module Iso191152
module MetadataInformation
@@fileIdentifierXPath = 'gmd:fileIdentifier//gco:CharacterString'
@@parentIdentifierXPath = 'gmd:parentIdentifier//gco:CharacterString'
def self.unpack(xMetadata, hResponseObj)

# instance classes needed in script
intMetadataClass = InternalMetadata.new
hMetadataInfo = intMetadataClass.newMetadataInfo

# <xs:element name="fileIdentifier" type="gco:CharacterString_PropertyType" minOccurs="0"/>
fileIdentifier = xMetadata.xpath(@@fileIdentifierXPath)[0]
hMetadataInfo[:metadataIdentifier][:identifier] = fileIdentifier.text unless fileIdentifier.nil?

# <xs:element name="parentIdentifier" type="gco:CharacterString_PropertyType" minOccurs="0"/>
parentIdentifier = xMetadata.xpath(@@parentIdentifierXPath)[0]
hMetadataInfo[:parentMetadata][:identifier] = [{"identifier":parentIdentifier.text}] unless parentIdentifier.nil?

return hMetadataInfo

end

end

end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ module Dcat_us
module Identifier

def self.build(intObj)
# identifier from metadataInfo has priority
identifier = intObj.dig(:metadata, :metadataInfo, :metadataIdentifier, :identifier)
return identifier unless identifier.nil?

# identifier from resourceInfo
citation = intObj.dig(:metadata, :resourceInfo, :citation)
identifiers = citation&.dig(:identifiers)
onlineResources = citation&.dig(:onlineResources)
uri = onlineResources.dig(0, :olResURI)

# return uri if it exists, or the first identifier found
# uri is supposed to be more descriptive than identifiers
return uri unless uri.nil?
return identifiers[0][:identifier] unless identifiers.nil? || identifiers.empty?

nil
end


end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module Dcat_us
module IsPartOf

def self.build(intObj)
parentIdentifiers = intObj.dig(:metadata, :metadataInfo, :parentMetadata, :identifier)
return parentIdentifiers[0][:identifier] unless parentIdentifiers.nil? || parentIdentifiers.empty?

associatedResources = intObj.dig(:metadata, :associatedResources)

associatedResources.each do |resource|
Expand Down
7 changes: 6 additions & 1 deletion test/readers/iso19115_2/testData/iso19115-2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isotc211.org/2005/gmi
ftp://ftp.ncddc.noaa.gov/pub/Metadata/Online_ISO_Training/Intro_to_ISO/schemas/ISObio/schema.xsd">

<gmd:fileIdentifier>
<gco:CharacterString>ISO19115-2-ID-123456</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:parentIdentifier>
<gco:CharacterString>ISO19115-2-ID-123456-parent</gco:CharacterString>
</gmd:parentIdentifier>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
Expand Down
15 changes: 14 additions & 1 deletion test/translator/tc_iso19115_2_to_dcatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
require 'adiwg/mdtranslator'
require 'adiwg/mdtranslator/readers/iso19115_2/modules/module_iso19115_2'
require 'adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us'
require 'debug'

# these tests are organized according to how data is processed in
# the dcat_us writer lib/adiwg/mdtranslator/writers/dcat_us/sections/dcat_us_dcat_us.rb
Expand Down Expand Up @@ -93,4 +92,18 @@ def test_theme
res = dcatusNS.build(@@intMetadata)
assert_equal('biota farming', res)
end

def test_identifier
dcatusNS = ADIWG::Mdtranslator::Writers::Dcat_us::Identifier
res = dcatusNS.build(@@intMetadata)

assert_equal('ISO19115-2-ID-123456', res)
end

def test_is_part_of
dcatusNS = ADIWG::Mdtranslator::Writers::Dcat_us::IsPartOf
res = dcatusNS.build(@@intMetadata)

assert_equal('ISO19115-2-ID-123456-parent', res)
end
end
2 changes: 1 addition & 1 deletion test/translator/tc_iso19115_3_to_dcatus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_identifier_translate
dcatusNS = ADIWG::Mdtranslator::Writers::Dcat_us::Identifier
res = dcatusNS.build(@@intMetadata)

assert_equal('http://dx.doi.org/10.5066/F7DV1H10', res)
assert_equal('57d97341e4b090824ffb0e6f', res)
rshewitt marked this conversation as resolved.
Show resolved Hide resolved
end

def test_distribution_translate
Expand Down
7 changes: 6 additions & 1 deletion test/translator/testData/iso19115-2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isotc211.org/2005/gmi
ftp://ftp.ncddc.noaa.gov/pub/Metadata/Online_ISO_Training/Intro_to_ISO/schemas/ISObio/schema.xsd">

<gmd:fileIdentifier>
<gco:CharacterString>ISO19115-2-ID-123456</gco:CharacterString>
</gmd:fileIdentifier>
<gmd:parentIdentifier>
<gco:CharacterString>ISO19115-2-ID-123456-parent</gco:CharacterString>
</gmd:parentIdentifier>
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
Expand Down
2 changes: 1 addition & 1 deletion test/translator/testData/iso19115-3-to-dcatus.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"@type":"dcat:Dataset","title":"Spatial data: A large-scale database of modeled contemporary and future water temperature data for 10,774 Michigan, Minnesota and Wisconsin Lakes","description":"Climate change has been shown to influence lake temperatures globally. To better understand the diversity of lake responses to climate change and give managers tools to manage individual lakes, we modelled daily water temperature profiles for 10,774 lakes in Michigan, Minnesota and Wisconsin for contemporary (1979-2015) and future (2020-2040 and 2080-2100) time periods with climate models based on the Representative Concentration Pathway 8.5, the worst-case emission scenario.","keyword":["water","temperate lakes","reservoirs","modeling","climate change","thermal profiles","environment","inlandWaters","007","012","Illinois","Indiana","Iowa","Michigan","Minnesota","South Dakota","Wisconsin","United States","US","Illinois","IL","Indiana","IN","Iowa","IA","Michigan","MI","Minnesota","MN","South Dakota","SD","Wisconsin","WI","Northeast CSC","Rivers, Streams and Lakes","Fish","Climate and Ecosystem Modeling"],"modified":"2017-04-06T20:04:58+00:00","publisher":{"@type":"org:Organization","name":"U.S. Geological Survey - ScienceBase"},"contactPoint":{"@type":"vcard:Contact","fn":"Robert G Test","hasEmail":"[email protected]"},"identifier":"http://dx.doi.org/10.5066/F7DV1H10","accessLevel":"non-public","bureauCode":[],"programCode":[],"distribution":[{"@type":"dcat:Distribution","description":"distribution description","downloadURL":"https://distributiontransfer.com/onlineresource.png","mediaType":"format specification","title":"name test 123"}],"license":"MD ID common constraint licence title","rights":"this is a releasability statement. it's important topSecret superSecret","spatial":"-83.0573307815185,41.7553570685206,-96.8589114267623,48.7289513243629","temporal":"1980-01-01T00:00:00+00:00/1995-12-31T00:00:00+00:00","issued":"2016-09-14T15:56:49+00:00","accrualPeriodicity":"R/P2M or R/P0.5M","language":["eng","test_lang_code","test_lang_code2"],"theme":"United States US Illinois IL Indiana IN Iowa IA Michigan MI Minnesota MN South Dakota SD Wisconsin WI","references":"http://resource.associated.org/10/F7DV1H10,http://as0d1028h3.associated.org/10/F7DV1H10,http://dx.doi.org/10.5066/F7DV1H10,http://additional.doc/10/F7DV1H10,http://additional.doc/56/data.json","landingPage":"http://dx.doi.org/10.5066/F7DV1H10","isPartOf":"http://resource.associated.org/10/F7DV1H10","systemOfRecords":"http://as0d1028h3.associated.org/10/F7DV1H10","primaryITInvestmentUII":"57d97341e4b090824ffb0e6f","describedBy":"http://test.something.org/10/F7DV1H10","describedByType":"https"}
{"@type":"dcat:Dataset","title":"Spatial data: A large-scale database of modeled contemporary and future water temperature data for 10,774 Michigan, Minnesota and Wisconsin Lakes","description":"Climate change has been shown to influence lake temperatures globally. To better understand the diversity of lake responses to climate change and give managers tools to manage individual lakes, we modelled daily water temperature profiles for 10,774 lakes in Michigan, Minnesota and Wisconsin for contemporary (1979-2015) and future (2020-2040 and 2080-2100) time periods with climate models based on the Representative Concentration Pathway 8.5, the worst-case emission scenario.","keyword":["water","temperate lakes","reservoirs","modeling","climate change","thermal profiles","environment","inlandWaters","007","012","Illinois","Indiana","Iowa","Michigan","Minnesota","South Dakota","Wisconsin","United States","US","Illinois","IL","Indiana","IN","Iowa","IA","Michigan","MI","Minnesota","MN","South Dakota","SD","Wisconsin","WI","Northeast CSC","Rivers, Streams and Lakes","Fish","Climate and Ecosystem Modeling"],"modified":"2017-04-06T20:04:58+00:00","publisher":{"@type":"org:Organization","name":"U.S. Geological Survey - ScienceBase"},"contactPoint":{"@type":"vcard:Contact","fn":"Robert G Test","hasEmail":"[email protected]"},"identifier":"57d97341e4b090824ffb0e6f","accessLevel":"non-public","bureauCode":[],"programCode":[],"distribution":[{"@type":"dcat:Distribution","description":"distribution description","downloadURL":"https://distributiontransfer.com/onlineresource.png","mediaType":"format specification","title":"name test 123"}],"license":"MD ID common constraint licence title","rights":"this is a releasability statement. it's important topSecret superSecret","spatial":"-83.0573307815185,41.7553570685206,-96.8589114267623,48.7289513243629","temporal":"1980-01-01T00:00:00+00:00/1995-12-31T00:00:00+00:00","issued":"2016-09-14T15:56:49+00:00","accrualPeriodicity":"R/P2M or R/P0.5M","language":["eng","test_lang_code","test_lang_code2"],"theme":"United States US Illinois IL Indiana IN Iowa IA Michigan MI Minnesota MN South Dakota SD Wisconsin WI","references":"http://resource.associated.org/10/F7DV1H10,http://as0d1028h3.associated.org/10/F7DV1H10,http://dx.doi.org/10.5066/F7DV1H10,http://additional.doc/10/F7DV1H10,http://additional.doc/56/data.json","landingPage":"http://dx.doi.org/10.5066/F7DV1H10","isPartOf":"http://resource.associated.org/10/F7DV1H10","systemOfRecords":"http://as0d1028h3.associated.org/10/F7DV1H10","primaryITInvestmentUII":"57d97341e4b090824ffb0e6f","describedBy":"http://test.something.org/10/F7DV1H10","describedByType":"https"}
rshewitt marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 12 additions & 0 deletions test/writers/dcat_us/tc_dcat_us_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TestWriterDcatUsIdentifier < TestWriterDcatUsParent
# get input JSON for test
@@jsonIn = TestWriterDcatUsParent.getJson('identifier.json')
@@jsonIn2 = TestWriterDcatUsParent.getJson('identifier2.json')
@@jsonIn3 = TestWriterDcatUsParent.getJson('identifier3.json')

def test_identifier_namespace
metadata = ADIWG::Mdtranslator.translate(
Expand All @@ -31,4 +32,15 @@ def test_identifier_url
assert_equal 'http://myOnlineResource-doi.com', got
end

def test_identifier_metadataInfo
metadata = ADIWG::Mdtranslator.translate(
file: @@jsonIn3, reader: 'mdJson', validate: 'normal',
writer: 'dcat_us', showAllTags: false)

hJsonOut = JSON.parse(metadata[:writerOutput])
got = hJsonOut['identifier']

assert_equal 'myMetadataIdentifierID', got
end

end
5 changes: 0 additions & 5 deletions test/writers/dcat_us/testData/identifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
],
"metadata": {
"metadataInfo": {
"metadataIdentifier": {
"identifier": "myMetadataIdentifierID",
"namespace": "gov.sciencebase.catalog",
"description": "metadata identifier"
},
"metadataContact": [
{
"role": "metadataContact",
Expand Down
5 changes: 0 additions & 5 deletions test/writers/dcat_us/testData/identifier2.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
],
"metadata": {
"metadataInfo": {
"metadataIdentifier": {
"identifier": "myMetadataIdentifierID",
"namespace": "gov.sciencebase.catalog",
"description": "metadata identifier"
},
"metadataContact": [
{
"role": "metadataContact",
Expand Down
89 changes: 89 additions & 0 deletions test/writers/dcat_us/testData/identifier3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"schema": {
"name": "mdJson",
"version": "2.0.0"
},
"contact": [
{
"contactId": "CID001",
"isOrganization": false,
"name": "Person 001"
}
],
"metadata": {
"metadataInfo": {
"metadataIdentifier": {
"identifier": "myMetadataIdentifierID",
"namespace": "gov.sciencebase.catalog",
"description": "metadata identifier"
},
"metadataContact": [
{
"role": "metadataContact",
"party": [
{
"contactId": "CID001"
}
]
}
]
},
"resourceInfo": {
"resourceType": [
{
"type": "type",
"name": "name"
}
],
"citation": {
"title": "myCitationTitle",
"identifier": [
{
"identifier": "myDoiIdentifier0",
"namespace": "ISBN",
"description": "myDescription0"
},
{
"identifier": "myIdentifier1",
"namespace": "mySchema1",
"description": "myDescription1"
},
{
"identifier": "myIdentifier1",
"namespace": "mySchema1",
"description": "myDescription1"
},
{
"identifier": "myIdentifier0",
"namespace": "mySchema0",
"description": "myDescription1"
}
],
"onlineResource": [
{
"uri": "http://myOnlineResource-doi.com"
}
]
},
"abstract": "myBody",
"status": [
"status"
],
"pointOfContact": [
{
"role": "pointOfContact",
"party": [
{
"contactId": "CID001"
}
]
}
],
"defaultResourceLocale": {
"language": "eng",
"country": "USA",
"characterSet": "UTF-8"
}
}
}
}