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:
- Add a new
rdf_def
rule to the grammar that defines either a class or property using anannotaion_only_body
(listing 1). - Add specific rules
rdf_type_class
andrdf_type_property
for the distinct keywords (listing 1). - Add a new
rdf_super_types
to specify the type or types of the definition. - Add the new rule
rdf_def
to the existingdefinition
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:
- If the keyword
structure
is used and no super types are provided, a predicaterdfs:type
with objectrdfs:Class
is added. - If the keyword
structure
is used and super types are provided, a predicaterdfs:subClassOf
is added for each super type with the super type as object. - If the keyword
structure
is used and an empty super type list is provided, nordfs:type
orrdfs:subClassOf
are added. - If the keyword
property
is used and no super types are provided a predicaterdfs:type
with objectrdf:Property
is added. - If the keyword
property
is used and super types are provided, a predicaterdfs:subPropertyOf
is added for each super type with the super type as object. - If the keyword
property
is used and an empty super type list is provided, nordfs:type
orrdfs: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
- 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. - An explicit test case,
rdf_definitions.sdm
has been added to the tree-sitter-sdmltest/corpus
directory. - An explicit test case,
rdf_definitions.sdm
has been added to the sdml-parse crate’stests/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.