adiwg-mdcodes 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/adiwg/mdcodes.rb +90 -80
- data/lib/adiwg/mdcodes/version.rb +3 -2
- data/package.json +1 -1
- data/resources/adiwg_metadataRepository.yml +1 -0
- data/resources/iso_associationType.yml +21 -16
- data/test/tc_mdcodes.rb +63 -41
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a40a9ab950a81d61db62806c5fb9a799926dbf83
|
4
|
+
data.tar.gz: a9ea92833aaa1c2f5bca91ffeda9db5bbab39757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e6f7d5214af91979ed6acae03193be84013fae9005451991022830a2f18908e17030bd724e299f159f0a6b79a100b63594f6cb81f411dc592c820f092212d2
|
7
|
+
data.tar.gz: 70fa5577ac472dfeac7091c837e5cc3d6c9dea642c2dcb4cc16886403179fd274f395be523282329ab5de8f912c4ad66d657351b4537842a761ea558b5a20ad9
|
data/lib/adiwg/mdcodes.rb
CHANGED
@@ -1,99 +1,109 @@
|
|
1
|
-
# Mdcodes - ADIwg
|
2
|
-
# ...
|
3
|
-
# ... the Mdcodes module has methods to access and return
|
1
|
+
# Mdcodes - ADIwg codelists to be used with adiwgJson and mdEditor
|
2
|
+
# ... codelists are maintained in a YAML file 'mdCodes.yml'
|
3
|
+
# ... the Mdcodes module has methods to access and return codelists
|
4
4
|
|
5
5
|
# History:
|
6
|
+
# Stan Smith 2017-08-08 add deprecated parameter to codelists
|
7
|
+
# Stan Smith 2014-12-18 split codelists into individual YAML file
|
8
|
+
# Stan Smith 2014-11-10 added README.md text
|
9
|
+
# Stan Smith 2014-11-10 added support for JSON returns
|
10
|
+
# Josh Bradley 2014-11-07 moved resources directory outside lib, add getYamlPath
|
11
|
+
# Stan Smith 2014-11-07 add methods to return only codeNames
|
6
12
|
# Stan Smith 2014-11-07 original script
|
7
|
-
# Stan Smith 2014-11-07 add methods to return only codeNames
|
8
|
-
# Josh Bradley 2014-11-07 moved resources directory outside lib, add getYamlPath
|
9
|
-
# Stan Smith 2014-11-10 added support for JSON returns
|
10
|
-
# Stan Smith 2014-11-10 added README.md text
|
11
|
-
# Stan Smith 2014-12-18 split codelists into individual YAML file
|
12
|
-
|
13
|
-
# add main directories to load_path
|
14
13
|
|
15
14
|
require 'yaml'
|
16
15
|
require 'json'
|
17
16
|
|
18
17
|
module ADIWG
|
19
|
-
|
18
|
+
module Mdcodes
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
# return the path to yaml files.
|
21
|
+
def self.getYamlPath
|
22
|
+
File.join(File.dirname(File.expand_path(__FILE__)), '..', '..', 'resources')
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
# return all codelists with all elements
|
26
|
+
def self.getAllCodelistsDetail(format='hash', showDeprecated=false)
|
27
|
+
path = getYamlPath + '/*.yml'
|
28
|
+
hCodelists = {}
|
29
|
+
Dir.glob(path) do |item|
|
30
|
+
hCodelist = YAML.load_file(item)
|
31
|
+
hCodelists[hCodelist['codelistName']] = hCodelist
|
32
|
+
end
|
33
|
+
unless showDeprecated
|
34
|
+
hCodelists.each do |key, value|
|
35
|
+
aKeepItems = []
|
36
|
+
value['codelist'].each do |item|
|
37
|
+
if item.has_key?('deprecated')
|
38
|
+
unless item['deprecated']
|
39
|
+
aKeepItems << item
|
40
|
+
end
|
41
|
+
else
|
42
|
+
aKeepItems << item
|
43
|
+
end
|
44
|
+
value['codelist'] = aKeepItems
|
45
|
+
end
|
33
46
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
47
|
+
end
|
48
|
+
return hCodelists.to_json if format == 'json'
|
49
|
+
return hCodelists
|
50
|
+
end
|
40
51
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
52
|
+
# return a single codelist with all elements
|
53
|
+
def self.getCodelistDetail(codelist, format='hash', showDeprecated=false)
|
54
|
+
file = File.join(getYamlPath, codelist + '.yml')
|
55
|
+
if File.exist?(file)
|
56
|
+
hCodelist = YAML.load_file(file)
|
57
|
+
unless showDeprecated
|
58
|
+
aKeepItems = []
|
59
|
+
hCodelist['codelist'].each do |item|
|
60
|
+
if item.has_key?('deprecated')
|
61
|
+
unless item['deprecated']
|
62
|
+
aKeepItems << item
|
63
|
+
end
|
64
|
+
else
|
65
|
+
aKeepItems << item
|
66
|
+
end
|
67
|
+
hCodelist['codelist'] = aKeepItems
|
68
|
+
end
|
48
69
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
70
|
+
else
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
return hCodelist.to_json if format == 'json'
|
74
|
+
return hCodelist
|
75
|
+
end
|
55
76
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
aItems.each do |item|
|
65
|
-
aList << item['codeName']
|
66
|
-
end
|
67
|
-
hCodeLists[key] = aList
|
68
|
-
end
|
77
|
+
# return all codelist with only the codeName
|
78
|
+
def self.getAllStaticCodelists(format='hash', showDeprecated=false)
|
79
|
+
hCodelists = {}
|
80
|
+
codelists = getAllCodelistsDetail('hash', showDeprecated)
|
81
|
+
codelists.each do |key, value|
|
82
|
+
aList = []
|
83
|
+
value['codelist'].each do |item|
|
84
|
+
aList << item['codeName']
|
69
85
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
86
|
+
hCodelists[key] = aList
|
87
|
+
end
|
88
|
+
return hCodelists.to_json if format == 'json'
|
89
|
+
return hCodelists
|
90
|
+
end
|
76
91
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
aList << item['codeName']
|
86
|
-
end
|
87
|
-
hCodeNames[hCodeList['codelistName']] = aList
|
88
|
-
if format == 'json'
|
89
|
-
return hCodeNames.to_json
|
90
|
-
else
|
91
|
-
return hCodeNames
|
92
|
-
end
|
93
|
-
else
|
94
|
-
return nil
|
92
|
+
# return a single codelist with only the codeName
|
93
|
+
def self.getStaticCodelist(codelist, format='hash', showDeprecated=false)
|
94
|
+
hCodelist = getCodelistDetail(codelist, 'hash', showDeprecated)
|
95
|
+
unless hCodelist.nil?
|
96
|
+
hCodeNames = {}
|
97
|
+
aList = []
|
98
|
+
hCodelist['codelist'].each do |item|
|
99
|
+
aList << item['codeName']
|
95
100
|
end
|
96
|
-
|
101
|
+
hCodeNames[hCodelist['codelistName']] = aList
|
102
|
+
return hCodeNames.to_json if format == 'json'
|
103
|
+
return hCodeNames
|
104
|
+
end
|
105
|
+
return nil
|
106
|
+
end
|
97
107
|
|
98
|
-
|
108
|
+
end
|
99
109
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# adiwg mdCodes
|
2
2
|
|
3
3
|
# version 2 history
|
4
|
+
# 2.3.0 2017-08-01 added showDeprecated parameter to mdCodes methods
|
5
|
+
# 2.3.0 2017-08-01 change to associationTypes: revised definitions, deprecated some codes
|
4
6
|
# 2.2.0 2017-06-29 added adiwg namespace codelist
|
5
7
|
# 2.1.7 2017-06-08 added scienceBase date codes to dateType
|
6
8
|
# 2.1.6 2017-05-16 added 'isoTopicCategory' to keyword type code list
|
@@ -12,7 +14,6 @@
|
|
12
14
|
# 2.1.0 2016-11-27 added 10 MI codelists
|
13
15
|
|
14
16
|
# version 1 history
|
15
|
-
|
16
17
|
# 0.1.0 2014-11-05 first release
|
17
18
|
# 0.1.1 2014-11-06 added factSheet to scope
|
18
19
|
# 0.2.0 2014-11-07 add option to return only codeNames
|
@@ -29,6 +30,6 @@
|
|
29
30
|
|
30
31
|
module ADIWG
|
31
32
|
module Mdcodes
|
32
|
-
VERSION = "2.
|
33
|
+
VERSION = "2.3.0"
|
33
34
|
end
|
34
35
|
end
|
data/package.json
CHANGED
@@ -12,3 +12,4 @@ codelist:
|
|
12
12
|
- {code: "cdddf5c7-eec4-4e0c-9b54-d75b763a88fc", codeName: data.gov, description: "U.S. Government repository of open data"}
|
13
13
|
- {code: "da0336c4-a8f6-4010-99b3-1b848d14ff2f", codeName: ScienceBase, description: "U.S. Geological Survey repository for data and metadata"}
|
14
14
|
- {code: "b1d2ffbe-0b64-40fe-890a-02c4f0b6b9b4", codeName: ScienceCatalog, description: "U.S. Geological Survey inventory for data and metadata"}
|
15
|
+
- {code: "a791e961-f2d4-4be4-ab3c-1cdf8fd025b9", codeName: LCCScienceCatalog, description: "Repository of Landscape Conservation Cooperative projects and data products."}
|
@@ -10,19 +10,24 @@ sourceName: "DS_AssociationTypeCode"
|
|
10
10
|
extensible: true
|
11
11
|
description: "justification for the correlation of two resources (datasets or projects)"
|
12
12
|
codelist:
|
13
|
-
- {code: "001", codeName: crossReference, description: "
|
14
|
-
- {code: "002", codeName: largerWorkCitation, description: "
|
15
|
-
- {code: "003", codeName: partOfSeamlessDatabase, description: "part of the same structured
|
16
|
-
- {code: "004", codeName: source, description: "mapping and charting information from which the
|
17
|
-
- {code: "005", codeName: stereoMate, description: "part of a set of imagery that when used together
|
18
|
-
- {code: "006", codeName: isComposedOf, description: "
|
19
|
-
- {code: "007", codeName: collectiveTitle, description: "common title for a collection of resources. NOTE Title identifies elements of a series collectively, combined with information about what volumes are available at the source cite."}
|
20
|
-
- {code: "008", codeName: series, description: "associated
|
21
|
-
- {code: "009", codeName: dependency, description: "associated
|
22
|
-
- {code: "010", codeName: revisionOf, description: "resource is a revision of associated resource"}
|
23
|
-
- {code: "adiwg001", codeName: projectProduct, description: "
|
24
|
-
- {code: "adiwg002", codeName: supplementalResource, description: "supplemental resource"}
|
25
|
-
- {code: "adiwg003", codeName: produced, description: "
|
26
|
-
- {code: "adiwg004", codeName: productOf, description: "
|
27
|
-
- {code: "adiwg005", codeName:
|
28
|
-
- {code: "adiwg006", codeName:
|
13
|
+
- {code: "001", codeName: crossReference, description: "the associated resource is a reference to another dataset or project"}
|
14
|
+
- {code: "002", codeName: largerWorkCitation, description: "the associated resource is a citation to a master resource of the main resource"}
|
15
|
+
- {code: "003", codeName: partOfSeamlessDatabase, description: "the associated resource is a part of the same structured dataset as the main resource"}
|
16
|
+
- {code: "004", codeName: source, description: "the associated resource is mapping and charting information from which the main resource content originates"}
|
17
|
+
- {code: "005", codeName: stereoMate, description: "the associated resource is part of a set of imagery that when used together provide three-dimensional images"}
|
18
|
+
- {code: "006", codeName: isComposedOf, description: "the associated resource is a dataset or project that is part of the main resource"}
|
19
|
+
- {code: "007", codeName: collectiveTitle, description: "the associated resource is a common title for a collection of resources. NOTE Title identifies elements of a series collectively, combined with information about what volumes are available at the source cite."}
|
20
|
+
- {code: "008", codeName: series, description: "the associated resource was produced via the same product specifications as the main resource"}
|
21
|
+
- {code: "009", codeName: dependency, description: "the associated resource is dependent on the main resource"}
|
22
|
+
- {code: "010", codeName: revisionOf, description: "the main resource is a revision of the associated resource"}
|
23
|
+
- {code: "adiwg001", codeName: projectProduct, description: "DEPRECATED: use product", deprecated: true}
|
24
|
+
- {code: "adiwg002", codeName: supplementalResource, description: "the associated resource is a supplemental resource to the main resource"}
|
25
|
+
- {code: "adiwg003", codeName: produced, description: "DEPRECATED: use product", deprecated: true}
|
26
|
+
- {code: "adiwg004", codeName: productOf, description: "DEPRECATED: use parentProject", deprecated: true}
|
27
|
+
- {code: "adiwg005", codeName: mainProjectOf, description: "DEPRECATED: use subProject", deprecated: true}
|
28
|
+
- {code: "adiwg006", codeName: subProjectOf, description: "DEPRECATED: use parentProject", deprecated: true}
|
29
|
+
- {code: "adiwg007", codeName: product, description: "the associated resource is a product developed as deliverable of the main resource"}
|
30
|
+
- {code: "adiwg008", codeName: parentProject, description: "the associated resource is a parent project of the main resource"}
|
31
|
+
- {code: "adiwg009", codeName: subProject, description: "the associated resource is sub-project or task of the main resource"}
|
32
|
+
- {code: "adiwg010", codeName: derivativeProduct, description: "the associated resource is product derived from main resource"}
|
33
|
+
- {code: "adiwg011", codeName: alternate, description: "the associated resource is an alternate reference for the main resource"}
|
data/test/tc_mdcodes.rb
CHANGED
@@ -6,49 +6,71 @@
|
|
6
6
|
=end
|
7
7
|
|
8
8
|
require 'minitest/autorun'
|
9
|
-
require File.join(File.dirname(__FILE__),'..','lib', 'adiwg-mdcodes.rb')
|
9
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'adiwg-mdcodes.rb')
|
10
10
|
|
11
11
|
class TestMdcodes < Minitest::Test
|
12
|
-
def test_parseYaml
|
13
|
-
@errors = Array.new
|
14
12
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
def test_parseYaml
|
14
|
+
@errors = Array.new
|
15
|
+
|
16
|
+
path = ADIWG::Mdcodes.getYamlPath
|
17
|
+
Dir["#{File.join(path, '**/*.yml')}"].each do |fname|
|
18
|
+
begin
|
19
|
+
YAML.load_file(fname)
|
20
|
+
rescue Exception
|
21
|
+
@errors << "Could not parse YAML: #{fname}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
assert(@errors.empty?, @errors.join("\n"))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_yamlResourceDir
|
28
|
+
yamlDir = ADIWG::Mdcodes.getYamlPath
|
29
|
+
assert(Dir.exist?(yamlDir), 'Did not find resource Directory.')
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_getAllCodelistsDetail
|
33
|
+
assert_instance_of(Hash, ADIWG::Mdcodes.getAllCodelistsDetail)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_getCodelistDetail
|
37
|
+
yaml = ADIWG::Mdcodes.getAllCodelistsDetail
|
38
|
+
refute_empty(yaml)
|
39
|
+
|
40
|
+
yaml.keys.each do |key|
|
41
|
+
assert_instance_of(Hash, ADIWG::Mdcodes.getCodelistDetail(key), 'Failed to load ' + key)
|
19
42
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_getAllStaticCodelists
|
46
|
+
assert_instance_of(Hash, ADIWG::Mdcodes.getAllStaticCodelists)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_getStaticCodelist
|
50
|
+
yaml = ADIWG::Mdcodes.getAllStaticCodelists
|
51
|
+
refute_empty(yaml)
|
52
|
+
|
53
|
+
yaml.keys.each do |key|
|
54
|
+
assert_instance_of(Hash, ADIWG::Mdcodes.getStaticCodelist(key), 'Failed to load ' + key)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_getStaticCodelist_deprecated
|
59
|
+
yaml = ADIWG::Mdcodes.getStaticCodelist('iso_associationType')
|
60
|
+
yamlDeprecated = ADIWG::Mdcodes.getStaticCodelist('iso_associationType', 'hash', true)
|
61
|
+
|
62
|
+
refute_empty yaml['iso_associationType']
|
63
|
+
refute_empty yamlDeprecated['iso_associationType']
|
64
|
+
assert (yaml['iso_associationType'].length < yamlDeprecated['iso_associationType'].length)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_getAllCodelistsDetail_deprecated
|
68
|
+
yaml = ADIWG::Mdcodes.getAllCodelistsDetail
|
69
|
+
yamlDeprecated = ADIWG::Mdcodes.getAllCodelistsDetail('hash', true)
|
70
|
+
|
71
|
+
refute_empty yaml['iso_associationType']['codelist']
|
72
|
+
refute_empty yamlDeprecated['iso_associationType']['codelist']
|
73
|
+
assert (yaml['iso_associationType']['codelist'].length < yamlDeprecated['iso_associationType']['codelist'].length)
|
74
|
+
end
|
75
|
+
|
54
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adiwg-mdcodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- stansmith907, jlblcc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
162
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.5
|
163
|
+
rubygems_version: 2.4.5
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: adiwg-mdcodes provides code lists for mdJSON.
|