Shape Trees Specification

Editor’s Draft,

This version:
https://shapetrees.org/TR/specification/
Issue Tracking:
Inline In Spec
Editors:
Eric Prud'hommeaux
Justin Bingham

Abstract

Semantic Web Applications interoperate by sharing semantics of terms and constellations of resource-oriented data structures. This specification defines shape trees, a mechanism for declaring and operating over constellations of resource-oriented data structures.

Status of this document

1. Introduction

This section is non-normative.

Realizing the value proposition of the Semantic Web lies in building useful and robust applications that can interoperate over linked data. Protocols such as [LDP] and [Solid] organize linked data graphs into resource hierarchies, providing a foundation upon which these robust and interoperable applications can be created.

Application interoperability depends on applications sharing semantics for relationships and data structures. Existing technologies fulfill portions of those dependencies:

For applications that operate on more complex and interconnected resources, Shape Trees express the layout of those resources and associate them with their respective shapes.

Shape trees marry RDF vocabularies, shapes, and resources into "little trees" that provide machine to machine interoperability, combining them into concepts that humans can easily comprehend, such as medical records, notes, notebooks, calendars, and financial records.

This allows one to treat a set of related resources as a single grouping, and apply that to a range of operations including access control, data organization, data validation, and data migration.

Shape trees are defined as an RDF graph structure that expresses a set of expected behaviors by agents that work with them. These semantics CAN be implemented by a server-side agent, or a client-side agent that pre-processes requests to a server. In the most typical use case, a server-side agent enforces the expected behaviors on data as it is manipulated by a client-side agent.

While shape trees are intended to adapt to different technology platforms that support the notion of containers and resources, examples in this specification will reflect usage in an [LDP] environment.

2. Shape Tree

A shape tree is a machine-readable template describing the expected layout of a tree of resources in a container-based ecosystem. A shape tree expresses a tree hierarchy by containing other shape trees. The terms used to express a shape tree are described using an [RDF] vocabulary.

A shape tree instance is a resource or set of resources assigned to and in conformance with a given shape tree. A resource in a shape tree instance is called a managed resource.

Every managed resource has an associated shape tree locator. A shape tree locator identifies the shape tree associated with a managed resource, and additional information needed to navigate nested hierarchies of managed resources.

The st:expectsType property specifies that the described managed resource be one of these three types:

st:ShapeTreeResource Regular RDF resource that is not a container
st:ShapeTreeContainer RDF resource that contains other resources
st:ShapeTreeNonRDFResource Non-RDF resource such as binaries or images

The st:shape property specifies that the described managed resource conforms to the stated [ShEx] or [SHACL] shape.

Shape trees prescribe physical hierarchies and can reference other shape trees to form virtual hierarchies.

In a physical hierarchy, a shape tree expresses a managed resource that explicitly contains another managed resource via st:contains.

If shape tree S1 st:contains shape tree S2, S1 describes a container that contains another managed resource described by S2. For example, in [LDP], S1 describes an [LDP] container which ldp:contains nested resources described by S2.

Shape tree validation of a physical hierarchy
Managed Resource Associated Shape Tree
/project-1/ ex:ProjectTree
-- /milestone-A/ ex:MilestoneTree
---- /task-43/ ex:TaskTree
---- /task-48/ ex:TaskTree
------ /attachment-aa89 ex:AttachmentTree
---- /task-61/ ex:TaskTree
---- /issue-22/ ex:IssueTree
------ /attachment-cd12 ex:AttachmentTree
------ /attachment-ef55 ex:AttachmentTree
---- /issue-31/ ex:IssueTree
PREFIX st: <http://www.w3.org/ns/st#>
PREFIX ex: <http://www.example.com/ns/ex#>

<#ProjectTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeContainer ;
  st:shape ex:ProjectShape ;
  st:contains <#MilestoneTree> ,
              st:AllowNone .

<#MilestoneTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeContainer ;
  st:shape ex:MilestoneShape ;
  st:contains <#TaskTree>, <#IssueTree> ; 
  st:AllowNone .

<#TaskTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeContainer ;
  st:shape ex:TaskShape ;
  st:contains <#AttachmentTree> ,
  st:AllowNone .

<#IssueTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeContainer ;
  st:shape ex:IssueShape ;
  st:contains <#AttachmentTree> ,
  st:AllowNone .

<#AttachmentTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeNonRDFResource .

In a virtual hierarchy, a shape tree defines one or more shape tree references via st:references. A shape tree reference identifies the shape tree to be referenced via st:hasShapeTree, and the shape path through which it is linked via st:traverseViaShapePath.

A shape path is a string that defines a traversal of a shape schema. [SHEXPATH]

Shape tree validation of a virtual hierarchy
Managed Resource Associated Shape Tree
/project-1 ex:VirtualProjectTree
/milestone-A ex:VirtualMilestoneTree
/task-43 ex:VirtualTaskTree
/task-48 ex:VirtualTaskTree
/attachment-aa89 ex:VirtualAttachmentTree
/task-61 ex:VirtualTaskTree
/issue-22 ex:VirtualIssueTree
/attachment-cd12 ex:VirtualAttachmentTree
/attachment-ef55 ex:VirtualAttachmentTree
/issue-31 ex:VirtualIssueTree
PREFIX st: <http://www.w3.org/ns/st#>
PREFIX ex: <http://www.example.com/ns/ex#>

