UP | HOME

RFC005: Explicit RDF definitions
Status: Approved

Table of Contents

1. Introduction

It turns out to be confusing to use existing structure types to define new RDF classes and properties. Rather than continuing to document rules on composition and restrictions on some RDF predicates we regularize these into new explicit definitions.

2. Motivation

The current use of standard structures to define RDF classes and properties is cumbersome.

3. Alternatives Considered

None.

4. Proposed Change

Syntax: The following grammar changes are required:

  1. Add a new rdf_def rule to the grammar that defines either a class or property using an annotaion_only_body (listing 1).
  2. Add specific rules rdf_type_class and rdf_type_property for the distinct keywords (listing 1).
  3. Add a new rdf_super_types to specify the type or types of the definition.
  4. Add the new rule rdf_def to the existing definition rule (listing 2).
rdf_def: $ => seq(
    keyword('rdf'),
    field(
        'type',
        choice(
            $.rdf_type_class,
            $.rdf_type_property,
        )
    ),
    field('name', $.identifier),
    optional(field('super_types', $.rdf_super_types)),
    field('body', $.annotation_only_body)
),

rdf_type_class: $ => keyword('structure'),
rdf_type_property: $ => keyword('property'),

rdf_super_types: $ => seq(
    operator('<-'),
    choice(
        $.identifier_reference,
        seq(
            '[',
            repeat($.identifier_reference),
            ']'
        )
    )
),
definition: $ => choice(
    $.data_type_def,
    $.entity_def,
    $.enum_def,
    $.event_def,
    $.property_def,
    $.structure_def,
    $.type_class_def,
    $.union_def,
    $.rdf_def
),

Semantics: As the super type list is optional the semantics assume the following:

  1. If the keyword structure is used and no super types are provided, a predicate rdfs:type with object rdfs:Class is added.
  2. If the keyword structure is used and super types are provided, a predicate rdfs:subClassOf is added for each super type with the super type as object.
  3. If the keyword structure is used and an empty super type list is provided, no rdfs:type or rdfs:subClassOf are added.
  4. If the keyword property is used and no super types are provided a predicate rdfs:type with object rdf:Property is added.
  5. If the keyword property is used and super types are provided, a predicate rdfs:subPropertyOf is added for each super type with the super type as object.
  6. If the keyword property is used and an empty super type list is provided, no rdfs:type or rdfs:subPropertyOf are added.

Example: Listing 3 shows this new grammar used to define elements in the RDF Schema module.

module rdf_schema <http://www.w3.org/2000/01/rdf-schema#> is

  import [ owl rdf ]

  structure Foo is a -> string end

  rdf structure Resource <- Resource is ;; assumed: @rdf:type = rdf:Class
    @comment = "The class resource, everything."
  end

  rdf property subClassOf is ;; assumed: @rdf:type = rdf:Property
    @domain = Class
    @range = Class
    @comment = "The subject is a subclass of a class."
  end

  rdf property comment is
    @rdf:type = owl:AnnotationProperty
    @domain = Resource
    @range = Literal
    @comment = "A description of the subject resource."
  end

end

4.1. Test cases

  1. The module in listing 3 is included in the tree-sitter-sdml package in the examples directory which is included in the parser test step.
  2. An explicit test case, rdf_definitions.sdm has been added to the tree-sitter-sdml test/corpus directory.
  3. An explicit test case, rdf_definitions.sdm has been added to the sdml-parse crate’s tests/examples directory.

4.2. Impact

This will require changes to the reference documentation to:

  • add new rules to sdml.ebnf,
  • update the surface syntax description to include these new rules, and
  • rewrite the section on defining new RDF properties and classes.

This will change how we define standard library modules as well.

Created: 2024-01-19 Fri 08:00