2018-03-15 21:35:09 +00:00
# Mapping Standards
2018-06-11 15:10:07 +00:00
Mapping Standards are declarations of standards of metadata. Once they are available and activated in your repository, you can map the metadata of your collections to them.
2018-03-15 21:35:09 +00:00
## Structure
A Mapping Standard has the following attributes.
### Name
2018-08-09 15:54:05 +00:00
String $name
2018-03-15 21:35:09 +00:00
The name of the Mapping Standard.
2018-06-11 15:10:07 +00:00
### Metadata
2018-03-15 21:35:09 +00:00
2018-08-09 15:54:05 +00:00
Array or false $metadata
2018-06-11 15:10:07 +00:00
A list of metadata, terms or attributes that this mapping have. These are the element you will be able to map your Collection's Metadata.
2018-03-15 21:35:09 +00:00
2018-06-11 15:10:07 +00:00
Each metadatum has the following attributes:
2018-03-15 21:35:09 +00:00
2018-08-09 15:54:05 +00:00
* slug - The metadatum name, that refers to the name of the attribute in the origin vocabulary or ontology (e.g. title)
* label - The human readable name
2018-03-15 21:35:09 +00:00
* URI - The URI of this term/attribute in the origin Ontoloy/Vocabulary
2018-08-09 15:54:05 +00:00
* metadata_type - The prefered type for the metadatum
2018-03-15 21:35:09 +00:00
2018-08-09 15:54:05 +00:00
Array of:
```
['slug'] => [
'URI' => 'http://...',
'label' => 'Label',
'metadata_type' => 'date',
]
```
2018-06-11 15:10:07 +00:00
### Allow additional custom metadata
2018-03-15 21:35:09 +00:00
2018-08-09 15:54:05 +00:00
Boolean $allow_extra_metadata
2018-06-11 15:10:07 +00:00
Boolen indicating wether this mapping allows additional custom metadata to be added.
2018-03-15 21:35:09 +00:00
### Context URL / Vocab URL
2018-08-09 15:54:05 +00:00
String $context_url
2018-03-15 21:35:09 +00:00
The URL of the Ontology or vocabulary. For example `http://schema.org` or `http://dublincore.org/documents/dcmi-terms/`
### Type
2018-08-16 14:38:51 +00:00
String $type
2018-08-09 15:54:05 +00:00
The Class of the ontology that this mapping refers to. For example `CreativeWork` , which is a class of Schema.org, if applied
2018-08-16 14:38:51 +00:00
### Header
String $header
The header to be append to API answer, like for Dublin Core, if we need to add RDF to xml header when using Dublin Core as mapper, so:
```
public $header = '<?xml version="1.0"?> <!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"> < rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc = "http://purl.org/dc/elements/1.1/" > < / rdf:RDF > ';
```
### Prefix
String $prefix
The optional prefix for the key labels, like ```dc:``` for Dublin Core in XML exposing.
2018-08-09 15:54:05 +00:00
### Registering a new mapper
For register a new mapper, the action need to be added to `tainacan-register-exposer-mappers` hook, like:
```
function myNewMapper($exposers) {
$exposers->register_exposer_mapper('Tainacan\Exposers\Mappers\NewMapper');
}
add_action('tainacan-register-exposer-mappers', 'myNewMapper');
```
2018-03-15 21:35:09 +00:00
## Examples
```
2018-08-09 15:54:05 +00:00
namespace Tainacan\Exposers\Mappers;
/**
* Support Dublin Core Mapping
* http://purl.org/dc/elements/1.1/
*
*/
class Dublin_Core extends Mapper {
public $slug = 'dublin-core';
public $name = 'Dublin Core';
public $allow_extra_metadata = true;
public $context_url = 'http://dublincore.org/documents/dcmi-terms/';
public $header = '<?xml version="1.0"?> <!DOCTYPE rdf:RDF SYSTEM "http://dublincore.org/2000/12/01-dcmes-xml-dtd.dtd"> < rdf:RDF xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc = "http://purl.org/dc/elements/1.1/" > < / rdf:RDF > ';
public $prefix = 'dc:';
public $metadata = [
'contributor' => [
'URI' => 'http://purl.org/dc/elements/1.1/contributor',
'label' => 'Contributor'
],
'coverage' => [
'URI' => 'http://purl.org/dc/elements/1.1/coverage',
'label' => 'Coverage'
],
'creator' => [
'URI' => 'http://purl.org/dc/elements/1.1/creator',
'label' => 'Creator'
],
...
2018-03-15 21:35:09 +00:00
```
```
2018-08-09 15:54:05 +00:00
namespace Tainacan\Exposers\Mappers;
class CreativeWorks extends Mapper {
public $name = 'Schema.org Creative Works';
public $slug = 'creative-works';
public $metadata = [
'name' => [
2018-03-15 21:35:09 +00:00
'label': 'Name',
'URI': 'http://schema.org/name'
2018-08-09 15:54:05 +00:00
],
'alternativeHeadline' => [
2018-03-15 21:35:09 +00:00
'label': 'Alternative Headline',
'URI': 'http://schema.org/alternativeHeadline'
2018-08-09 15:54:05 +00:00
],
2018-03-15 21:35:09 +00:00
... And so on...
2018-08-09 15:54:05 +00:00
],
public $allow_extra_fields = false;
public $context_url = 'http://schema.org';
public $type = 'CreativeWork';
2018-03-15 21:35:09 +00:00
}
```