<#VirtualProjectTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeResource ;
  st:shape ex:ProjectShape ;
  st:references [
    st:hasShapeTree <#VirtualMilestoneTree> ;
    st:traverseViaShapePath "@ex:ProjectShape/ex:hasMilestone"
  ] .

<#VirtualMilestoneTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeResource ;
  st:shape ex:MilestoneShape ;
  st:references [
    st:hasShapeTree <#VirtualTaskTree> ;
    st:traverseViaShapePath "@ex:MilestoneShape/ex:hasTask"
  ] ,
  [
    st:hasShapeTree <#VirtualIssueTree> ;
    st:traverseViaShapePath "@ex:IssueShape/ex:hasIssue"
  ] .

<#VirtualTaskTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeResource ;
  st:shape ex:TaskShape ;
  st:references [
    st:hasShapeTree <#VirtualAttachmentTree> ;
    st:traverseViaShapePath "@ex:AttachmentShape/ex:hasAttachment"
  ] .

<#VirtualIssueTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeTreeContainer ;
  st:shape ex:IssueShape ;
  st:references [
    st:hasShapeTree <#VirtualAttachmentTree> ;
    st:traverseViaShapePath "@ex:AttachmentShape/ex:hasAttachment"
  ] .

<#VirtualAttachmentTree>
  a st:ShapeTree ;
  st:expectsType st:ShapeNonRDFResource .

Let ST be a shape tree. Let STI be a corresponding shape tree instance.

A { ST st:hasShapeTreeDecoratorIndex DI } arc indicates the location of an index of SKOS hierarchies that describes ST.

2.1. Shape Tree Schema

ShEx Schema for a Shape Tree
PREFIX st: <http://www.w3.org/ns/st#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

<#ShapeTree> {
  a st:ShapeTree ;
  (
    st:expectsType [st:ShapeTreeContainer] ;
    st:contains @<#ShapeTree> +
    |
    st:expectsType [st:ShapeTreeResource, st:ShapeTreeNonRDFResource]
  ) ;
  rdfs:label xsd:string ? ;
  st:references @<#ReferencedShapeTree> * ;
  st:shape IRI ? ;
  st:contains IRI ? ;
  st:supports IRI ? ;
}

<#ReferencedShapeTree> {
  st:hasShapeTree IRI ;
  st:traverseViaShapePath xsd:string
}

3. Shape Tree Locator

A shape tree locator associates a managed resource with one or more shape trees. No more than one shape tree locator may be associated with a managed resource.

For example, in [Solid] a shape tree locator would be stored in an auxiliary resource associated with a given managed resource.

A shape tree locator includes one or more shape tree locations via st:location. Each shape tree location identifies a shape tree associated with the managed resource, the focus node for shape validation, and the information needed to navigate the physical hierarchy in which that managed resource resides.

If there is more than one shape tree location, they are all applied to the managed resource associated with the shape tree locator.

Shape tree locations identify key contextual points in a physical hierarchy:

Shape Tree Location properties
Property Description
st:hasShapeTree Identifies the shape tree to be associated with the managed resource
st:node Identifies the focus node for shape validation in the associated managed resource, and is only valid when the corresponding shape tree includes st:shape
st:shape Identifies the shape to which st:node must conform
st:hasRootShapeTree Identifies the shape tree root
st:hasShapeTreeInstanceRoot Identifies the shape tree instance root

A shape tree root, and its corresponding shape tree instance root can be planted within an existing managed hierarchy, alongside or within other shape tree roots and shape tree instance roots.

Shape tree locations in a given shape tree locator may have different focus nodes.

Navigating a physical shape tree hierarchy
Managed Resource Shape Tree Shape Tree Root Shape Tree Instance Root
/data/ ex:DataTree ex:DataTree /data/
-- /projects/ ex:DataCollectionTree
ex:ProjectsTree
ex:DataTree
ex:ProjectsTree
/data/
/data/projects/
---- /project-1/ ex:ProjectTree ex:ProjectsTree /data/projects/
------ /milestone-A/ ex:MilestoneTree ex:ProjectsTree /data/projects/
-------- /task-43/ ex:TaskTree ex:ProjectsTree /data/projects/
-------- /task-48/ ex:TaskTree ex:ProjectsTree /data/projects/
---------- /attachment-aa89 ex:AttachmentTree ex:ProjectsTree /data/projects/
-------- /task-61/ ex:TaskTree ex:ProjectsTree /data/projects/
-------- /issue-22/ ex:IssueTree ex:ProjectsTree /data/projects/
---------- /attachment-cd12 ex:AttachmentTree ex:ProjectsTree /data/projects/
---------- /attachment-ef55 ex:AttachmentTree ex:ProjectsTree /data/projects/
-------- /issue-31/ ex:IssueTree ex:ProjectsTree /data/projects/
Shape Tree Locator for /data/projects with multiple shape tree locations in a nested physical hierarchy
PREFIX st: <http://www.w3.org/ns/st#> 
PREFIX ex: <http://www.example.com/ns/ex#>
PREFIX data: <https://storage.example.com/data/>

