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_defrule to the grammar that defines either a class or property using anannotaion_only_body(listing 1). - Add specific rules
rdf_type_classandrdf_type_propertyfor the distinct keywords (listing 1). - Add a new
rdf_super_typesto specify the type or types of the definition. - Add the new rule
rdf_defto the existingdefinitionrule (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
structureis used and no super types are provided, a predicaterdfs:typewith objectrdfs:Classis added. - If the keyword
structureis used and super types are provided, a predicaterdfs:subClassOfis added for each super type with the super type as object. - If the keyword
structureis used and an empty super type list is provided, nordfs:typeorrdfs:subClassOfare added. - If the keyword
propertyis used and no super types are provided a predicaterdfs:typewith objectrdf:Propertyis added. - If the keyword
propertyis used and super types are provided, a predicaterdfs:subPropertyOfis added for each super type with the super type as object. - If the keyword
propertyis used and an empty super type list is provided, nordfs:typeorrdfs:subPropertyOfare 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
examplesdirectory which is included in the parser test step. - An explicit test case,
rdf_definitions.sdmhas been added to the tree-sitter-sdmltest/corpusdirectory. - An explicit test case,
rdf_definitions.sdmhas been added to the sdml-parse crate’stests/examplesdirectory.
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.