{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# User/Issue model from [ShEx primer](http://shex.io/shex-primer/#simple-expressions)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2021-01-05T21:24:24.644220Z", "iopub.status.busy": "2021-01-05T21:24:24.643660Z", "iopub.status.idle": "2021-01-05T21:24:25.782030Z", "shell.execute_reply": "2021-01-05T21:24:25.782504Z" } }, "outputs": [], "source": [ "!pip install biolinkml --upgrade --disable-pip-version-check -q" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2021-01-05T21:24:25.789824Z", "iopub.status.busy": "2021-01-05T21:24:25.789150Z", "iopub.status.idle": "2021-01-05T21:24:26.313052Z", "shell.execute_reply": "2021-01-05T21:24:26.313332Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "# Auto generated from None by pythongen.py version: 0.9.0\n", "# Generation date: 2021-01-05 15:24\n", "# Schema: issue\n", "#\n", "# id: http://shex.io/shex-primer/issueshape\n", "# description:\n", "# license:\n", "\n", "import dataclasses\n", "import sys\n", "import re\n", "from typing import Optional, List, Union, Dict, ClassVar, Any\n", "from dataclasses import dataclass\n", "from biolinkml.meta import EnumDefinition, PermissibleValue, PvFormulaOptions\n", "\n", "from biolinkml.utils.slot import Slot\n", "from biolinkml.utils.metamodelcore import empty_list, empty_dict, bnode\n", "from biolinkml.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int\n", "if sys.version_info < (3, 7, 6):\n", " from biolinkml.utils.dataclass_extensions_375 import dataclasses_init_fn_with_kwargs\n", "else:\n", " from biolinkml.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs\n", "from biolinkml.utils.formatutils import camelcase, underscore, sfx\n", "from biolinkml.utils.enumerations import EnumDefinitionImpl\n", "from rdflib import Namespace, URIRef\n", "from biolinkml.utils.curienamespace import CurieNamespace\n", "\n", "\n", "metamodel_version = \"1.7.0\"\n", "\n", "# Overwrite dataclasses _init_fn to add **kwargs in __init__\n", "dataclasses._init_fn = dataclasses_init_fn_with_kwargs\n", "\n", "# Namespaces\n", "EX = CurieNamespace('ex', 'http://ex.example/#')\n", "FOAF = CurieNamespace('foaf', 'http://xmlns.com/foaf/0.1/')\n", "ISSUE = CurieNamespace('issue', 'http://shex.io/shex-primer/issue/')\n", "XSD = CurieNamespace('xsd', 'http://www.w3.org/2001/XMLSchema#')\n", "DEFAULT_ = ISSUE\n", "\n", "\n", "# Types\n", "class Str(str):\n", " type_class_uri = XSD.string\n", " type_class_curie = \"xsd:string\"\n", " type_name = \"str\"\n", " type_model_uri = ISSUE.Str\n", "\n", "\n", "class Int(int):\n", " type_class_uri = XSD.integer\n", " type_class_curie = \"xsd:integer\"\n", " type_name = \"int\"\n", " type_model_uri = ISSUE.Int\n", "\n", "\n", "# Class references\n", "\n", "\n", "\n", "class Person(YAMLRoot):\n", " _inherited_slots: ClassVar[List[str]] = []\n", "\n", " class_class_uri: ClassVar[URIRef] = ISSUE.Person\n", " class_class_curie: ClassVar[str] = \"issue:Person\"\n", " class_name: ClassVar[str] = \"person\"\n", " class_model_uri: ClassVar[URIRef] = ISSUE.Person\n", "\n", "\n", "class Enrolee(Person):\n", " _inherited_slots: ClassVar[List[str]] = []\n", "\n", " class_class_uri: ClassVar[URIRef] = ISSUE.Enrolee\n", " class_class_curie: ClassVar[str] = \"issue:Enrolee\"\n", " class_name: ClassVar[str] = \"enrolee\"\n", " class_model_uri: ClassVar[URIRef] = ISSUE.Enrolee\n", "\n", "\n", "# Enumerations\n", "\n", "\n", "# Slots\n", "class slots:\n", " pass\n", "\n", "slots.name = Slot(uri=ISSUE.name, name=\"name\", curie=ISSUE.curie('name'),\n", " model_uri=ISSUE.name, domain=Person, range=Union[dict, Person])\n", "\n", "slots.age = Slot(uri=FOAF.age, name=\"age\", curie=FOAF.curie('age'),\n", " model_uri=ISSUE.age, domain=Enrolee, range=Optional[int])\n", "\n", "slots.hasGuardian = Slot(uri=ISSUE.hasGuardian, name=\"hasGuardian\", curie=ISSUE.curie('hasGuardian'),\n", " model_uri=ISSUE.hasGuardian, domain=Enrolee, range=Union[Union[dict, Person], List[Union[dict, Person]]])\n", "BASE \n", "PREFIX rdf: \n", "PREFIX xsd: \n", "\n", "\n", " xsd:string\n", "\n", " xsd:integer\n", "\n", " CLOSED {\n", " ( $ ( & ;\n", " rdf:type [ ] ?\n", " ) ;\n", " rdf:type [ ] ?\n", " )\n", "}\n", "\n", " (\n", " CLOSED {\n", " ( $ rdf:type . * ;\n", " rdf:type [ ] ?\n", " )\n", " } OR @\n", ")\n", "\n", "\n", "\n" ] } ], "source": [ "from biolinkml.generators.shexgen import ShExGenerator\n", "from biolinkml.generators.pythongen import PythonGenerator\n", "\n", "model = \"\"\"\n", "id: http://shex.io/shex-primer/issueshape\n", "title: Issue Shape from ShEx primer\n", "name: issue\n", "version: 0.1.0\n", "\n", "prefixes:\n", " issue: http://shex.io/shex-primer/issue/\n", " ex: http://ex.example/#\n", " xsd: http://www.w3.org/2001/XMLSchema#\n", " foaf: http://xmlns.com/foaf/0.1/\n", "\n", "default_prefix: issue\n", "\n", "default_range: str\n", "\n", "types:\n", " str:\n", " base: str\n", " uri: xsd:string\n", "\n", " int:\n", " base: int\n", " uri: xsd:integer\n", "\n", "classes:\n", " person:\n", " enrolee:\n", " is_a: person\n", "\n", "slots:\n", " name:\n", " domain: person\n", " range: str\n", " key: true\n", "\n", " age:\n", " domain: enrolee\n", " range: int\n", " slot_uri: foaf:age\n", "\n", " hasGuardian:\n", " domain: enrolee\n", " range: person\n", " multivalued: true\n", " required: true\n", "\n", "\"\"\"\n", "print(PythonGenerator(model).serialize())\n", "print(ShExGenerator(model).serialize(collections=False))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 1 }