<#locator>
  a st:ShapeTreeLocator ;
  st:location [
    st:hasRootShapeTree ex:DataTree ;
    st:hasShapeTree ex:DataTypeTree ;
    st:hasShapeTreeInstanceRoot data: ;
    st:node data:projects#collection ;
    st:shape ex:DataCollectionShape ;
  ], [
    st:hasRootShapeTree ex:ProjectsTree ;
    st:hasShapeTree ex:ProjectsTree ;
    st:hasShapeTreeInstanceRoot data:projects ;
    st:node data:projects#collection ;
    st:shape ex:ProjectCollectionShape ;
  ] .
Shape Tree Locator for /data/projects/project-1/milestone-A/task-48 with a single shape tree location in a nested physical hierarchy
PREFIX st: <http://www.w3.org/ns/st#> 
PREFIX ex: <http://www.example.com/ns/ex#>
PREFIX data: <https://storage.example.com/data/>
PREFIX task-48: <https://storage.example.com/data/projects/project-1/milestone-A/task-48>

<#locator>
  a st:ShapeTreeLocator ;
  st:location [
    st:hasRootShapeTree ex:ProjectsTree ;
    st:hasShapeTree ex:TaskTree ;
    st:hasShapeTreeInstanceRoot data:projects ;
    st:node task-48#task ;
    st:shape ex:TaskShape ;
  ] .

A shape tree location may be used to provide shape validation only, in which case only the focus node and shape are provided, via st:node and st:shape, respectively.

A shape tree locator providing only shape validation
Managed Resource Shape Focus Node
/data/projects/project-1 ex:ProjectShape /data/projects/project-1#project
PREFIX st: <http://www.w3.org/ns/st#> 
PREFIX ex: <http://www.example.com/ns/ex#>
PREFIX project1: <https://storage.example.com/data/projects/project-1#>

<#locator>
  a st:ShapeTreeLocator ;
  st:location [
    st:node project1:project ;
    st:shape ex:ProjectShape ;
] .

3.1. Shape Tree Locator Schema

ShEx Schema for a Shape Tree Locator
PREFIX st: <http://www.w3.org/ns/st#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

<#ShapeTreeLocatorShape> {
  a [st:ShapeTreeLocator] ;
  st:location @<#ShapeTreeLocationShape>+
}  

<#ShapeTreeLocationShape> {
  st:hasRootShapeTree IRI ;
  st:hasShapeTree IRI ;
  st:hasShapeTreeInstanceRoot IRI ;
  ( st:node IRI ;
    st:shape IRI )?
  |
  st:node IRI ;
  st:shape IRI
}

4. Shape Tree Operations

Working with shape trees entails using several higher-level operations —each of which may represent one or more HTTP requests and/or pieces of processing logic.

The key operations used to manage shape trees are:

These operations make use of reusable, internal algorithms defined in Shape Tree Algorithms.

4.1. Discover Shape Tree

