class DatasetSchemaV3(CreatorMixinSchemaV3, EntitySchemaV3): """Dataset schema.""" class Meta: """Meta class.""" rdf_type = schema.Dataset model = Dataset unknown = EXCLUDE creators = fields.Nested(schema.creator, PersonSchemaV3, many=True) date_created = fields.DateTime(schema.dateCreated, missing=None) date_published = fields.DateTime(schema.datePublished, missing=None) description = fields.String(schema.description, missing=None) files = fields.Nested(schema.hasPart, DatasetFileSchemaV3, many=True) identifier = fields.String(schema.identifier) in_language = fields.Nested(schema.inLanguage, LanguageSchemaV5, missing=None) keywords = fields.List(schema.keywords, fields.String()) license = fields.Uri(schema.license, missing=None, allow_none=True) name = fields.String(schema.alternateName, missing=None) same_as = fields.Nested(schema.sameAs, UrlSchemaV5, missing=None) tags = fields.Nested(schema.subjectOf, DatasetTagSchemaV5, many=True) title = fields.String(schema.name) url = fields.String(schema.url) version = fields.String(schema.version, missing=None) @pre_load def fix_files_context(self, data, **kwargs): """Fix DatasetFile context for _label and external fields.""" from renku.core.utils.migrate import migrate_types data = migrate_types(data) if "@context" not in data: return data context = data["@context"] if not isinstance(context, dict) or "files" not in context: return data context.setdefault("rdfs", "http://www.w3.org/2000/01/rdf-schema#") context.setdefault("_label", "rdfs:label") files = data["@context"]["files"] if not isinstance(files, dict) or "@context" not in files: return data context = files["@context"] context.setdefault("rdfs", "http://www.w3.org/2000/01/rdf-schema#") context.setdefault("_label", "rdfs:label") context.setdefault("external", "renku:external") context.setdefault( "renku", "https://swissdatasciencecenter.github.io/renku-ontology#") return data
class CommitMixinSchemaV3(JsonLDSchema): """CommitMixin schema.""" _id = fields.Id(missing=None) _label = fields.String(rdfs.label, missing=None) _project = fields.Nested(schema.isPartOf, ProjectSchemaV3, missing=None) path = fields.String(prov.atLocation)
class CreatorMixinSchema(JsonLDSchema): """CreatorMixin schema.""" class Meta: """Meta class.""" unknown = EXCLUDE creator = fields.Nested(schema.creator, PersonSchema, many=True)
class DatasetSchemaV7(DatasetSchemaV3): """Dataset schema.""" class Meta: """Meta class.""" rdf_type = schema.Dataset model = Dataset unknown = EXCLUDE files = fields.Nested(schema.hasPart, DatasetFileSchemaV7, many=True)
class CommitMixinSchema(JsonLDSchema): """CommitMixin schema.""" class Meta: """Meta class.""" model = CommitMixin path = fields.String(prov.atLocation) _id = fields.Id(init_name='id') _label = fields.String(rdfs.label, init_name='label', missing=None) _project = fields.Nested(schema.isPartOf, ProjectSchema, init_name='project', missing=None)
class ProjectSchemaV3(JsonLDSchema): """Project Schema.""" class Meta: """Meta class.""" rdf_type = [prov.Location, schema.Project] model = Project unknown = EXCLUDE _id = fields.Id(missing=None) name = fields.String(schema.name, missing=None) created = fields.DateTime(schema.dateCreated, missing=None) updated = fields.DateTime(schema.dateUpdated, missing=None) version = fields.String(schema.schemaVersion, missing=1) creator = fields.Nested(schema.creator, PersonSchemaV3, missing=None)
class DatasetFileSchemaV3(EntitySchemaV3): """DatasetFile schema.""" class Meta: """Meta class.""" rdf_type = schema.DigitalDocument model = DatasetFile unknown = EXCLUDE added = fields.DateTime(schema.dateCreated) based_on = fields.Nested(schema.isBasedOn, "DatasetFileSchemaV3", missing=None) name = fields.String(schema.name, missing=None) url = fields.String(schema.url, missing=None) external = fields.Boolean(renku.external, missing=False)
class DatasetSchema(EntitySchema, CreatorMixinSchema): """Dataset schema.""" class Meta: """Meta class.""" rdf_type = schema.Dataset model = Dataset unknown = EXCLUDE _id = fields.Id(init_name='id', missing=None) _label = fields.String(rdfs.label, init_name='label', missing=None) date_published = fields.DateTime(schema.datePublished, missing=None) description = fields.String(schema.description, missing=None) identifier = fields.String(schema.identifier) in_language = fields.Nested( schema.inLanguage, LanguageSchema, missing=None ) keywords = fields.List(schema.keywords, fields.String()) license = fields.Uri(schema.license, missing=None, allow_none=True) name = fields.String(schema.name) url = fields.String(schema.url) version = fields.String(schema.version, missing=None) created = fields.DateTime(schema.dateCreated, missing=None) files = fields.Nested(schema.hasPart, DatasetFileSchema, many=True) tags = fields.Nested(schema.subjectOf, DatasetTagSchema, many=True) same_as = fields.Nested(schema.sameAs, UrlSchema, missing=None) short_name = fields.String(schema.alternateName) @pre_load def fix_files_context(self, data, **kwargs): """Fix DatasetFile context for _label and external fields.""" context = None if '@context' not in data: return data context = data['@context'] if not isinstance(context, dict) or 'files' not in context: return data context.setdefault('rdfs', 'http://www.w3.org/2000/01/rdf-schema#') files = data['@context']['files'] if not isinstance(files, dict) or '@context' not in files: return data context = files['@context'] context.setdefault('rdfs', 'http://www.w3.org/2000/01/rdf-schema#') context.setdefault('_label', 'rdfs:label') context.setdefault('external', 'renku:external') context.setdefault( 'renku', 'https://swissdatasciencecenter.github.io/renku-ontology#' ) return data @pre_load def migrate_types(self, data, **kwargs): """Fix types.""" from renku.core.utils.migrate import migrate_types return migrate_types(data)
class CreatorMixinSchemaV3(JsonLDSchema): """CreatorMixin schema.""" creators = fields.Nested(schema.creator, PersonSchemaV3, many=True)
class DatasetFileSchemaV7(DatasetFileSchemaV3): """DatasetFile schema.""" based_on = fields.Nested(schema.isBasedOn, "DatasetFileSchemaV7", missing=None) source = fields.String(renku.source, missing=None)