Title: | Ecological Metadata as Linked Data |
---|---|
Description: | This is a utility for transforming Ecological Metadata Language ('EML') files into 'JSON-LD' and back into 'EML.' Doing so creates a list-based representation of 'EML' in R, so that 'EML' data can easily be manipulated using standard 'R' tools. This makes this package an effective backend for other 'R'-based tools working with 'EML.' By abstracting away the complexity of 'XML' Schema, developers can build around native 'R' list objects and not have to worry about satisfying many of the additional constraints of set by the schema (such as element ordering, which is handled automatically). Additionally, the 'JSON-LD' representation enables the use of developer-friendly 'JSON' parsing and serialization that may facilitate the use of 'EML' in contexts outside of 'R,' as well as the informatics-friendly serializations such as 'RDF' and 'SPARQL' queries. |
Authors: | Carl Boettiger [aut, cre, cph] , Matthew B. Jones [aut, cph] , Bryce Mecum [aut, cph] |
Maintainer: | Carl Boettiger <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.1 |
Built: | 2024-10-28 06:22:15 UTC |
Source: | https://github.com/ropensci/emld |
The goal of emld is to provide a way to work with EML metadata in the JSON-LD format. At it's heart, the package is simply a way to translate an EML XML document into JSON-LD and be able to reverse this so that any semantically equivalent JSON-LD file can be serialized into EML-schema valid XML.
The package has only three core functions:
as_emld()
Convert EML's xml
files (or the json
version created
by this package) into a native R object (an S3 class called emld
,
essentially just a list
).
as_xml()
Convert the native R format, emld
, back into
XML-schema valid EML.
as_json()
Convert the native R format, emld
, into json
(LD).
Maintainer: Carl Boettiger [email protected] (ORCID) [copyright holder]
Authors:
Matthew B. Jones [email protected] (ORCID) [copyright holder]
Bryce Mecum [email protected] (ORCID) [copyright holder]
Useful links:
Report bugs at https://github.com/ropensci/emld/issues
Coerce an EML file or object into an emld object.
as_emld(x, from = c("guess", "xml", "json", "list"))
as_emld(x, from = c("guess", "xml", "json", "list"))
x |
path to an EML file |
from |
explicit type for the input format. By default, will attempt to guess the format, but it always safer to specify the input format. This is essential for literal text strings or raw vectors where the type cannot be guessed by the R object class or file extension of the input. |
an emld object
hf205 <- system.file("extdata/hf205.xml", package="emld") as_emld(hf205)
hf205 <- system.file("extdata/hf205.xml", package="emld") as_emld(hf205)
Coerce an emld object into JSON
as_json(x, file = NULL)
as_json(x, file = NULL)
x |
an emld object |
file |
optional path to write out to file. Otherwise, defaults to NULL and will return a json object. |
Note: since emld list object maintains a 1:1 correspondence with JSON, following the conventions of jsonlite, this function is basically trivial. The only purpose is to default to auto_unbox = TRUE in serializing lists to JSON.
a json object. Or if a file path is provided, the metadata
is written out in JSON file and the function returns NULL
invisibly.
f <- system.file("extdata/example.xml", package = "emld") emld <- as_emld(f) json <- as_json(emld) ## can also write a json file to disk: json_file <- tempfile() as_json(emld, json_file)
f <- system.file("extdata/example.xml", package = "emld") emld <- as_emld(f) json <- as_json(emld) ## can also write a json file to disk: json_file <- tempfile() as_json(emld, json_file)
Coerce an emld object into XML (EML's standard format)
as_xml(x, file = NULL, root = "eml", ns = "eml", schemaLocation = TRUE)
as_xml(x, file = NULL, root = "eml", ns = "eml", schemaLocation = TRUE)
x |
an emld object |
file |
optional path to write out to file. Otherwise, defaults to NULL and will return an xml_document object. |
root |
name for the root node; default to 'eml' |
ns |
namespace abbreviation on root node, default 'eml' |
schemaLocation |
If not explicitly set on |
Unlike as_json, this function cannot rely on the existing
convention of serializing a list to xml, eg, as defined by xml2::as_xml_document()
Instead, this relies on a modified version, as_eml_document. In addition
further steps must be taken when working with JSON-LD to deal with
different possible framings and namespaces from the JSON-LD context
element. Thus this as_xml
function is particular to EML and emld
objects alone.
a xml_document object. Or if a file path is provided, the metadata
is written out in XML file and the function returns NULL
invisibly.
f <- system.file("extdata/example.xml", package = "emld") emld <- as_emld(f) xml <- as_xml(emld) ## can also write directly to a file: xml_file <- tempfile() as_xml(emld, xml_file) ## if you don't want the `xsi:schemaLocation` attribute set as_xml(emld, schemaLocation = FALSE) ## or if you want to set your own value as_xml(emld, schemaLocation = "https://eml.ecoinformatics.org/eml-2.2.0 http://example.com/eml-2.2.0/eml.xsd")
f <- system.file("extdata/example.xml", package = "emld") emld <- as_emld(f) xml <- as_xml(emld) ## can also write directly to a file: xml_file <- tempfile() as_xml(emld, xml_file) ## if you don't want the `xsi:schemaLocation` attribute set as_xml(emld, schemaLocation = FALSE) ## or if you want to set your own value as_xml(emld, schemaLocation = "https://eml.ecoinformatics.org/eml-2.2.0 http://example.com/eml-2.2.0/eml.xsd")
Utility function for use when filling in xmlns
, schemaLocation
, or
vocab
in various representations of EML. This is a little more future-proof
than keeping a dictionary for each version since this won't break on the next
release.
eml_ns(version = eml_version())
eml_ns(version = eml_version())
version |
EML version, currently either eml-2.2.0 (current version) or eml-2.1.1. Defaults to current version. |
returns the full XML namespace URI for the specified version of the schema
eml_validate processes an EML document using the XSD schema for the appropriate version of EML and determines if the document is schema-valid as defined by the XSD specification
eml_validate(eml, encoding = "UTF-8", schema = NULL)
eml_validate(eml, encoding = "UTF-8", schema = NULL)
eml |
file path, xml_document, |
encoding |
optional encoding for files, default UTF-8. |
schema |
path to schema |
Whether the document is valid (logical)
f <- system.file("extdata", "example.xml", package = "emld") ## validate file directly from disk: eml_validate(f) ## validate an eml object: eml <- as_emld(f) eml_validate(eml)
f <- system.file("extdata", "example.xml", package = "emld") ## validate file directly from disk: eml_validate(f) ## validate an eml object: eml <- as_emld(f) eml_validate(eml)
Set or check the EML version default
eml_version(version = getOption("emld_db", "eml-2.2.0"))
eml_version(version = getOption("emld_db", "eml-2.2.0"))
version |
EML version, currently either eml-2.2.0 (current version), or eml-2.1.1. The 'eml-' prefix can be omitted. |
returns the EML version string. As a side-effect, sets the
requested version as the default version by setting the emld_db
variable in options()
.
eml_version() eml_version("2.1.1") eml_version("eml-2.1.1")
eml_version() eml_version("2.1.1") eml_version("eml-2.1.1")
QName
for the root element, including its prefixNote that if a default namespace is used, the prefix will be d1
.
find_real_root_name(doc)
find_real_root_name(doc)
doc |
An |
A list
with elements prefix
and name
. prefix
will be NULL
if the element has no namespace prefix but name
will always be a
character
.
Find the root schema module and version
guess_root_schema(doc)
guess_root_schema(doc)
doc |
An |
If found, a list with names 'version', 'module', and 'namespace. If not found, throws an error.
schemaLocation
value for a given version of the schemaThis is a simple helper to make filling in the schemaLocation
attribute
on documents this package creates. Supports EML 2.1.1 and newer.
guess_schema_location(version = eml_version())
guess_schema_location(version = eml_version())
version |
Optional. Override the version of the schema. Defaults to the
current version returned by |
Returns a string suitable as a value for schemaLocation
or NULL
if a value wasn't found.
## Not run: # Get an appropriate schemaLocation value for the current version fo EML guess_schema_location() # Get an appropriate value for EML 2.1.1 guess_schema_location("eml-2.1.1") ## End(Not run)
## Not run: # Get an appropriate schemaLocation value for the current version fo EML guess_schema_location() # Get an appropriate value for EML 2.1.1 guess_schema_location("eml-2.1.1") ## End(Not run)
Create a template for an EML object
template(object)
template(object)
object |
the name of an eml object to create |
Note: while this function can be called in recursions, doing so may be a bad idea.
a list with elements named according to the properties of the object. This can be coerced into EML, see vignettes. NULL-valued elements (~) can take a data entry directly, while empty list()-valued elements () indicate properties that take other eml objects as values.
template("creator")
template("creator")