Description
The discover shape tree operation entails discovering what, if any, shape trees are managing a given container.
Inputs
URI The URI of the resource to discover shape trees for
Outputs
LOCATORS Collection of st:ShapeTreeLocator subjects
  1. Perform a HEAD on the provided URI to discover Shape Tree metadata URI

    Note: This step SHOULD be performed by a client-side agent.

    URI = /data/CommonNotes/
    HEAD /data/CommonNotes/
    
    Discover Container Shape Tree Metadata - HEAD container - Response
    HTTP/1.1 200 OK
    Link: </data/CommonNotes/meta/bc1b490a#loc>;
          rel="http://shapetrees.org/#ShapeTreeLocator"
    Link: <http://www.w3.org/ns/ldp#Container>; rel="type"
    ...other headers omitted...
    

    Discovering shape trees only applies to URIs of containers. A status code of 400 MUST be returned if no Link headers with a relation type which maps to the implementation’s notion of a container (e.g. http://www.w3.org/ns/ldp#Container in an LDP context) exists.

    Let METAURI be the URI of the shape tree metadata resource pertaining to URI through the Link header with relation http://shapetrees.org/#ShapeTreeLocator.

  2. Perform a GET on the discovered Shape Tree metadata resource (METAURI)

    Note: This step SHOULD performed by a client-side agent.

    Discover Container Shape Tree Metadata - Get Shape Tree metadata - Request
    GET /data/CommonNotes/meta/bc1b490a#loc
    
    Discover Container Shape Tree Metadata - GET Shape Tree metadata - Managed Container Response
    PREFIX st: <http://www.w3.org/ns/st#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    
    <#loc>
      a st:ShapeTreeLocator ;
      st:location [
        st:hasRootShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTreeInstanceRoot </data/CommonNotes/> ;
        st:node </data/CommonNotes/Note1#doc> ;
        st:shape <http://commonnote.example/schema#NotesContainer> ;
      ]
    .
    
    Discover Container Shape Tree Metadata - GET Shape Tree metadata - Unmanaged Container Response
    HTTP/1.1 404 NOT FOUND
    

    A 404 status code indicates that no shape trees manage this container, and so it MUST be considered an Unmanaged Container.

  3. Collect any navigable shape trees

    Note: This step SHOULD performed by a client-side agent.

    If the <#loc> subject has one or more st:location predicates, this container MUST be considered a Managed Container.

    Let MC be this managed container.

    The st:hasShapeTree of each st:ShapeTreeLocator subject specifies what shape tree manages MC.

    The IRI of each st:ShapeTreeLocator describing a shape tree managing MC SHOULD be returned.

4.2. Plant Shape Tree

Description
The plant operation marks a container (new or existing) as being managed by one or more shape trees.
Inputs
REQ A POST or PUT HTTP request with the following characteristics:
  • Let LINKST be one or more Link headers with the relation of "http://shapetrees.org/#ShapeTreeLocator". This represents one or more shape trees to be planted by the plant operation.

  • A Link header with the relation "type" and a value of a compatible container (e.g. <http://www.w3.org/ns/ldp#BasicContainer>)

  • Let LINKFN be an OPTIONAL Link header with the relation of "http://shapetrees.org/#FocusNode". This represents the target subject within the request body (used for ShEx validation, etc.)

  • Let LINKTST be an OPTIONAL Link header with the relation of "http://shapetrees.org/#TargetShapeTree"

Outputs
RESPONSE A HTTP response containing a Location header with the URI of the container that the requested shape trees (LINKST) are planted in

Note: A plant operation MAY be performed by either a client or server-side agent.

  • Let TC be the Target Container - The container that will contain instances of the planted shape tree. This container may or may not already exist.

  • Let PC be the Parent Container - The container that will contain the new or existing target container representing the planted shape tree. When REQ is a POST, this will be the location URL. For PUT, this will be the parent of the PUT container.

  1. Preconditions

    Note: This step SHOULD be performed by a client-side agent.

    1. Ensure the Parent Container (PC) exists. If not, this operation MUST return a 404 status code.

    2. Discover any planted shape tree IRIs managing PC.

      1. Let PARENTST be the collection of dereferenced shape tree IRIs discovered for PC

    3. If the Target Container (TC) already exists, discover any previously planted shape tree IRIs.

      1. Collect any existing shape tree IRIs and combine with the IRIs of the LINKST provided via the request Link header to represent the full collection of existing and proposed shape trees for TC.

      2. Let ALLST be the collection of dereferenced shape tree IRIs representing both existing and LINKST IRIs

  2. Static Validation of Shape Trees for Conflicts

    Note: This step MAY be performed by either a client or server-side agent.

    1. Iterate ALLST to validate that none of the following conditions are met:

      • any shape tree has a st:expectsResourceType with a value other than st:ShapeTreeContainer

      • more than one shape tree has a st:shape value

      • more than one shape tree has a st:contains value

    If any of the above static validations fail, this operation MUST return a 400 status code.

  3. Validate graph body

    Note: This step MAY be performed by either a client or server-side agent.

    Must detail how to differentiate between ShEx and SHACL validation

    1. Let VST be the validating shape tree that is identified by the only shape tree in ALLST having a st:shape value

    2. If VST is present and the plant operation (REQ) includes an RDF graph body and ShEx validation is used and a Focus Node (LINKFN) is not present, this operation MUST return a 422 status code

    3. Perform a validation of the RDF graph body of REQ using the VST st:shape shape, targeting the graph’s LINKFN. If validation fails, this operation MUST return a 422 status code

  4. Validate against parent container

    Note: This step MAY be performed by either a client or server-side agent..

    1. Determine if the Parent Container (PC) is a Managed Container by evaluating if PARENTST is not empty

    2. If PC is a Managed Container call the validate proposed resource algorithm with parameters:

    Parameter Value Notes
    URI PC The parent container that will contain the target container
    STH LINKTST Link header with the relation of "http://shapetrees.org/#TargetShapeTree"
    RT st:ShapeTreeContainer The resource type being created/modified
  5. Create Target Container (TC), if necessary

    Note: This step MAY be performed by either a client or server-side agent..

    1. If TC does not exist, create it.

      Create Target Container - Request
      POST /<PC>/
      Slug: <TC>;
      Link: <http://www.w3.org/ns/ldp#BasicContainer>; rel="type"
      
      Create Target Container - Response
      HTTP 201 CREATED
      Location: http://pod.example/<PC>/<TC>/
      Content-type: text/turtle; charset=utf-8
      Content-length: 396
      
  6. Update Shape Tree Meta Data for Target Container (TC)

    Note: This step MAY be performed by either a client or server-side agent..

    1. Update Target Container TC Metadata (METAURI)

      1. Iterate the collection of shape trees to be planted (LINKST), let LINKSTI be the current shape tree in context.

      2. Call algorithm Update Container Metadata with parameters:

      Parameter Value Notes
      TC TC The target container to that will contain instance data of the shape tree
      ROOTST LINKSTI The root shape tree at the top of the hierarchy
      ST LINKSTI The shape tree managing the target container
      ROOTPATH TC The target container to that will contain instance data of the shape tree
  7. Initialize Static Content

    Note: This step MAY be performed by either a client or server-side agent..

    1. Let CST be the shape tree having a st:contains value (if one exists) from the list of shape trees that were planted LINKST

    2. Iterate any st:contains IRIs within CST, letting CSTI be the current IRI in context

    3. Let CSTIST be the shape tree resulting in dereferencing IRI CSTI

    4. If CSTIST has a rdfs:label value, let LABEL be the value of rdfs:label for CSTIST, and call algorithm Initialize Statics with parameters:

    Parameter Value Notes
    PC TC The target container to that will contain instance data of the shape tree
    SST CSTIST The matching contained shape tree
    RST CST The shape tree containing a st:container
    RC TC The target container to that will contain instance data of the shape tree

4.3. Create Shape Tree Instance

Description
The create shape tree instance operation creates an instance of a shape tree within a managed container.
Inputs
REQ A POST or PUT HTTP request with the following characteristics:
  • A Link header with the relation "type" and a value of a compatible container (e.g. <http://www.w3.org/ns/ldp#BasicContainer>)

  • Let LINKFN be an OPTIONAL Link header with the relation of "http://shapetrees.org/#FocusNode". This represents the target subject within the request body (used for ShEx validation, etc.)

  • Let LINKTST be a REQUIRED Link header with the relation of "http://shapetrees.org/#TargetShapeTree"

Outputs
RESPONSE A standard HTTP response
  1. Preconditions

    Note: This step SHOULD be performed by a client-side agent.

    1. Ensure the Parent Container (PC) exists. If not, return this operation MUST return a 404 status code.

    2. Discover any planted shape tree IRIs managing PC.

      1. Let PARENTST be the collection of dereferenced shape tree IRIs discovered for PC

  2. Validate against parent container

    Note: This step MAY be performed by either a client or server-side agent.

    1. Determine if the Parent Container (PC) is a Managed Container by evaluating if PARENTST is not empty

    2. If PC is a Managed Container call the validate proposed resource algorithm with parameters:

    Parameter Value Notes
    URI PC The parent container to that will contain the target container
    STH LINKTST The shape tree managing the target container
    RT st:ShapeTreeContainer or st:ShapeTreeResource or st:ShapeTreeNonRDFResource The resource type being created
  3. Create Resource

    Note: This step MAY be performed by either a client or server-side agent..

  4. Initialize Static Content

    Note: This step MAY be performed by either a client or server-side agent.

    1. Iterate any st:contains IRIs within MCST, letting CSTI be the current IRI in context

    2. Let CSTIST be the shape tree resulting in dereferencing IRI CSTI

    3. If CSTIST has a rdfs:label value, let LABEL be the value of rdfs:label for CSTIST, and call algorithm Initialize Statics with parameters:

    Parameter Value Note
    PC TC The target container that will contain instance data of the shape tree
    SST CSTIST The matching shape tree
    RST CST The parent shape tree managing the parent container
    RC TC The target container that will contain instance data of the shape tree

4.4. Update Shape Tree Instance

Description
The update shape tree instance operation updates an instance of a shape tree within a managed container.
Inputs
REQ A PUT or PATCH HTTP request with the following characteristics:
  • Let LINKFN be an OPTIONAL Link header with the relation of "http://shapetrees.org/#FocusNode". This represents the target subject within the request body (used for ShEx validation, etc.)

  • Let LINKTST be an REQUIRED Link header with the relation of "http://shapetrees.org/#TargetShapeTree"

  • Let RT be the resource type inferred by the request’s content type header

Outputs
RESPONSE A standard HTTP response
  1. Preconditions

    Note: This step SHOULD be performed by a client-side agent.

    1. Ensure the Parent Container (PC) exists. If not, this operation MUST return a 404 status code.

    2. Discover any planted shape tree IRIs managing PC.

      1. Let PARENTST be the collection of dereferenced shape tree IRIs discovered for PC

  2. Validate against parent container

    Note: This step MAY be performed by either a client or server-side agent.

    1. Determine if the Parent Container (PC) is a Managed Container by evaluating if PARENTST is not empty

    2. If PC is a Managed Container call the validate proposed resource algorithm with parameters:

    Parameter Value Notes
    URI PC The parent container that will contain the target container
    STH LINKTST The shape tree managing the target container
    RT RT The resource type being modified
  3. Update Resource

    Note: This step MAY be performed by either a client or server side agent.

4.5. Delete Shape Tree Instance

Description
The delete shape tree instance operation deletes an instance of a shape tree within a managed container.
Inputs
REQ A DELETE HTTP request
Outputs
RESPONSE A standard HTTP response
  1. Delete Resource

    Note: This step MAY be performed by either a client or server-side agent.

4.6. Unplant Shape Tree

Description
The unplant shape tree operation unassigns the provided shape tree from the provided container. If there are no remaining shape trees managing the container, it would no longer be considered a managed container.
Inputs
REQ A DELETE HTTP request with the following characteristics:
  • Let LINKST be a Link header with the relation of "http://shapetrees.org/#ShapeTreeLocator" indicating the shape tree that should no longer manage the target container

Outputs
RESPONSE A standard HTTP response
  • Let PC be the parent Container of the resource being deleted

  • Let TC be the Container of the resource being deleted

  1. Remove Shape Tree Metadata

    Note: This step MAY be performed by either a client or server-side agent.

    Call the remove shape tree metadata algorithm with parameters:

    Parameter Value Notes
    URI TC The target container that the [shape tree] is being removed from
    ST LINKST The shape tree no longer managing the tc

5. Shape Tree Algorithms

The below algorithms detail key pieces of logic required for shape tree implementations.

5.1. Validate Proposed Resource Against Parent Container

Description
This algorithm is responsible for determining if a proposed resource (which may more specifically be a container, resource, or non-RDF source) is valid to be created within a given container.

Note: This algorithm MAY be performed by either a client or server-side agent.

Inputs
PC The URI of the Managed Container that will contain the proposed resource
STH The target shape tree hint, from the request’s Link header with the relation of "http://shapetrees.org/#TargetShapeTree"
RT The resource type of proposed resource (container, resource, non-RDF source)
Outputs
MCST The URI of the matching contains shape tree
  1. Determine if the Parent Container (PC) is a Managed Container by evaluating if PARENTST is not empty

  2. If PC is a Managed Container, let MCST be the matching contained shape tree which is the result of calling the matching contained shape tree algorithm with parameters:

    Parameter Value Notes
    URI PC The parent container to discover shape trees for
    STH STH The shape tree hint provided as a Link header
    RT RT The resource type being created/modified
  3. If RT does not match MCST’s st:expectsType value, this operation MUST return a 422 status code

  4. If MCST has a st:shape value, and the plant operation (REQ) includes an RDF graph body and ShEx validation is used and a Focus Node (LINKFN) is not present, this operation MUST return a 422 status code

  5. Perform a validation of the RDF graph body of REQ using the mcst st:shape shape, targeting the graph’s LINKFN. If validation fails, this operation MUST return a 422 status code

5.2. Find Matching Contained Shape Tree

Description
This algorithm is responsible for determining which shape tree within a set of shape trees mentioned in st:contains is applicable for a given proposed resource.

Note: This algorithm MAY be performed by either a client or server-side agent.

Inputs
URI The URI of the Managed Container that will contain the proposed resource
STH The target shape tree hint, from the request’s Link header with the relation of "http://shapetrees.org/#TargetShapeTree"
RT The resource type of proposed resource (container, resource, non-RDF source)
Outputs
MCST A single shape tree IRI that should be used for validation
  1. Let MST be the shape trees managing URI found by discovering the shape trees

  2. Let CST be the shape tree within MST with a st:contains value(s)

  3. Let CCST be the candidate shape trees for matching - populated by each st:contains of CST

  4. If STH is specified

    1. and STH does NOT exist within CCST this algorithm MUST return a 400 status code

    2. and STH exists within CCST return STH

  5. If CCST does not contain any of st:AllowAll, st:AllowResources, st:AllowContainers, st:AllowNonRDFSources, this algorithm MUST return a status code of 422

  6. If st:AllowNone exists within CCST, this algorithm MUST return a status code 422

  7. If st:AllowAll exists within CCST, return null - indicating that while no match was found, PC has been configured to allow resources of any type to be created without matching the shape tree

  8. If st:AllowResources exists within CCST:

    1. And the resource type (RT) is not a Resource, this algorithm MUST return a status code of 422

    2. And the resource type (RT) is a Resource, return null - indicating that while no match was found, PC has been configured to allow Resources to be created without matching the shape tree

  9. If st:AllowContainers exists within CCST:

    1. And the resource type (RT) is not a Container, this algorithm MUST return a status code of 422

    2. And the resource type (RT) is a Container, return null - indicating that while no match was found, PC has been configured to allow Containers to be created without matching the shape tree

  10. If st:AllowNonRDFSources exists within CCST:

    1. And the resource type (RT) is not a Non-RDF Source, this algorithm MUST return a status code of 422

    2. And the resource type (RT) is a Non-RDF Source, return null - indicating that while no match was found, PC has been configured to allow non-RDF Sources to be created without matching the shape tree

5.3. Initialize Static Content

Description
This algorithm is responsible for initializing static content that is implied through the creation of its parent. When called, it recursively seeks out resources to be statically created.

Note: This algorithm MAY be performed by either a client or server-side agent.

Inputs
PC The parent container that any statics would be created within
SST The static shape tree to be initialized where an rdfs:label is set
RST The root shape tree that was planted at the top of this shape tree hierarchy
RC The root container at the top of this shape tree hierarchy
Outputs
NONE
  1. Let LABEL be the rdfs:label value of the provided "static" shape tree (SST)

  2. Create the expected resource using a PUT in order to have control of resource naming, letting CR be the resulting resource that was created

    1. Set the appropriate Link header with "type" relation based on the st:expectsType value of SST

  3. If the st:expectsType value of SST is st:ShapeTreeContainer:

    1. Call algorithm Update Container Metadata with parameters:

      Parameter Value Notes
      TC CR Created static resource
      ROOTST RST The root shape tree of the hierarchy
      ST SST The shape tree to assign to cr
      ROOTPATH RC The root container at the top of this shape tree hierarchy
    2. If SST has any values for st:contains:

      1. Iterate any st:contains IRIs within SST, letting CSSTI be the current IRI in context

      2. Let CSSTIT be the shape tree resulting in dereferencing IRI CSSTI

      3. If CSSTIT has a rdfs:label value then recursively call algorithm Initialize Statics with parameters:

        Parameter Value Notes
        PC CR Created static resource, now the parent
        SST CSSTIT A shape tree to be recursively planted
        RST RST The root shape tree of the hierarchy
        RC RC The root container at the top of this shape tree hierarchy

5.4. Update Container Metadata

Description
This algorithm is responsible for updating the shape tree metadata for a container to reflect what shapetree(s) manage that container and the container’s location relative to the broader hierarchy of shape trees.

Note: This algorithm MAY be performed by either a client or server-side agent.

Inputs
TC The URI of the Container to update metadata for
ROOTST The root shape tree within a hierarchy of shape tree containers
ST A shape tree that will manage TC
ROOTPATH Tthe URI of the root of this shape tree hierarchy, where ROOTST is planted
Outputs
NONE
  1. Perform a HEAD on Target Container TC

    Discover Target Container Shape Tree Metadata URI - Request
    HEAD /data/CommonNotes/
    
    Discover Target Container Shape Tree Metadata URI - Response
    HTTP/1.1 200 OK
    Link: </data/CommonNotes/meta/bc1b490a#loc>; rel="http://shapetrees.org/#ShapeTreeLocator"
    ...other headers omitted...
    

    Let METAURI be the URI of the shape tree metadata resource pertaining to TC.

  2. Perform a GET on the Target Container’s Shape Tree metadata (METAURI)

    Dereference Target Container Shape Tree Metadata URI - Request
    GET /data/CommonNotes/meta/bc1b490a#loc
    
    Dereference Target Container Shape Tree Metadata URI - Managed Response
    PREFIX st: <http://www.w3.org/ns/st#>
    
    <#loc>
      a st:ShapeTreeLocator ;
      st:location [
        st:hasRootShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTreeInstanceRoot </data/CommonNotes/> ;
        st:node </data/CommonNotes/Note1#doc> ;
        st:shape <http://commonnote.example/schema#NotesContainer> ;
      ]
    .
    
    Dereference Target Container Shape Tree Metadata URI - Unmanaged Response
    HTTP/1.1 404 NOT FOUND
    

    If a 404 is returned that indicates that no shape trees manage this container. Let EG be the existing metadata graph resulting from dereferencing and parsing METAURI.

  3. Populate the metadata graph with triples

    Using EG, if it exists, otherwise a new graph, the following triples should be added:

    Subject Predicate Object Description
    <#generated UUID> rdf:type st:ShapeTreeLocator Indicates the RDF class of the subject
    <#generated UUID> st:hasRootShapeTree ROOTST Describes the shape tree planted at the root of this shape tree hierarchy
    <#generated UUID> st:hasShapeTree ST Describes the shape tree planted at this container
    <#generated UUID> st:hasShapeTreeInstanceRoot ROOTPATH Describes the URI to the root container of this shape tree hierarchy
    referenced st:ShapeTreeLocator (e.g. <#loc>) st:location <#generated UUID> Identifies the st:node and st:shape for validation as well as the corresponding node in the ShapeTree (st:hasShapeTree), ShapeTree root in the resource hierarchy (st:hasShapeTreeInstanceRoot) and root node in the ShapeTree (st:hasRootShapeTree).
  4. Persist the above triples to METAURI.

5.5. Remove Shape Tree From Container Metadata

Description
This algorithm is responsible for updating the shape tree metadata for a container to remove a shape tree from managing a container.

Note: This algorithm MAY be performed by either a client or server-side agent.

Inputs
TC The URI of the Container to update metadata for
ST A shape tree that will no longer manage TC
Outputs
NONE
  1. Perform a HEAD on Target Container TC

    Discover Target Container Shape Tree Metadata URI - Request
    HEAD /data/CommonNotes/
    
    Discover Target Container Shape Tree Metadata URI - Response
    HTTP/1.1 200 OK
    Link: </data/CommonNotes/meta/bc1b490a#loc>; rel="http://shapetrees.org/#ShapeTreeLocator"
    ...other headers omitted...
    

    Let METAURI be the URI of the shape tree metadata resource pertaining to TC.

  2. Perform a GET on the Target Container’s Shape Tree metadata (METAURI)

    Dereference Target Container Shape Tree Metadata URI - Request
    GET /data/CommonNotes/meta/bc1b490a#loc
    
    Dereference Target Container Shape Tree Metadata URI - Managed Response
    PREFIX st: <http://www.w3.org/ns/st#>
    
    <#loc>
      a st:ShapeTreeLocator ;
      st:location [
        st:hasRootShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTree <http://commonnote.example/commonnote#container-tree> ;
        st:hasShapeTreeInstanceRoot </data/CommonNotes/> ;
        st:node </data/CommonNotes/Note1#doc> ;
        st:shape <http://commonnote.example/schema#NotesContainer> ;
      ]
    .
    
    Dereference Target Container Shape Tree Metadata URI - Unmanaged Response
    HTTP/1.1 404 NOT FOUND
    

    If a 404 is returned that indicates that no shape trees manage this container. Let EG be the existing metadata graph resulting from dereferencing and parsing METAURI.

  3. Remove pertinent shape tree triples

    Let S be the subject of type ShapeTreeLocator with a st:hasShapeTree matching ST.

    Remove the subject S along with the st:hasShapeTreeLocator referencing S from the metadata graph.

  4. Persist the updated graph to METAURI.

6. Describing Shape Trees

While the RDF structure of shape trees enable machine readability, additional context is needed to make it human-friendly.

External SKOS graphs can be OPTIONALLY linked to describe the shape tree in human-readable terms.

  • Let STR be an RDF document containing one or more shape trees STs.

  • The { <> st:hasShapeTreeDecoratorIndex IDX } arc indicates that there is exactly one st:ShapeTreeDecoratorIndex located at IDX.

  • The { IDX a st:ShapeTreeDecoratorIndex } arc indicates a st:ShapeTreeDecoratorIndex that represents an index of st:ShapeTreeDecoratorSet.

  • The { IDX st:hasSet SET } arc indicates linkage to one or more st:ShapeTreeDecoratorSet.

  • The { SET a st:ShapeTreeDecoratorSet } arc indicates a st:ShapeTreeDecoratorSet that represents a SKOS graphs for a given language or interpretation.

  • The { SET st:hasShapeTreeDecoratorResource DECRESOURCE } arc indicates linkage to a single st:ShapeTreeDecoratorResource.

  • The { SET st:usesLanguage LANG } arc indicates the language used by the associated DECRESOURCE.

ShEx validation of a Shape Tree Decorators
PREFIX st: <http://www.w3.org/ns/st#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>

<#DecoratorIndex> {
  a [ st:ShapeTreeDecoratorIndex ] ;
  st:defaultLanguage xsd:language ? ;
  st:hasSet IRI*
}

<#DecoratorSet> {
  a [ st:ShapeTreeDecoratorSet ] ;
  st:usesLanguage xsd:language ;
  st:hasShapeTreeDecoratorResource IRI
}

<#Decorator> {
  a [ st:ShapeTreeDecorator ] ;
  st:hasShapeTree IRI ;
  skos:prefLabel xsd:string ;
  skos:definition xsd:string ?
}
  

SKOS constructs such as skos:narrower MAY be used to group or organize related shape trees.

7. Definitions

The following terms are used throughout this specification:
  • Arc -- the directed relationship between two nodes in an RDF graph

  • Client-side Agent -- A software component interacting with a server. in the context of shape trees, a client-side agent may be responsible for data validation.

  • Container -- the generalized notion of a collection of resources; implementations of shape trees MAY use a container implementation such as [LDP] (ldp:Container, ldp:BasicContainer, etc.)

  • Ecosystem -- a software environment with resources organized in some hierarchical grouping that rely on shape tree concepts to better organize and validate structures of data

  • Focus Node -- the IRI to an RDF subject which is used to specify which subject within a document should be processed first. In the context of shape trees one usage is directing shape validation to the appropriate node in the graph.

  • Managed Container -- any container that has a shape tree planted in it. A Managed Container MAY be an Instance Root or hierarchically nested within the resource hierarchy.

  • Non-RDF Source -- the generalized notion of document not containing linked-data triples; this may include plain text or binary data.

  • RDF -- Resource Description Framework [rdf11-primer]

  • Resource -- the generalized notion of document containing linked-data; implementations of shape trees may use a resource implementation such as [LDP] (ldp:Resource, etc.)

  • Server-side Agent -- A server-side software component. Server-side agents that support shape trees are responsible for data validation.

  • Shape -- a schema definition allowing validation of an RDF subject. Example specifications supporting the notion of shapes include [ShEx] and [SHACL].

  • SKOS Graph -- an RDF graph conforming to [skos-reference] data model. For purposes of shape trees a SKOS Graph is used to describe a shape tree in human-readable terms.

  • Unmanaged Container -- any Container which is not described by a shape tree

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Index

Terms defined by this specification

References

Normative References

[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119

Informative References

[LDP]
Steve Speicher; John Arwe; Ashok Malhotra. Linked Data Platform 1.0. URL: https://www.w3.org/TR/ldp/
[RDF]
Richard Cyganiak; David Wood; Markus Lanthaler. RDF 1.1 Concepts and Abstract Syntax. URL: https://www.w3.org/TR/rdf11-concepts
[RDF11-PRIMER]
Guus Schreiber; Yves Raimond. RDF 1.1 Primer. 24 June 2014. NOTE. URL: https://www.w3.org/TR/rdf11-primer/
[SHACL]
Holger Knublauch; Dimitris Kontokostas. Shapes Constraint Language (SHACL). 20 July 2017. REC. URL: https://www.w3.org/TR/shacl/
[ShEx]
Eric Prud'hommeaux; et al. Shape Expressions Language 2.1. URL: http://shex.io/shex-semantics/index.html
[SHEXPATH]
Eric Prud'hommeaux. Shape Expressions ShExPath Language. URL: https://shexspec.github.io/spec/ShExPath
[SKOS-REFERENCE]
Alistair Miles; Sean Bechhofer. SKOS Simple Knowledge Organization System Reference. 18 August 2009. REC. URL: https://www.w3.org/TR/skos-reference/
[Solid]
Sarven Capasdisli; et al. Solid Protocol. URL: https://solidproject.org/TR/protocol

Issues Index

Must detail how to differentiate between ShEx and SHACL validation