Cleaner code generation, npytyping type hints for arrays

- split off generated subclasses into "include" files, not sure if that's good, but in any case we have them separable now.
- more work on cleanly un-nesting scalar and 1D-vector data into attributes and lists, respectively
- brought the pydantic generator in-repo to do a bunch of overrides
This commit is contained in:
sneakers-the-rat 2023-08-30 20:56:30 -07:00
parent be21325123
commit fd9aef9531
15 changed files with 229 additions and 266 deletions

View file

@ -92,7 +92,6 @@ class NamespacesAdapter(Adapter):
all_matches = [*internal_matches, *import_matches]
if len(all_matches)>1:
pdb.set_trace()
raise KeyError(f"Found multiple schemas in namespace that define {name}:\ninternal: {pformat(internal_matches)}\nimported:{pformat(import_matches)}")
elif len(all_matches) == 1:
return all_matches[0]

View file

@ -1,4 +1,4 @@
/docs/
/project/docs/
/tmp/

View file

@ -110,11 +110,6 @@ gen-pydantic: $(PYMODEL)
$(RUN) gen-pydantic $(SOURCE_SCHEMA_PATH) --pydantic_version 1 > $(PYMODEL)/nwb_schema_pydantic.py
$(RUN) run_patches --phase post_generation_pydantic
gen-pydantic-test: $(PYMODEL)
$(RUN) gen-pydantic src/nwb_schema_language/schema/test_multival.yml --pydantic_version 1 > $(PYMODEL)/test_multival_pydantic.py
# $(RUN) run_patches --phase post_generation
test: test-schema test-python test-examples
test-schema:

View file

