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

Merge Dev #4

Merged
merged 3 commits into from
Dec 20, 2014
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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.project
/resources/json/mdcodes.json
/resources/json
*.gem
*.rbc
.bundle
Expand All @@ -15,10 +15,10 @@ lib/bundler/man
pkg
rdoc
spec/reports
test/dev.rb
test/tmp
test/version_tmp
tmp
dev
*.bundle
*.so
*.o
Expand Down
49 changes: 33 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[![Build Status](https://travis-ci.org/adiwg/mdCodes.svg)](https://travis-ci.org/adiwg/mdCodes)
[![Gem Version](https://badge.fury.io/rb/adiwg-mdcodes.svg)](http://badge.fury.io/rb/adiwg-mdcodes)

# Mdcodes
# mdCodes

adiwg-mdcodes provides code lists in hash or JSON formats for loading of mdEditor and other metadata
tools that use the adiwg-json-schema. The code lists include all ISO 19115-2 and ISO 19115-1 codes plus
supplemental codes added NGDC and ADIwg.
mdCodes provides code lists in hash or JSON formats for loading of mdEditor and other metadata
tools that use the ADIwg [mdJson-schemas](https://github.com/adiwg/mdJson-schemas). The code lists
include all ISO 19115-2 and ISO 19115-1 codes plus supplemental codes added by NGDC and ADIwg. The
code lists may be accessed in Ruby using the gem. Alternatively, JSON may be generated from the YAML
using [Grunt](http://gruntjs.com/getting-started). See the following for instructions.

## Installation
## Ruby

The adiwg-mdcodes gem provides code lists in Ruby hash or JSON formats.

### Installation

Add this line to your application's Gemfile:

Expand All @@ -22,29 +28,40 @@ Or install it yourself as:
$ gem install adiwg-mdcodes


## Methods
### Methods

### getYamlPath
> returns the path to the YAML file of code lists.
#### getYamlPath
> returns the path to the 'resources' folder containing codelist files in YAML format'.

### getCodeLists( returnFormat )
> returns all code lists with all code list data
#### getAllCodelistsDetail( returnFormat )
> returns all code lists with all codelist detail
> returnFormat = \[__hash__ | json] (string)

### getCodeList( codeListName, returnFormat )
> returns a single code list with all code list data
#### getCodelistDetail( codeListName, returnFormat )
> returns a single codelist with all code list detail
> codeListName = name of code list to return (string)
> returnFormat = \[ __hash__ | json ] (string)

### getCodeNames( returnFormat )
> returns all code lists with only the code list item names
#### getAllStaticCodelists( returnFormat )
> returns all static codelists with only the codelist item names
> returnFormat = \[__hash__ | json] (string)

### getCodeName( codeListName, returnFormat )
> returns a single code list with only the code list item names
#### getStaticCodelist( codeListName, returnFormat )
> returns a single static codelist with only the codelist item names
> codeListName = name of code list to return (string)
> returnFormat = \[__hash__ | json] (string)

##Grunt

Generate JSON verions of the code lists using Grunt.

**Note**: These instructions assume that [npm](https://docs.npmjs.com/) and [Grunt](http://gruntjs.com/getting-started) are already installed. The generated
files are not tracked by git.

1. Change to the project's root directory.
2. Install project dependencies with ```npm install```.
3. Generate the JSON code lists with ```grunt```.
4. The JSON is written to the *resources/json* directory.

## Contributing

Expand Down
18 changes: 18 additions & 0 deletions dev/dev.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# uncomment next 2 lines to run code (not gem) ....
lib = File.expand_path('lib')
res = File.expand_path('resources')
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
$LOAD_PATH.unshift(res)

require 'adiwg-mdcodes'
require 'json'
require 'pp'

# codelists = ADIWG::Mdcodes.getAllCodeistsDetail
# codelists = ADIWG::Mdcodes.getCodelistDetail('iso_characterSet')
# codelists = ADIWG::Mdcodes.getAllStaticCodelists
# codelists = ADIWG::Mdcodes.getStaticCodelist('iso_characterSet')
codelists = ADIWG::Mdcodes.getStaticCodelist('characterSet')
pp codelists
# puts codelists.to_json
95 changes: 54 additions & 41 deletions lib/adiwg/mdcodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,92 @@
# Josh Bradley 2014-11-07 moved resources directory outside lib, add getYamlPath
# Stan Smith 2014-11-10 added support for JSON returns
# Stan Smith 2014-11-10 added README.md text
# Stan Smith 2014-12-18 split codelists into individual YAML file

# add main directories to load_path

require 'yaml'
require 'json'

module ADIWG

module Mdcodes
# return the path to yaml file.

# return the path to yaml files.
def self.getYamlPath
File.join(File.dirname(__FILE__),'..','..','resources','mdcodes.yml')
File.join(File.dirname(__FILE__),'..','..','resources')
end

# read the yml file into ruby
def self.getCodeLists(format='hash')
file = getYamlPath
codes = YAML.load_file(file)
# return all codelists with full details
def self.getAllCodeistsDetail(format='hash')
path = getYamlPath + '/*.yml'
hCodeLists = {}
Dir.glob(path) do |item|
hCodeList = YAML.load_file(item)
hCodeLists[hCodeList['codelistName']] = hCodeList
end
if format == 'json'
return codes.to_json
return hCodeLists.to_json
else
return codes
return hCodeLists
end
end

# return a single code list
def self.getCodeList(codeList, format='hash')
codeLists = getCodeLists
hCodeList = {}
hCodeList[codeList] = codeLists[codeList]
# return a single codelist with full details
def self.getCodelistDetail(codeList, format='hash')
file = File.join(getYamlPath, codeList + '.yml')
if File.exist?(file)
hCodeList = YAML.load_file(file)
else
return nil
end
if format == 'json'
return hCodeList.to_json
else
return hCodeList
end
end

# return only code names
def self.getCodeNames(format='hash')
codeLists = getCodeLists
hCodeNames = {}
# return all static codelist with only the item names
def self.getAllStaticCodelists(format='hash')
codeLists = getAllCodeistsDetail
hCodeLists = {}
codeLists.each do |key, value|
aItems = value['items']
aList = []
aItems.each do |item|
aList << item['codeName']
if value['codelistType'] == 'staticList'
aItems = value['codelist']
aList = []
aItems.each do |item|
aList << item['codeName']
end
hCodeLists[key] = aList
end
hCodeNames[key] = aList
end
end
if format == 'json'
return hCodeNames.to_json
hCodeLists.to_json if format == 'json'
else
return hCodeNames
return hCodeLists
end
end

# return a single code name list
def self.getCodeName(codeList, format='hash')
hCodeList = getCodeList(codeList)
hCodeNames = {}
aItems = hCodeList[codeList]['items']
aList = []
aItems.each do |item|
aList << item['codeName']
# return a single static codelist with only the item names
def self.getStaticCodelist(codeList, format='hash')
hCodeList = getCodelistDetail(codeList)
if hCodeList
hCodeNames = {}
aItems = hCodeList['codelist']
aList = []
aItems.each do |item|
aList << item['codeName']
end
hCodeNames[hCodeList['codelistName']] = aList
if format == 'json'
return hCodeNames.to_json
else
return hCodeNames
end
else
return nil
end
hCodeNames[codeList] = aList
if format == 'json'
return hCodeNames.to_json
else
return hCodeNames
end
end

end

end
3 changes: 2 additions & 1 deletion lib/adiwg/mdcodes/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
# ... moved resources directory outside of lib
# 0.2.1 2014-11-10 added support for JSON returns
# 0.3.0 2014-11-18 added administrator to role codelist
# 0.4.0 2014-12-18 split codelists into individual YAML file

module ADIWG

module Mdcodes
VERSION = "0.3.0"
VERSION = "0.4.0"
end

end
24 changes: 24 additions & 0 deletions resources/iso_associationType.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# mdJson codelists
# base codelist for ISO 19115-2, 19115-1
# extended for ADIwg

codelistType: "staticList"
codelistName: "iso_associationType"
source: "ISO"
sourceName: "DS_AssociationTypeCode"
extensible: true
description: "justification for the correlation of two resources (datasets or projects)"
codelist:
- {code: "001", codeName: crossReference, description: "reference from one resource (dataset or project) to another"}
- {code: "002", codeName: largerWorkCitation, description: "reference to a master resource (dataset or project) of which this one is a part"}
- {code: "003", codeName: partOfSeamlessDatabase, description: "part of the same structured set of data held in a computer"}
- {code: "004", codeName: source, description: "mapping and charting information from which the dataset content originates"}
- {code: "005", codeName: stereoMate, description: "part of a set of imagery that when used together, provides three-dimensional images"}
- {code: "006", codeName: isComposedOf, description: "reference to resources (datasets or projects) that are parts of this resource"}
- {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."}
- {code: "008", codeName: series, description: "associated through a common heritage such as produced to a common product specification"}
- {code: "009", codeName: dependency, description: "associated through a dependency"}
- {code: "010", codeName: revisionOf, description: "resource is a revision of associated resource"}
- {code: "adiwg001", codeName: projectProduct, description: "products developed as deliverables of a project or program"}
- {code: "adiwg002", codeName: supplementalResource, description: "supplemental resource"}
39 changes: 39 additions & 0 deletions resources/iso_characterSet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# mdJson codelists
# base codelist for ISO 19115-2, 19115-1

codelistType: "staticList"
codelistName: "iso_characterSet"
source: "ISO"
sourceName: "MD_CharacterSetCode"
extensible: true
description: "name of the character coding standard used in the resource"
codelist:
- {code: "001", codeName: ucs2, description: "16-bit fixed size Universal Character Set, based on ISO/IEC 10646"}
- {code: "002", codeName: ucs4, description: "32-bit fixed size Universal Character Set, based on ISO/IEC 10646"}
- {code: "003", codeName: utf7, description: "7-bit variable size UCS Transfer Format, based on ISO/IEC 10646"}
- {code: "004", codeName: utf8, description: "8-bit variable size UCS Transfer Format, based on ISO/IEC 10646"}
- {code: "005", codeName: utf16, description: "16-bit variable size UCS Transfer Format, based on ISO/IEC 10646"}
- {code: "006", codeName: 8859part1, description: "ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic character sets - Part 1 : Latin alphabet No.1"}
- {code: "007", codeName: 8859part2, description: "ISO/IEC 8859-2, Information technology - 8-bit single byte coded graphic character sets - Part 2 : Latin alphabet No.2"}
- {code: "008", codeName: 8859part3, description: "ISO/IEC 8859-3, Information technology - 8-bit single byte coded graphic character sets - Part 3 : Latin alphabet No.3"}
- {code: "009", codeName: 8859part4, description: "ISO/IEC 8859-4, Information technology - 8-bit single byte coded graphic character sets - Part 4 : Latin alphabet No.4"}
- {code: "010", codeName: 8859part5, description: "ISO/IEC 8859-5, Information technology - 8-bit single byte coded graphic character sets - Part 5 : Latin/Cyrillic alphabet"}
- {code: "011", codeName: 8859part6, description: "ISO/IEC 8859-6, Information technology - 8-bit single byte coded graphic character sets - Part 6 : Latin/Arabic alphabet"}
- {code: "012", codeName: 8859part7, description: "ISO/IEC 8859-7, Information technology - 8-bit single byte coded graphic character sets - Part 7 : Latin/Greek alphabet"}
- {code: "013", codeName: 8859part8, description: "ISO/IEC 8859-8, Information technology - 8-bit single byte coded graphic character sets - Part 8 : Latin/Hebrew alphabet"}
- {code: "014", codeName: 8859part9, description: "ISO/IEC 8859-9, Information technology - 8-bit single byte coded graphic character sets - Part 9 : Latin alphabet No.5"}
- {code: "015", codeName: 8859part10, description: "ISO/IEC 8859-10, Information technology - 8-bit single byte coded graphic character sets - Part 10 : Latin alphabet No.6"}
- {code: "016", codeName: 8859part11, description: "ISO/IEC 8859-11, Information technology - 8-bit single byte coded graphic character sets - Part 11 : Latin/Thai alphabet"}
- {code: "018", codeName: 8859part13, description: "ISO/IEC 8859-13, Information technology - 8-bit single byte coded graphic character sets - Part 13 : Latin alphabet No.7"}
- {code: "019", codeName: 8859part14, description: "ISO/IEC 8859-14, Information technology - 8-bit single byte coded graphic character sets - Part 14 : Latin alphabet No.8 (Celtic)"}
- {code: "020", codeName: 8859part15, description: "ISO/IEC 8859-15, Information technology - 8-bit single byte coded graphic character sets - Part 15 : Latin alphabet No.9"}
- {code: "021", codeName: 8859part16, description: "ISO/IEC 8859-16, Information technology - 8-bit single byte coded graphic character sets - Part 16 : Latin alphabet No.10"}
- {code: "022", codeName: jis, description: "japanese code set used for electronic transmission"}
- {code: "023", codeName: shiftJIS, description: "japanese code set used on MS-DOS machines"}
- {code: "024", codeName: eucJP, description: "japanese code set used on UNIX based machines"}
- {code: "025", codeName: usAscii, description: "United States ASCII code set (ISO 646 US)"}
- {code: "026", codeName: ebcdic, description: "IBM mainframe code set"}
- {code: "027", codeName: ecuKR, description: "Korean code set"}
- {code: "028", codeName: big5, description: "traditional Chinese code set used in Taiwan, Hong Kong of China and other areas"}
- {code: "029", codeName: GB2312, description: "simplified Chinese code set"}
20 changes: 20 additions & 0 deletions resources/iso_classification.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# mdJson codelists
# base codelist for ISO 19115-2, 19115-1

codelistType: "staticList"
codelistName: "iso_classification"
source: "ISO"
sourceName: "MD_ClassificationCode"
extensible: true
description: "name of the handling restrictions on the dataset"
codelist:
- {code: "001", codeName: unclassified, description: "available for general disclosure"}
- {code: "002", codeName: restricted, description: "not for general disclosure"}
- {code: "003", codeName: confidential, description: "available for someone who can be entrusted with information"}
- {code: "004", codeName: secret, description: "kept or meant to be kept private, unknown, or hidden from all but a select group of people"}
- {code: "005", codeName: topSecret, description: "of the highest secrecy"}
- {code: "006", codeName: sensitiveButUnclassified, description: "although unclassified, requires strict controls over its distribution"}
- {code: "007", codeName: forOfficialUseOnly, description: "unclassified information that is to be used only for official purposes determined by the designating body"}
- {code: "008", codeName: protected, description: "compromise of the information could cause damage"}
- {code: "009", codeName: limitedDistribution, description: "dissemination limited by designating body"}
27 changes: 27 additions & 0 deletions resources/iso_dataType.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# mdJson codelists
# base codelist for ISO 19115-2, 19115-1

codelistType: "staticList"
codelistName: iso_"dataType"
source: "ISO"
sourceName: "MD_DatatypeCode"
extensible: true
description: "datatype of element or entity"
codelist:
- {code: "001", codeName: class, description: "descriptor of a set of objects that share the same attributes, operations, methods, relationships, and behavior"}
- {code: "002", codeName: codelist, description: "flexible enumeration useful for expressing a long list of values, can be extended"}
- {code: "003", codeName: enumerations, description: "data type whose instances form a list of named literal values, not extendable"}
- {code: "004", codeName: codelistElement, description: "permissible value for a codelist or enumeration"}
- {code: "005", codeName: abstractClass, description: "class that cannot be directly instantiated"}
- {code: "006", codeName: aggregateClass, description: "class that is composed of classes it is connected to by an aggregate relationship"}
- {code: "007", codeName: specifiedClass, description: "subclass that may be substituted for its superclass"}
- {code: "008", codeName: datatypeClass, description: "class with few or no operations whose primary purpose is to hold the abstract state of another class for transmittal, storage, encoding or persistent storage"}
- {code: "009", codeName: interfaceClass, description: "named set of operations that characterize the behavior of an element"}
- {code: "010", codeName: unionClass, description: "class describing a selection of one of the specified types"}
- {code: "011", codeName: metaClass, description: "class whose instances are classes"}
- {code: "012", codeName: typeClass, description: "class used for specification of a domain of instances (objects), together with the operations applicable to the objects. A type may have attributes and associations"}
- {code: "013", codeName: characterString, description: "free text field"}
- {code: "014", codeName: integer, description: "numeric filed"}
- {code: "015", codeName: association, description: "semantic relationship between two classes that involves connections among their instances"}
- {code: "016", codeName: typeClass, description: "class used for specification of a domain of instances (objects), together with the operations applicable to the objects. A type may have attributes and associations"}
Loading