Create a new ROCrate object using a default template or from a valid jsonld object.
a valid jsonld object
Optional
config: {Optional
array?: booleanAlways return property of an Entity as an array (eg when using getEntity() method)
Optional
defaultType?: stringThe default value for @type
to be used when adding a new entity and the property is not specified. Default to 'Thing'
Optional
duplicate?: booleanAllow duplicate values in a property that has multiple values
Optional
link?: booleanResolve linked node as nested object
Optional
merge?: booleanWhen replacing or updating an entity, merge the values and the properties instead of full replace
Optional
replace?: booleanWhen importing from json, a subsequent duplicate entity always replaces the existing one
Internal representation of the context
A cache of resolved context content
Index for context IRI that is irregular
Lookup table to index nodes by their properties
Lookup table to get a reference to existing and non-existing nodes. This is needed to avoid searching for the whole graph for every "@reverse" lookup as an entity referenced by other entities may not exist yet in the graph.
Import Utils class directly
Static
defaultsThe context part of the crate. An alias for '@context'. This returns the original context information.
An array of all nodes in the graph. An alias for '@graph'
The Metadata File Descriptor, which describes the RO-Crate Metadata File and links it to the Root Data Entity.
The Root Data Entity.
The root identifier of the RO Crate
Create a new node or return an existing node with the given data
Identifier of the node (@id)
Optional
ref: NodeRefAn immutable and unique reference to node that contains id and reverse information only
a newly created or existing node that matches the id
Return a proxy that wraps a node as an entity object supporting linked objects capability.
Init a new node or update existing one
Update the node with the given data
Optional
add?: booleanIf true, create an entity even if the data is empty
Optional
merge?: booleanIf false and if node already exists, remove all existing properties not in the specified data
Optional
recurse?: booleanProcess nested objects recursively
Optional
replace?: booleanIf false and if node already exists, do nothing to the node
Optional
seen?: WeakSet<any>A set to keep track of cyclic reference in the input
Return true if node is changed
Append the specified string or object directly as an entry into the RO-Crate JSON-LD Context array. It does not check for duplicates or overlapping content if the context is an object.
A URL or an Object that contains the context mapping
Add an entity to the crate.
A valid RO-Crate entity described in plain object.
Optional
recurse?: booleanIf true, nested entities will be added as well.
Optional
replace?: booleanIf true, replace existing entity with the same id.
true if the entity is successfully added.
Add a new identifier as a PropertyValue to the Root Data Entity. identifier and name are required parameters
The added identifier or undefined
Add a Profile URI to the crate
A valid Profile URI
Add the term and its definition to the first context definition (a map) found from the @context
entries.
If no existing context definition found, a new one will be created.
The term name like 'name' or 'schema:name'
The term IRI
Optional
force: booleanIf the term is in the format of prefix:suffix and force is true, add the term to the context as it is
Add one or more value to a property of an entity. If the specified property does not exists, a new one will be set. If the property already exists, the new value will be added to the property array.
The id or the entity to add the property to
The name of the property
The value of the property
Optional
duplicate?: booleanIf true, allow a property to have duplicate values in the array
Deep clone the instance of this crate.
Transform the property names of all entities by replacing it with the specified prefixes
The set of prefixes to use for the compaction
Delete an entity from the graph
Entity Identifier or the entity object itself
Optional
references?: booleanSet true to delete all references to the deleted entity
True if any existing entity was deleted
Delete a property of an Entity
The id of the entity to add the property to
The name of the property
Delete one or more values from a property.
Returns a new iterator object that contains the entities in the graph.
Optional
filter?: anyFilter the result based on the values of the properties defined in this object.
Optional
flat?: booleanIf true, return the copy of entity as a plain object.
Experimental method to turn a graph into a flat dictionary eg for turning it into a table
Get configuration value
Name of the config parameter
Get the context term definition. This method will also search for term defined locally in the graph.
Make sure resolveContext()
has been called prior calling this method.
Get an entity from the graph. If config.link is true, any reference (object with just "@id" property) is resolved as a nested object.
An entity identifier
A wrapper for entity that resolves properties as linked objects
Use getGraph with argument set to true
Get an array of all nodes in the graph. Each node in the array is an Entity instance. If config.link is true, any link to other node will be made into nested object.
If true, return the copy of entity as a plain object.
Get named identifier
the identifier
Use toJSON
Use getTree with the following argument: { root, depth, allowCycle: true }
Get the property of an entity
the value of the property
Use rootDataset
Use rootId
Get the context term name from it's definition id.
Make sure resolveContext()
has been called prior calling this method.
Return a JSON.stringify-ready tree structure starting from the specified item
with all values (apart from @id) as arrays
and string-values expressed like: {"@value": "string-value"}
Optional
allowCycle?: booleanOptional
depth?: numberThe number of nesting the tree will have. Must be 0 or positive integer.
Optional
root?: anyOptional
valueObject?: booleanthe root entity
Check if entity exists in the graph
An entity identifier
Check if an entity has a type
Add a remote URL to the context and resolve the entries.
Get the index of the entity in the graph array. This is an O(n) operation.
Create a simple tree-like object - but don't make circular structures
Use getTree with the valueObject argument set to false`
Add a value to an item's property array
Use addValues
A JSON-LD item or array of [item]
An array of objects that represents a 'path' through the graph.
Object must have a "property" to follow, eg:
resolve(item, {"property": "miltaryService"});
and optionally a condition "includes", eg:
"includes": {"@type", "Action"}}
and optionally, a function "matchFn" which takes an item
as argument and returns a boolean, eg:
"matchFn": (item) => item['@id'].match(/anzsrc-for/)
Optional
subgraph: any[]If present and true, all intervening items during the traversal will be stored. If an array is passed, the intervening items will be stored in the array.
null, or an array of items
resolveAll does a resolve but collects and deduplicates intermediate items. Its first returned value is the final items (ie what resolve(..)) would have returned.
Expand a term into the IRI, which is the same as the @id
of the term definition.
Make sure resolveContext()
has been called prior calling this method.
a short word defined in the context
Use getGraph and pass true as the argument
Set a property of an entity with the given value. If a property with the same name exists, its existing value will be replaced with the specified value. If values contain nested non-empty entities, they will be processed recursively.
The id of the entity to add the property to
The name of the property
A value or an array of values
Optional
duplicate?: booleanIf true, allow a property to have duplicate values
Convert the rocrate into plain JSON object. The value returned by this method is used when JSON.stringify() is used on the ROCrate object.
plain JSON object
Generate a new unique id that does not match any existing id in the graph.
The base string of the id.
The base suffixed with the incremental number.
Update an entity by replacing the object with the same id.
This operations will remove all properties of the existing entity and
add the new ones contained in data
, unless merge
argument is true.
Optional
merge?: booleanIf true, new properties will be merged. Defaults to config.merge
.
Optional
recurse?: booleanIf true, nested entities will be updated as well.
false if there is no existing entity with the same id or data is empty.
Change the identifier of an entity node
Static
createCreate a new ROCrate instance with default configuration set as the following:
array
: truelink
: truereplace
: falsemerge
: trueduplicate
: false
and resolve all the included contexta valid jsonld object
Class for building, navigating, testing and rendering ROCrates
Todo
import validation and rendering from Calcyte