@ -11,17 +11,17 @@ type Attribute implements DtypeMixin
defaultValue: AnyType
doc: String!
required: Boolean
dtype: String
dtype: [String]
}
type CompoundDtype
{
name: String!
doc: String!
dtype: FlatDtype!
dtype: [String]!
}
type Dataset implements DtypeMixin, NamingMixin
type Dataset implements DtypeMixin
{
neurodataTypeDef: String
neurodataTypeInc: String
@ -35,7 +35,7 @@ type Dataset implements DtypeMixin, NamingMixin
quantity: String
linkable: Boolean
attributes: [Attribute]
dtype: String
dtype: [String]
}
type Datasets
@ -45,10 +45,10 @@ type Datasets
interface DtypeMixin
{
dtype: String
dtype: [String]
}
type Group implements NamingMixin
type Group
{
neurodataTypeDef: String
neurodataTypeInc: String
@ -93,10 +93,6 @@ type Namespaces
namespaces: [Namespace]
}
interface NamingMixin
{
}
type ReferenceDtype
{
targetType: String!

View file

@ -1,15 +1,13 @@
{
"comments": {
"description": "Auto generated by LinkML jsonld context generator",
"generation_date": "2023-08-18T00:36:53",
"generation_date": "2023-08-30T20:53:58",
"source": "nwb_schema_language.yaml"
},
"@context": {
"linkml": "https://w3id.org/linkml/",
"nwb_schema_language": "https://w3id.org/p2p_ld/nwb-schema-language/",
"schema": {
"@type": "@id"
},
"schema": "http://schema.org/",
"skos": "http://www.w3.org/2004/02/skos/core#",
"@vocab": "https://w3id.org/p2p_ld/nwb-schema-language/",
"attributes": {
@ -54,6 +52,9 @@
"required": {
"@type": "xsd:boolean"
},
"schema_": {
"@type": "@id"
},
"value": {
"@type": "@id"
},

View file

@ -31,6 +31,9 @@
"name": "string",
"definition_uri": "https://w3id.org/linkml/String",
"description": "A character string",
"notes": [
"In RDF serializations, a slot with range of string is treated as a literal or type xsd:string. If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"string\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"exact_mappings": [
@ -44,6 +47,9 @@
"name": "integer",
"definition_uri": "https://w3id.org/linkml/Integer",
"description": "An integer",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"integer\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"exact_mappings": [
@ -57,6 +63,9 @@
"name": "boolean",
"definition_uri": "https://w3id.org/linkml/Boolean",
"description": "A binary (true or false) value",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"boolean\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"exact_mappings": [
@ -71,6 +80,9 @@
"name": "float",
"definition_uri": "https://w3id.org/linkml/Float",
"description": "A real number that conforms to the xsd:float specification",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"float\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"exact_mappings": [
@ -84,6 +96,9 @@
"name": "double",
"definition_uri": "https://w3id.org/linkml/Double",
"description": "A real number that conforms to the xsd:double specification",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"double\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"close_mappings": [
@ -97,6 +112,9 @@
"name": "decimal",
"definition_uri": "https://w3id.org/linkml/Decimal",
"description": "A real number with arbitrary precision that conforms to the xsd:decimal specification",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"decimal\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"broad_mappings": [
@ -111,7 +129,8 @@
"definition_uri": "https://w3id.org/linkml/Time",
"description": "A time object represents a (local) time of day, independent of any particular day",
"notes": [
"URI is dateTime because OWL reasoners do not work with straight date or time"
"URI is dateTime because OWL reasoners do not work with straight date or time",
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"time\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
@ -128,7 +147,8 @@
"definition_uri": "https://w3id.org/linkml/Date",
"description": "a date (year, month and day) in an idealized calendar",
"notes": [
"URI is dateTime because OWL reasoners don't work with straight date or time"
"URI is dateTime because OWL reasoners don't work with straight date or time",
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"date\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
@ -144,6 +164,9 @@
"name": "datetime",
"definition_uri": "https://w3id.org/linkml/Datetime",
"description": "The combination of a date and time",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"datetime\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"exact_mappings": [
@ -158,6 +181,9 @@
"name": "date_or_datetime",
"definition_uri": "https://w3id.org/linkml/DateOrDatetime",
"description": "Either a date or a datetime",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"date_or_datetime\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "str",
@ -169,6 +195,9 @@
"name": "uriorcurie",
"definition_uri": "https://w3id.org/linkml/Uriorcurie",
"description": "a URI or a CURIE",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"uriorcurie\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "URIorCURIE",
@ -181,6 +210,9 @@
"definition_uri": "https://w3id.org/linkml/Curie",
"conforms_to": "https://www.w3.org/TR/curie/",
"description": "a compact URI",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"curie\"."
],
"comments": [
"in RDF serializations this MUST be expanded to a URI",
"in non-RDF serializations MAY be serialized as the compact representation"
@ -197,6 +229,9 @@
"definition_uri": "https://w3id.org/linkml/Uri",
"conforms_to": "https://www.ietf.org/rfc/rfc3987.txt",
"description": "a complete URI",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"uri\"."
],
"comments": [
"in RDF serializations a slot with range of uri is treated as a literal or type xsd:anyURI unless it is an identifier or a reference to an identifier, in which case it is translated directly to a node"
],
@ -214,6 +249,9 @@
"name": "ncname",
"definition_uri": "https://w3id.org/linkml/Ncname",
"description": "Prefix part of CURIE",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"ncname\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "NCName",
@ -225,6 +263,9 @@
"name": "objectidentifier",
"definition_uri": "https://w3id.org/linkml/Objectidentifier",
"description": "A URI or CURIE that represents an object in the model.",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"objectidentifier\"."
],
"comments": [
"Used for inheritance and type checking"
],
@ -239,6 +280,9 @@
"name": "nodeidentifier",
"definition_uri": "https://w3id.org/linkml/Nodeidentifier",
"description": "A URI, CURIE or BNODE that represents a node in a model.",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"nodeidentifier\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "NodeIdentifier",
@ -251,6 +295,9 @@
"definition_uri": "https://w3id.org/linkml/Jsonpointer",
"conforms_to": "https://datatracker.ietf.org/doc/html/rfc6901",
"description": "A string encoding a JSON Pointer. The value of the string MUST conform to JSON Point syntax and SHOULD dereference to a valid object within the current instance document when encoded in tree form.",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"jsonpointer\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "str",
@ -263,6 +310,9 @@
"definition_uri": "https://w3id.org/linkml/Jsonpath",
"conforms_to": "https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html",
"description": "A string encoding a JSON Path. The value of the string MUST conform to JSON Point syntax and SHOULD dereference to zero or more valid objects within the current instance document when encoded in tree form.",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"jsonpath\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "str",
@ -275,6 +325,9 @@
"definition_uri": "https://w3id.org/linkml/Sparqlpath",
"conforms_to": "https://www.w3.org/TR/sparql11-query/#propertypaths",
"description": "A string encoding a SPARQL Property Path. The value of the string MUST conform to SPARQL syntax and SHOULD dereference to zero or more valid objects within the current instance document when encoded as RDF.",
"notes": [
"If you are authoring schemas in LinkML YAML, the type is referenced with the lower case \"sparqlpath\"."
],
"from_schema": "https://w3id.org/linkml/types",
"imported_from": "linkml:types",
"base": "str",
@ -584,8 +637,9 @@
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/schema",
"description": "List of the schema to be included in this namespace.",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/schema",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/schema_",
"multivalued": true,
"alias": "schema_",
"owner": "Namespace",
"domain_of": [
"Namespace"
@ -677,6 +731,7 @@
{
"name": "neurodata_type_def",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/neurodata_type_def",
"description": "Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/neurodata_type_def",
"owner": "Dataset",
@ -695,6 +750,7 @@
{
"name": "neurodata_type_inc",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/neurodata_type_inc",
"description": "Used alongside neurodata_type_def to indicate inheritance, naming, and mixins",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/neurodata_type_inc",
"owner": "Dataset",
@ -836,6 +892,7 @@
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/dtype",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/dtype",
"multivalued": true,
"owner": "DtypeMixin",
"domain_of": [
"CompoundDtype",
@ -862,7 +919,7 @@
"name": "dims",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/dims",
"todos": [
"Can't quite figure out how to allow an array of arrays"
"Can't quite figure out how to allow an array of arrays - see https://github.com/linkml/linkml/issues/895"
],
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/dims",
@ -873,13 +930,23 @@
"Dataset"
],
"range": "string",
"any_of": [
{
"range": "string",
"@type": "AnonymousSlotExpression"
},
{
"range": "AnyType",
"@type": "AnonymousSlotExpression"
}
],
"@type": "SlotDefinition"
},
{
"name": "shape",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/shape",
"todos": [
"Can't quite figure out how to allow an array of arrays"
"Can't quite figure out how to allow an array of arrays - see https://github.com/linkml/linkml/issues/895"
],
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/shape",
@ -890,15 +957,20 @@
"Dataset"
],
"range": "string",
"exactly_one_of": [
"any_of": [
{
"range": "integer",
"minimum_value": 1,
"@type": "AnonymousSlotExpression"
},
{
"range": "string",
"equals_string": "null",
"@type": "AnonymousSlotExpression"
},
{
"range": "AnyType",
"@type": "AnonymousSlotExpression"
}
],
"@type": "SlotDefinition"
@ -960,16 +1032,6 @@
],
"range": "string",
"required": true,
"any_of": [
{
"range": "Dataset",
"@type": "AnonymousSlotExpression"
},
{
"range": "Group",
"@type": "AnonymousSlotExpression"
}
],
"@type": "SlotDefinition"
},
{
@ -1073,6 +1135,7 @@
"is_a": "dtype",
"domain": "CompoundDtype",
"slot_uri": "https://w3id.org/p2p_ld/nwb-schema-language/dtype",
"multivalued": true,
"alias": "dtype",
"owner": "CompoundDtype",
"domain_of": [
@ -1080,20 +1143,16 @@
],
"is_usage_slot": true,
"usage_slot_name": "dtype",
"range": "FlatDtype",
"range": "string",
"required": true,
"any_of": [
{
"range": "FlatDtype",
"@type": "AnonymousSlotExpression"
},
{
"range": "CompoundDtype",
"@type": "AnonymousSlotExpression"
},
{
"range": "ReferenceDtype",
"@type": "AnonymousSlotExpression"
},
{
"range": "FlatDtype",
"@type": "AnonymousSlotExpression"
}
],
"@type": "SlotDefinition"
@ -1270,9 +1329,6 @@
"name": "Group",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/Group",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"mixins": [
"NamingMixin"
],
"slots": [
"neurodata_type_def",
"neurodata_type_inc",
@ -1341,8 +1397,7 @@
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/Dataset",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"mixins": [
"DtypeMixin",
"NamingMixin"
"DtypeMixin"
],
"slots": [
"neurodata_type_def",
@ -1415,7 +1470,7 @@
"slot_conditions": [
{
"name": "dtype",
"range": "CompoundDtype",
"range": "FlatDtype",
"@type": "SlotDefinition"
}
],
@ -1425,7 +1480,6 @@
"slot_conditions": [
{
"name": "dtype",
"multivalued": true,
"@type": "SlotDefinition"
}
],
@ -1436,72 +1490,6 @@
],
"@type": "ClassDefinition"
},
{
"name": "NamingMixin",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/NamingMixin",
"description": "require either neurodata_type_def or name to be present",
"from_schema": "https://w3id.org/p2p_ld/nwb-schema-language",
"mixin": true,
"slot_usage": {},
"class_uri": "https://w3id.org/p2p_ld/nwb-schema-language/NamingMixin",
"rules": [
{
"preconditions": {
"slot_conditions": [
{
"name": "neurodata_type_def",
"value_presence": {
"text": "ABSENT",
"@type": "PermissibleValue"
},
"@type": "SlotDefinition"
}
],
"@type": "AnonymousClassExpression"
},
"postconditions": {
"slot_conditions": [
{
"name": "name",
"required": true,
"@type": "SlotDefinition"
}
],
"@type": "AnonymousClassExpression"
},
"description": "If not defining a new type, a name is required",
"@type": "ClassRule"
},
{
"preconditions": {
"slot_conditions": [
{
"name": "name",
"value_presence": {
"text": "ABSENT",
"@type": "PermissibleValue"
},
"@type": "SlotDefinition"
}
],
"@type": "AnonymousClassExpression"
},
"postconditions": {
"slot_conditions": [
{
"name": "neurodata_type_def",
"required": true,
"@type": "SlotDefinition"
}
],
"@type": "AnonymousClassExpression"
},
"description": "If a name is not given, must be defining a new type",
"@type": "ClassRule"
}
],
"@type": "ClassDefinition"
},
{
"name": "AnyType",
"definition_uri": "https://w3id.org/p2p_ld/nwb-schema-language/AnyType",
@ -1516,9 +1504,9 @@
],
"metamodel_version": "1.7.0",
"source_file": "nwb_schema_language.yaml",
"source_file_date": "2023-08-18T00:28:45",
"source_file_size": 10952,
"generation_date": "2023-08-18T00:36:53",
"source_file_date": "2023-08-30T20:53:55",
"source_file_size": 10793,
"generation_date": "2023-08-30T20:53:59",
"settings": [
{
"setting_key": "email",

View file

@ -16,6 +16,14 @@
},
"dims": {
"items": {
"anyOf": [
{
"type": "string"
},
{
"$ref": "#/$defs/AnyType"
}
],
"type": "string"
},
"type": "array"
@ -25,6 +33,7 @@
"type": "string"
},
"dtype": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/FlatDtype"
@ -38,6 +47,8 @@
],
"type": "string"
},
"type": "array"
},
"name": {
"type": "string"
},
@ -47,13 +58,17 @@
},
"shape": {
"items": {
"oneOf": [
"anyOf": [
{
"minimum": 1,
"type": "integer"
},
{
"const": "null"
"const": "null",
"type": "string"
},
{
"$ref": "#/$defs/AnyType"
}
],
"type": "string"
@ -81,7 +96,15 @@
"type": "string"
},
"dtype": {
"anyOf": [
{
"$ref": "#/$defs/ReferenceDtype"
},
{
"$ref": "#/$defs/FlatDtype"
}
],
"type": "string"
},
"name": {
"type": "string"
@ -114,6 +137,14 @@
},
"dims": {
"items": {
"anyOf": [
{
"type": "string"
},
{
"$ref": "#/$defs/AnyType"
}
],
"type": "string"
},
"type": "array"
@ -123,6 +154,7 @@
"type": "string"
},
"dtype": {
"items": {
"anyOf": [
{
"$ref": "#/$defs/FlatDtype"
@ -136,6 +168,8 @@
],
"type": "string"
},
"type": "array"
},
"linkable": {
"type": "boolean"
},
@ -143,9 +177,11 @@
"type": "string"
},
"neurodata_type_def": {
"description": "Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins",
"type": "string"
},
"neurodata_type_inc": {
"description": "Used alongside neurodata_type_def to indicate inheritance, naming, and mixins",
"type": "string"
},
"quantity": {
@ -162,13 +198,17 @@
},
"shape": {
"items": {
"oneOf": [
"anyOf": [
{
"minimum": 1,
"type": "integer"
},
{
"const": "null"
"const": "null",
"type": "string"
},
{
"$ref": "#/$defs/AnyType"
}
],
"type": "string"
@ -273,9 +313,11 @@
"type": "string"
},
"neurodata_type_def": {
"description": "Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins",
"type": "string"
},
"neurodata_type_inc": {
"description": "Used alongside neurodata_type_def to indicate inheritance, naming, and mixins",
"type": "string"
},
"quantity": {
@ -335,14 +377,6 @@
"type": "string"
},
"target_type": {
"anyOf": [
{
"$ref": "#/$defs/Dataset"
},
{
"$ref": "#/$defs/Group"
}
],
"description": "Describes the neurodata_type of the target that the reference points to",
"type": "string"
}
@ -388,7 +422,7 @@
"name": {
"type": "string"
},
"schema": {
"schema_": {
"description": "List of the schema to be included in this namespace.",
"items": {
"$ref": "#/$defs/Schema"
@ -446,14 +480,6 @@
"description": "describes the kind of reference"
},
"target_type": {
"anyOf": [
{
"$ref": "#/$defs/Dataset"
},
{
"$ref": "#/$defs/Group"
}
],
"description": "Describes the neurodata_type of the target that the reference points to",
"type": "string"
}

View file

@ -7,13 +7,13 @@ message Attribute
anyType defaultValue = 0
string doc = 0
boolean required = 0
string dtype = 0
repeated string dtype = 0
}
message CompoundDtype
{
string name = 0
string doc = 0
flatDtype dtype = 0
repeated string dtype = 0
}
message Dataset
{
@ -29,7 +29,7 @@ message Dataset
string quantity = 0
boolean linkable = 0
repeated attribute attributes = 0
string dtype = 0
repeated string dtype = 0
}
message Datasets
{

View file

@ -59,7 +59,7 @@ linkml:Sparqlpath xsd:string
<default_value> @<AnyType> ? ;
<doc> @linkml:String ;
<required> @linkml:Boolean ? ;
<dtype> @linkml:String ?
<dtype> @linkml:String *
) ;
rdf:type [ <Attribute> ] ?
)
@ -68,7 +68,7 @@ linkml:Sparqlpath xsd:string
<CompoundDtype> CLOSED {
( $<CompoundDtype_tes> ( <name> @linkml:String ;
<doc> @linkml:String ;
<dtype> @<FlatDtype>
<dtype> @linkml:String +
) ;
rdf:type [ <CompoundDtype> ] ?
)
@ -77,8 +77,6 @@ linkml:Sparqlpath xsd:string
<Dataset> CLOSED {
( $<Dataset_tes> ( &<DtypeMixin_tes> ;
rdf:type [ <DtypeMixin> ] ? ;
&<NamingMixin_tes> ;
rdf:type [ <NamingMixin> ] ? ;
<neurodata_type_def> @linkml:String ? ;
<neurodata_type_inc> @linkml:String ? ;
<name> @linkml:String ? ;
@ -91,7 +89,7 @@ linkml:Sparqlpath xsd:string
<quantity> @linkml:String ? ;
<linkable> @linkml:Boolean ? ;
<attributes> @<Attribute> * ;
<dtype> @linkml:String ?
<dtype> @linkml:String *
) ;
rdf:type [ <Dataset> ] ?
)
@ -104,15 +102,13 @@ linkml:Sparqlpath xsd:string
}
<DtypeMixin> {
( $<DtypeMixin_tes> <dtype> @linkml:String ? ;
( $<DtypeMixin_tes> <dtype> @linkml:String * ;
rdf:type [ <DtypeMixin> ] ?
)
}
<Group> CLOSED {
( $<Group_tes> ( &<NamingMixin_tes> ;
rdf:type [ <NamingMixin> ] ? ;
<neurodata_type_def> @linkml:String ? ;
( $<Group_tes> ( <neurodata_type_def> @linkml:String ? ;
<neurodata_type_inc> @linkml:String ? ;
<name> @linkml:String ? ;
<default_name> @linkml:String ? ;
@ -152,7 +148,7 @@ linkml:Sparqlpath xsd:string
schema1:dateModified @linkml:Date ? ;
schema1:author @linkml:String + ;
schema1:email @linkml:String + ;
<schema> @<Schema> *
<schema_> @<Schema> *
) ;
rdf:type [ <Namespace> ] ?
)
@ -164,12 +160,6 @@ linkml:Sparqlpath xsd:string
)
}
<NamingMixin> {
( $<NamingMixin_tes> rdf:type . * ;
rdf:type [ <NamingMixin> ] ?
)
}
<ReferenceDtype> CLOSED {
( $<ReferenceDtype_tes> ( <target_type> @linkml:String ;
<reftype> @<ReftypeOptions> ?

View file

@ -15,7 +15,7 @@ CREATE TABLE "Attribute" (
CREATE TABLE "CompoundDtype" (
name TEXT NOT NULL,
doc TEXT NOT NULL,
dtype VARCHAR(11) NOT NULL,
dtype TEXT NOT NULL,
PRIMARY KEY (name, doc, dtype)
);
@ -77,8 +77,8 @@ CREATE TABLE "Namespace" (
date DATE,
author TEXT NOT NULL,
contact TEXT NOT NULL,
schema TEXT,
PRIMARY KEY (doc, name, full_name, version, date, author, contact, schema)
schema_ TEXT,
PRIMARY KEY (doc, name, full_name, version, date, author, contact, schema_)
);
CREATE TABLE "Namespaces" (

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "nwb_schema_language"
version = "0.1.0"
version = "0.1.1"
description = "Translation of the nwb-schema-language to LinkML"
authors = ["Jonny Saunders <j@nny.fyi>"]
license = "GNU GPL v3.0"

View file

@ -1,9 +1,9 @@
# Auto generated from nwb_schema_language.yaml by pythongen.py version: 0.0.1
# Generation date: 2023-08-18T00:36:55
# Schema: nwb_schema_language
# Generation date: 2023-08-30T20:54:02
# Schema: nwb-schema-language
#
# id: https://w3id.org/p2p_ld/nwb-schema-language
# description: Translation of the nwb_schema_language to LinkML
# description: Translation of the nwb-schema-language to LinkML
# license: GNU GPL v3.0
import dataclasses
@ -59,7 +59,7 @@ class Namespace(YAMLRoot):
contact: Union[str, List[str]] = None
full_name: Optional[str] = None
date: Optional[Union[str, XSDDate]] = None
schema: Optional[Union[Union[dict, "Schema"], List[Union[dict, "Schema"]]]] = empty_list()
schema_: Optional[Union[Union[dict, "Schema"], List[Union[dict, "Schema"]]]] = empty_list()
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.doc):
@ -95,9 +95,9 @@ class Namespace(YAMLRoot):
if self.date is not None and not isinstance(self.date, XSDDate):
self.date = XSDDate(self.date)
if not isinstance(self.schema, list):
self.schema = [self.schema] if self.schema is not None else []
self.schema = [v if isinstance(v, Schema) else Schema(**as_dict(v)) for v in self.schema]
if not isinstance(self.schema_, list):
self.schema_ = [self.schema_] if self.schema_ is not None else []
self.schema_ = [v if isinstance(v, Schema) else Schema(**as_dict(v)) for v in self.schema_]
super().__post_init__(**kwargs)
@ -251,7 +251,7 @@ class Attribute(YAMLRoot):
value: Optional[Union[dict, "AnyType"]] = None
default_value: Optional[Union[dict, "AnyType"]] = None
required: Optional[Union[bool, Bool]] = True
dtype: Optional[str] = None
dtype: Optional[Union[str, List[str]]] = empty_list()
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.name):
@ -275,8 +275,9 @@ class Attribute(YAMLRoot):
if self.required is not None and not isinstance(self.required, Bool):
self.required = Bool(self.required)
if self.dtype is not None and not isinstance(self.dtype, str):
self.dtype = str(self.dtype)
if not isinstance(self.dtype, list):
self.dtype = [self.dtype] if self.dtype is not None else []
self.dtype = [v if isinstance(v, str) else str(v) for v in self.dtype]
super().__post_init__(**kwargs)
@ -336,7 +337,7 @@ class Dataset(YAMLRoot):
quantity: Optional[str] = 1
linkable: Optional[Union[bool, Bool]] = None
attributes: Optional[Union[Union[dict, Attribute], List[Union[dict, Attribute]]]] = empty_list()
dtype: Optional[str] = None
dtype: Optional[Union[str, List[str]]] = empty_list()
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.doc):
@ -372,8 +373,9 @@ class Dataset(YAMLRoot):
self._normalize_inlined_as_dict(slot_name="attributes", slot_type=Attribute, key_name="name", keyed=False)
if self.dtype is not None and not isinstance(self.dtype, str):
self.dtype = str(self.dtype)
if not isinstance(self.dtype, list):
self.dtype = [self.dtype] if self.dtype is not None else []
self.dtype = [v if isinstance(v, str) else str(v) for v in self.dtype]
super().__post_init__(**kwargs)
@ -432,7 +434,7 @@ class CompoundDtype(YAMLRoot):
name: str = None
doc: str = None
dtype: Union[str, "FlatDtype"] = None
dtype: Union[str, List[str]] = None
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.name):
@ -447,8 +449,9 @@ class CompoundDtype(YAMLRoot):
if self._is_empty(self.dtype):
self.MissingRequiredField("dtype")
if not isinstance(self.dtype, FlatDtype):
self.dtype = FlatDtype(self.dtype)
if not isinstance(self.dtype, list):
self.dtype = [self.dtype] if self.dtype is not None else []
self.dtype = [v if isinstance(v, str) else str(v) for v in self.dtype]
super().__post_init__(**kwargs)
@ -462,27 +465,16 @@ class DtypeMixin(YAMLRoot):
class_name: ClassVar[str] = "DtypeMixin"
class_model_uri: ClassVar[URIRef] = NWB_SCHEMA_LANGUAGE.DtypeMixin
dtype: Optional[str] = None
dtype: Optional[Union[str, List[str]]] = empty_list()
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self.dtype is not None and not isinstance(self.dtype, str):
self.dtype = str(self.dtype)
if not isinstance(self.dtype, list):
self.dtype = [self.dtype] if self.dtype is not None else []
self.dtype = [v if isinstance(v, str) else str(v) for v in self.dtype]
super().__post_init__(**kwargs)
class NamingMixin(YAMLRoot):
"""
require either neurodata_type_def or name to be present
"""
_inherited_slots: ClassVar[List[str]] = []
class_class_uri: ClassVar[URIRef] = NWB_SCHEMA_LANGUAGE.NamingMixin
class_class_curie: ClassVar[str] = "nwb_schema_language:NamingMixin"
class_name: ClassVar[str] = "NamingMixin"
class_model_uri: ClassVar[URIRef] = NWB_SCHEMA_LANGUAGE.NamingMixin
AnyType = Any
# Enumerations
@ -645,7 +637,7 @@ slots.author = Slot(uri=SCHEMA.author, name="author", curie=SCHEMA.curie('author
slots.contact = Slot(uri=SCHEMA.email, name="contact", curie=SCHEMA.curie('email'),
model_uri=NWB_SCHEMA_LANGUAGE.contact, domain=None, range=Union[str, List[str]])
slots.schema = Slot(uri=NWB_SCHEMA_LANGUAGE.schema, name="schema", curie=NWB_SCHEMA_LANGUAGE.curie('schema'),
slots.schema = Slot(uri=NWB_SCHEMA_LANGUAGE.schema_, name="schema", curie=NWB_SCHEMA_LANGUAGE.curie('schema_'),
model_uri=NWB_SCHEMA_LANGUAGE.schema, domain=None, range=Optional[Union[Union[dict, Schema], List[Union[dict, Schema]]]])
slots.source = Slot(uri=NWB_SCHEMA_LANGUAGE.source, name="source", curie=NWB_SCHEMA_LANGUAGE.curie('source'),
@ -692,7 +684,7 @@ slots.links = Slot(uri=NWB_SCHEMA_LANGUAGE.links, name="links", curie=NWB_SCHEMA
model_uri=NWB_SCHEMA_LANGUAGE.links, domain=None, range=Optional[Union[Union[dict, Link], List[Union[dict, Link]]]])
slots.dtype = Slot(uri=NWB_SCHEMA_LANGUAGE.dtype, name="dtype", curie=NWB_SCHEMA_LANGUAGE.curie('dtype'),
model_uri=NWB_SCHEMA_LANGUAGE.dtype, domain=None, range=Optional[str])
model_uri=NWB_SCHEMA_LANGUAGE.dtype, domain=None, range=Optional[Union[str, List[str]]])
slots.dims = Slot(uri=NWB_SCHEMA_LANGUAGE.dims, name="dims", curie=NWB_SCHEMA_LANGUAGE.curie('dims'),
model_uri=NWB_SCHEMA_LANGUAGE.dims, domain=None, range=Optional[Union[str, List[str]]])
@ -728,4 +720,4 @@ slots.CompoundDtype_name = Slot(uri=NWB_SCHEMA_LANGUAGE.name, name="CompoundDtyp
model_uri=NWB_SCHEMA_LANGUAGE.CompoundDtype_name, domain=CompoundDtype, range=str)
slots.CompoundDtype_dtype = Slot(uri=NWB_SCHEMA_LANGUAGE.dtype, name="CompoundDtype_dtype", curie=NWB_SCHEMA_LANGUAGE.curie('dtype'),
model_uri=NWB_SCHEMA_LANGUAGE.CompoundDtype_dtype, domain=CompoundDtype, range=Union[str, "FlatDtype"])
model_uri=NWB_SCHEMA_LANGUAGE.CompoundDtype_dtype, domain=CompoundDtype, range=Union[str, List[str]])

View file

@ -135,6 +135,21 @@ class Schema(ConfiguredBaseModel):
doc: Optional[str] = Field(None)
class Group(ConfiguredBaseModel):
neurodata_type_def: Optional[str] = Field(None, description="""Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins""")
neurodata_type_inc: Optional[str] = Field(None, description="""Used alongside neurodata_type_def to indicate inheritance, naming, and mixins""")
name: Optional[str] = Field(None)
default_name: Optional[str] = Field(None)
doc: str = Field(..., description="""Description of corresponding object.""")
quantity: Optional[Union[QuantityEnum, int]] = Field(1)
linkable: Optional[bool] = Field(None)
attributes: Optional[List[Attribute]] = Field(default_factory=list)
datasets: Optional[List[Dataset]] = Field(default_factory=list)
groups: Optional[List[Group]] = Field(default_factory=list)
links: Optional[List[Link]] = Field(default_factory=list)
class Groups(ConfiguredBaseModel):
groups: Optional[List[Group]] = Field(default_factory=list)
@ -183,29 +198,7 @@ class Attribute(DtypeMixin):
dtype: Optional[Union[List[CompoundDtype], FlatDtype, ReferenceDtype]] = Field(default_factory=list)
class NamingMixin(ConfiguredBaseModel):
"""
require either neurodata_type_def or name to be present
"""
None
class Group(NamingMixin):
neurodata_type_def: Optional[str] = Field(None, description="""Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins""")
neurodata_type_inc: Optional[str] = Field(None, description="""Used alongside neurodata_type_def to indicate inheritance, naming, and mixins""")
name: Optional[str] = Field(None)
default_name: Optional[str] = Field(None)
doc: str = Field(..., description="""Description of corresponding object.""")
quantity: Optional[Union[QuantityEnum, int]] = Field(1)
linkable: Optional[bool] = Field(None)
attributes: Optional[List[Attribute]] = Field(default_factory=list)
datasets: Optional[List[Dataset]] = Field(default_factory=list)
groups: Optional[List[Group]] = Field(default_factory=list)
links: Optional[List[Link]] = Field(default_factory=list)
class Dataset(NamingMixin, DtypeMixin):
class Dataset(DtypeMixin):
neurodata_type_def: Optional[str] = Field(None, description="""Used alongside neurodata_type_inc to indicate inheritance, naming, and mixins""")
neurodata_type_inc: Optional[str] = Field(None, description="""Used alongside neurodata_type_def to indicate inheritance, naming, and mixins""")
@ -219,7 +212,6 @@ class Dataset(NamingMixin, DtypeMixin):
quantity: Optional[Union[QuantityEnum, int]] = Field(1)
linkable: Optional[bool] = Field(None)
attributes: Optional[List[Attribute]] = Field(default_factory=list)
datasets: Optional[List[Dataset]] = Field(default_factory=list)
dtype: Optional[Union[List[CompoundDtype], FlatDtype, ReferenceDtype]] = Field(default_factory=list)
@ -229,6 +221,7 @@ class Dataset(NamingMixin, DtypeMixin):
Namespace.update_forward_refs()
Namespaces.update_forward_refs()
Schema.update_forward_refs()
Group.update_forward_refs()
Groups.update_forward_refs()
Link.update_forward_refs()
Datasets.update_forward_refs()
@ -236,7 +229,5 @@ ReferenceDtype.update_forward_refs()
CompoundDtype.update_forward_refs()
DtypeMixin.update_forward_refs()
Attribute.update_forward_refs()
NamingMixin.update_forward_refs()
Group.update_forward_refs()
Dataset.update_forward_refs()

View file

@ -66,8 +66,6 @@ classes:
description: If source is present, namespace cannot be.
Group:
mixins:
- NamingMixin
slots:
- neurodata_type_def
- neurodata_type_inc
@ -110,7 +108,6 @@ classes:
Dataset:
mixins:
- DtypeMixin
- NamingMixin
slots:
- neurodata_type_def
- neurodata_type_inc
@ -124,7 +121,6 @@ classes:
- quantity
- linkable
- attributes
- groups
Datasets:
slots:
@ -164,17 +160,6 @@ classes:
dtype:
multivalued: false
NamingMixin:
mixin: true
description: require either neurodata_type_def or name to be present
rules:
- preconditions: { slot_conditions: { neurodata_type_def: { value_presence: ABSENT } } }
postconditions: { slot_conditions: { name: { required: true } } }
description: If not defining a new type, a name is required
- preconditions: { slot_conditions: { name: { value_presence: ABSENT } } }
postconditions: { slot_conditions: { neurodata_type_def: { required: true } } }
description: If a name is not given, must be defining a new type
AnyType:
class_uri: linkml:Any