diff --git a/docs/developers/operations.ipynb b/docs/developers/operations.ipynb index a64f244..678ff11 100644 --- a/docs/developers/operations.ipynb +++ b/docs/developers/operations.ipynb @@ -1,187 +1,187 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "edcc1fd6-2474-4d15-8355-084ef85bc748", - "metadata": {}, - "source": [ - "# Operations development" - ] - }, - { - "cell_type": "markdown", - "id": "e191786a-786a-418e-886a-a4da0c2d741e", - "metadata": {}, - "source": [ - "SimPhoNy operations are actions (written in Python) that can be executed on\n", - "demand on any ontology individual belonging to the ontology class they\n", - "are defined for." - ] - }, - { - "cell_type": "markdown", - "id": "7ea449f9-bc08-4ddc-a8a8-13c6d3ade2ef", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "File uploads and downloads in SimPhoNy are an example of SimPhoNy operations.\n", - "Head to the [assertional knowledge](../usage/assertional_knowledge.html#Operations) section to see them in action.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "ee275d73-f2ef-4418-bc94-cec8458c803c", - "metadata": {}, - "source": [ - "\n", - "SimPhoNy operations are distributed as (or as part of) Python packages. \n", - "Developing operations for an ontology class is fairly simple. To do so, import the [Operations abstract class](../api_reference.md#simphony_osp.development.Operations) from the `simphony_osp.development` module, and create an implementation by subclassing it.\n", - "\n", - "Then, define an `iri` attribute having as value the IRI of the ontology class that the\n", - "operation should be associated to. Every public method ([not starting with\n", - "an underscore](https://peps.python.org/pep-0008/#method-names-and-instance-variables)) defined on the implementation is automatically detected and\n", - "assigned as an operation to said ontology class. The\n", - "[ontology individual object](../usage/assertional_knowledge.ipynb#Ontology-individual-objects)\n", - "on which the operation is called is available as the private attribute\n", - "`_individual` on every instance of the implementation. For a specific \n", - "ontology individual, the implementation gets instantiated the first time that \n", - "any operation defined on it is called by the user.\n", - "\n", - "Finally, define an\n", - "[entry point](https://packaging.python.org/en/latest/specifications/entry-points/#entry-points-specification)\n", - "(or many if implementing operations for several ontology classes) under the\n", - "`simphony_osp.ontology.operations`\n", - "[group](https://packaging.python.org/en/latest/specifications/entry-points/#data-model)\n", - "that points to your\n", - "implementation of the `Operations` abstract class.\n", - "\n", - "An example implementation of an operation that takes advantage of\n", - "[geopy](https://pypi.org/project/geopy/) to compute the distance between \n", - "two points on Earth defined using the \n", - "[WGS84 Geo Positioning vocabulary](https://www.w3.org/2003/01/geo/wgs84_pos)\n", - "is shown below." - ] - }, - { - "cell_type": "markdown", - "id": "0fffa052-186a-46b7-9076-8acfed6b1ee0", - "metadata": {}, - "source": [ - "```python\n", - "\"\"\"Operations for classes from the WGS84 Geo Positioning vocabulary.\"\"\"\n", - "\n", - "from geopy import distance\n", - "from simphony_osp.namespaces import wgs84_pos\n", - "from simphony_osp.ontology import OntologyIndividual\n", - "from simphony_osp.ontology.operations import Operations\n", - "\n", - "\n", - "class Wgs84Pos(Operations):\n", - " \"\"\"Operations for the Point ontology class.\"\"\"\n", - "\n", - " iri = wgs84_pos.Point.iri\n", - "\n", - " def distance(self, other: OntologyIndividual) -> float:\n", - " \"\"\"Compute the distance between two points on Earth.\n", - " \n", - " Args:\n", - " other: Another point with respect to which the distance will be computed. \n", - " \n", - " Returns:\n", - " The distance between this point and the given one in km.\n", - " \"\"\"\n", - " lat_self = float(self._individual[wgs84_pos.latitude].one())\n", - " long_self = float(self._individual[wgs84_pos.longitude].one())\n", - " lat_other = float(other[wgs84_pos.latitude].one())\n", - " long_other = float(other[wgs84_pos.longitude].one())\n", - " return distance.geodesic(\n", - " (lat_self, long_self),\n", - " (lat_other, long_other),\n", - " ellipsoid=\"WGS-84\"\n", - " ).km\n", - "\n", - "```" - ] - }, - { - "cell_type": "markdown", - "id": "744e037f-aabe-4bdf-a994-8787f3f039b1", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "Remember that the implementation above is still not enough for the operation to\n", - "work: the corresponding \n", - "[entry point](https://packaging.python.org/en/latest/specifications/entry-points/#entry-points-specification)\n", - "for `Wgs84Pos` must have been defined and the `wgs84_pos` vocabulary needs to be installed using [pico](../usage/ontologies/pico.html).\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "d3db93d6-e26f-4831-b9a2-d9223cc4a51f", - "metadata": {}, - "source": [ - "The operation can be used as follows." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "40a97048-80ea-4d99-8711-3ecd6ab5598b", - "metadata": {}, - "outputs": [ + "cells": [ + { + "cell_type": "markdown", + "id": "edcc1fd6-2474-4d15-8355-084ef85bc748", + "metadata": {}, + "source": [ + "# Operations development" + ] + }, + { + "cell_type": "markdown", + "id": "e191786a-786a-418e-886a-a4da0c2d741e", + "metadata": {}, + "source": [ + "SimPhoNy operations are actions (written in Python) that can be executed on\n", + "demand on any ontology individual belonging to the ontology class they\n", + "are defined for." + ] + }, { - "data": { - "text/plain": [ - "417.4695920611045" + "cell_type": "markdown", + "id": "7ea449f9-bc08-4ddc-a8a8-13c6d3ade2ef", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "File uploads and downloads in SimPhoNy are an example of SimPhoNy operations.\n", + "Head to the [assertional knowledge](../usage/assertional_knowledge.html#Operations) section to see them in action.\n", + " \n", + "
" ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" + }, + { + "cell_type": "markdown", + "id": "ee275d73-f2ef-4418-bc94-cec8458c803c", + "metadata": {}, + "source": [ + "\n", + "SimPhoNy operations are distributed as (or as part of) Python packages. \n", + "Developing operations for an ontology class is fairly simple. To do so, import the [Operations abstract class](../api_reference.md#simphony_osp.development.Operations) from the `simphony_osp.development` module, and create an implementation by subclassing it.\n", + "\n", + "Then, define an `iri` attribute having as value the IRI of the ontology class that the\n", + "operation should be associated to. Every public method ([not starting with\n", + "an underscore](https://peps.python.org/pep-0008/#method-names-and-instance-variables)) defined on the implementation is automatically detected and\n", + "assigned as an operation to said ontology class. The\n", + "[ontology individual object](../usage/assertional_knowledge.ipynb#Ontology-individual-objects)\n", + "on which the operation is called is available as the private attribute\n", + "`_individual` on every instance of the implementation. For a specific \n", + "ontology individual, the implementation gets instantiated the first time that \n", + "any operation defined on it is called by the user.\n", + "\n", + "Finally, define an\n", + "[entry point](https://packaging.python.org/en/latest/specifications/entry-points/#entry-points-specification)\n", + "(or many if implementing operations for several ontology classes) under the\n", + "`simphony_osp.ontology.operations`\n", + "[group](https://packaging.python.org/en/latest/specifications/entry-points/#data-model)\n", + "that points to your\n", + "implementation of the `Operations` abstract class.\n", + "\n", + "An example implementation of an operation that takes advantage of\n", + "[geopy](https://pypi.org/project/geopy/) to compute the distance between \n", + "two points on Earth defined using the \n", + "[WGS84 Geo Positioning vocabulary](https://www.w3.org/2003/01/geo/wgs84_pos)\n", + "is shown below." + ] + }, + { + "cell_type": "markdown", + "id": "0fffa052-186a-46b7-9076-8acfed6b1ee0", + "metadata": {}, + "source": [ + "```python\n", + "\"\"\"Operations for classes from the WGS84 Geo Positioning vocabulary.\"\"\"\n", + "\n", + "from geopy import distance\n", + "from simphony_osp.namespaces import wgs84_pos\n", + "from simphony_osp.ontology import OntologyIndividual\n", + "from simphony_osp.ontology.operations import Operations\n", + "\n", + "\n", + "class Wgs84Pos(Operations):\n", + " \"\"\"Operations for the Point ontology class.\"\"\"\n", + "\n", + " iri = wgs84_pos.Point.iri\n", + "\n", + " def distance(self, other: OntologyIndividual) -> float:\n", + " \"\"\"Compute the distance between two points on Earth.\n", + " \n", + " Args:\n", + " other: Another point with respect to which the distance will be computed. \n", + " \n", + " Returns:\n", + " The distance between this point and the given one in km.\n", + " \"\"\"\n", + " lat_self = float(self._individual[wgs84_pos.latitude].one())\n", + " long_self = float(self._individual[wgs84_pos.longitude].one())\n", + " lat_other = float(other[wgs84_pos.latitude].one())\n", + " long_other = float(other[wgs84_pos.longitude].one())\n", + " return distance.geodesic(\n", + " (lat_self, long_self),\n", + " (lat_other, long_other),\n", + " ellipsoid=\"WGS-84\"\n", + " ).km\n", + "\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "744e037f-aabe-4bdf-a994-8787f3f039b1", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "Remember that the implementation above is still not enough for the operation to\n", + "work: the corresponding \n", + "[entry point](https://packaging.python.org/en/latest/specifications/entry-points/#entry-points-specification)\n", + "for `Wgs84Pos` must have been defined and the `wgs84_pos` vocabulary needs to be installed using [pico](../usage/ontologies/pico.html).\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "d3db93d6-e26f-4831-b9a2-d9223cc4a51f", + "metadata": {}, + "source": [ + "The operation can be used as follows." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "40a97048-80ea-4d99-8711-3ecd6ab5598b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "417.4695920611045" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.namespaces import wgs84_pos\n", + "\n", + "location_freiburg = wgs84_pos.Point()\n", + "location_freiburg[wgs84_pos.latitude] = 47.997791\n", + "location_freiburg[wgs84_pos.longitude] = 7.842609\n", + "\n", + "location_paris = wgs84_pos.Point()\n", + "location_paris[wgs84_pos.latitude] = 48.85333\n", + "location_paris[wgs84_pos.longitude] = 2.34885\n", + "\n", + "location_freiburg.operations.distance(location_paris)" + ] + } + ], + "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.8.12" } - ], - "source": [ - "from simphony_osp.namespaces import wgs84_pos\n", - "\n", - "location_freiburg = wgs84_pos.Point()\n", - "location_freiburg[wgs84_pos.latitude] = 47.997791\n", - "location_freiburg[wgs84_pos.longitude] = 7.842609\n", - "\n", - "location_paris = wgs84_pos.Point()\n", - "location_paris[wgs84_pos.latitude] = 48.85333\n", - "location_paris[wgs84_pos.longitude] = 2.34885\n", - "\n", - "location_freiburg.operations.distance(location_paris)" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/introduction/quickstart.ipynb b/docs/introduction/quickstart.ipynb index b26eebf..268e578 100644 --- a/docs/introduction/quickstart.ipynb +++ b/docs/introduction/quickstart.ipynb @@ -1,612 +1,612 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "803ff440-2093-4455-96ba-214d9fc0f91b", - "metadata": {}, - "source": [ - "# Quickstart" - ] - }, - { - "cell_type": "markdown", - "id": "1921410c-6d62-4322-abe9-8f0390368168", - "metadata": {}, - "source": [ - "
\n", - " \n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fintroduction%2Fquickstart.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
\n", - "\n", - "
\n", - "
Tip
\n", - " \n", - "Using the button above, you can launch a Jupyter notebook to follow this tutorial without even having to install SimPhoNy.\n", - " \n", - "
\n", - "\n", - "\n", - "This tutorial offers a quick first-contact with SimPhoNy. The learning objectives are:\n", - "\n", - "- Convey the purpose of SimPhoNy\n", - "- Manage the installed ontologies\n", - "- Use the installed ontologies to instantiate ontology individuals\n", - "- Demonstrate the usage of wrappers to achieve interoperability\n", - "\n", - "Following the tutorial on your own machine requires the installation of [SimPhoNy](../installation.md#installation) and the [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrapper. We recommend that you use the button above to follow the tutorial online using Binder." - ] - }, - { - "cell_type": "markdown", - "id": "648d8664-4cac-404d-9580-3ae9cd0a6b5c", - "metadata": {}, - "source": [ - "## Ontologies" - ] - }, - { - "cell_type": "markdown", - "id": "8d7e260f-ecb6-487b-b550-47677d2821c1", - "metadata": {}, - "source": [ - "SimPhoNy enables you to manage data that is based on ontologies. This means that all information is represented in terms of _ontology individuals_. Individuals belong to a specific _ontology class_, have specific _attributes_ and can be connected to other individuals through _relationships_. Classes, attributes and relationships are defined in ontologies. Therefore, in order for SimPhoNy to be able to properly interpret the data, such ontologies need to be installed. For that purpose, SimPhoNy includes an ontology management tool called _pico_." - ] - }, - { - "cell_type": "markdown", - "id": "415d9ee0-6672-482a-a8d7-f0a2f77ed124", - "metadata": {}, - "source": [ - "In this tutorial, you will work, among others, with the SimLAMMPS wrapper. This wrapper only understands data based on the SimLAMMPS ontology, which is included with it. Therefore, you will start by installing such ontology." - ] - }, - { - "cell_type": "markdown", - "id": "98b3f4e3-2943-46dc-8c30-41870e2e2183", - "metadata": {}, - "source": [ - "_pico_ works with so-called \"ontology packages\". Ontology packages are just a pointer to an ontology file with some additional metadata defined on it, such as the namespaces that the ontology includes or a name for the package. You can learn to create your own packages here." - ] - }, - { - "cell_type": "markdown", - "id": "00fcc98d-b3a7-4c1d-9b9f-af3edebd9c01", - "metadata": {}, - "source": [ - "To install the desired ontology use the command `pico install` and provide the path to the ontology package." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "5a9b1ce4-e9bb-4c59-afd6-0e4e733a0bd3", - "metadata": {}, - "outputs": [], - "source": [ - "# if you are running the tutorial online using Binder, then the simlammps\n", - "# ontology is already pre-installed\n", - "\n", - "# otherwise, download `simlammps.ttl` and `simlammps.yml` from \n", - "# https://github.com/simphony/simlammps/tree/v4.0.0/simphony_osp_simlammps\n", - "# and run\n", - "\n", - "#!pico install simlammps.yml" - ] - }, - { - "cell_type": "markdown", - "id": "bd1bd1a5-8cdf-4a46-b86a-f58eb44573ab", - "metadata": {}, - "source": [ - "_pico_ will install the ontology. After the installation is complete, it is listed among the installed ontology packages when running the `pico list` command." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "320f4159-f306-4755-a1e2-c1b5ff97e7ae", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Packages:\n", - "\t- simlammps\n", - "Namespaces:\n", - "\t- simphony\n", - "\t- owl\n", - "\t- rdfs\n", - "\t- simlammps\n" - ] - } - ], - "source": [ - "!pico list" - ] - }, - { - "cell_type": "markdown", - "id": "489d9c00-fd53-4751-a389-b2bffe9c9517", - "metadata": {}, - "source": [ - "That's all! Everything is ready to start using SimPhoNy. " - ] - }, - { - "cell_type": "markdown", - "id": "7501ee0c-23f5-40c4-962d-2f7cdb392466", - "metadata": {}, - "source": [ - "## Data and sessions" - ] - }, - { - "cell_type": "markdown", - "id": "ede3e762-ce82-477f-aa9f-4a300020de4d", - "metadata": {}, - "source": [ - "The simplest way to start working with some data is the following.\n", - "\n", - "1. Import an installed _ontology namespace_. Namespaces agglomerate the ontology classes, relationships, and attributes included in an ontology. Namespaces come bundled with ontology packages, so that one ontology package can provide several namespaces.\n", - "2. Retrieve a class from the namespace and use it to create an ontology individual.\n", - "3. Assign attributes or connect the individual with others.\n", - "\n", - "In the example below, first the `simlammps` namespace from the previously installed ontology is imported, then two ontology individuals of classes _Atom_ and _Position_ are created. After that, the individual of class Atom is linked to the individual of class Position through the relationship _hasPart_, and finally some coordinates are assigned to the individual of class Position." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "d81a8471-2c97-48d3-b2ca-50c7cdf5a780", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import simlammps\n", - "\n", - "atom, position = simlammps.Atom(), simlammps.Position(vector=[1, 0, 3])\n", - "atom[simlammps.hasPart] = position\n", - "\n", - "atom.label = \"My Atom\"\n", - "position.label = \"My Atom's position\"" - ] - }, - { - "cell_type": "markdown", - "id": "586d7063-5034-4cb2-b210-97b8b235ad14", - "metadata": {}, - "source": [ - "SimPhoNy includes a visualization tool that can draw a graph containing any ontology individuals you desire, their attributes, and the relationships connecting them. Using it, the dataset that has just been created may be visualized." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "f214d5c7-85e2-4396-8183-b32202e39968", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-project.eu_entity#b9074f9e-6bd4-4eef-b8ae-78fd4d1d86cb\n", - "\n", - "My Atom's position\n", - "classes: Position (simlammps)\n", - "Vector: [1 0 3]\n", - "session: 0x55899b8cab40\n", - "\n", - "\n", - "\n", - "https___www.simphony-project.eu_entity#63f477ea-dfc5-48c7-8227-60b71cc65cb6\n", - "\n", - "My Atom\n", - "classes: Atom (simlammps)\n", - "session: 0x55899b8cab40\n", - "\n", - "\n", - "\n", - "https___www.simphony-project.eu_entity#63f477ea-dfc5-48c7-8227-60b71cc65cb6->https___www.simphony-project.eu_entity#b9074f9e-6bd4-4eef-b8ae-78fd4d1d86cb\n", - "\n", - "\n", - "has part (simlammps)\n", - "\n", - "\n", - "\n" + "cells": [ + { + "cell_type": "markdown", + "id": "803ff440-2093-4455-96ba-214d9fc0f91b", + "metadata": {}, + "source": [ + "# Quickstart" + ] + }, + { + "cell_type": "markdown", + "id": "1921410c-6d62-4322-abe9-8f0390368168", + "metadata": {}, + "source": [ + "
\n", + " \n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fintroduction%2Fquickstart.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
\n", + "\n", + "
\n", + "
Tip
\n", + " \n", + "Using the button above, you can launch a Jupyter notebook to follow this tutorial without even having to install SimPhoNy.\n", + " \n", + "
\n", + "\n", + "\n", + "This tutorial offers a quick first-contact with SimPhoNy. The learning objectives are:\n", + "\n", + "- Convey the purpose of SimPhoNy\n", + "- Manage the installed ontologies\n", + "- Use the installed ontologies to instantiate ontology individuals\n", + "- Demonstrate the usage of wrappers to achieve interoperability\n", + "\n", + "Following the tutorial on your own machine requires the installation of [SimPhoNy](../installation.md#installation) and the [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrapper. We recommend that you use the button above to follow the tutorial online using Binder." + ] + }, + { + "cell_type": "markdown", + "id": "648d8664-4cac-404d-9580-3ae9cd0a6b5c", + "metadata": {}, + "source": [ + "## Ontologies" + ] + }, + { + "cell_type": "markdown", + "id": "8d7e260f-ecb6-487b-b550-47677d2821c1", + "metadata": {}, + "source": [ + "SimPhoNy enables you to manage data that is based on ontologies. This means that all information is represented in terms of _ontology individuals_. Individuals belong to a specific _ontology class_, have specific _attributes_ and can be connected to other individuals through _relationships_. Classes, attributes and relationships are defined in ontologies. Therefore, in order for SimPhoNy to be able to properly interpret the data, such ontologies need to be installed. For that purpose, SimPhoNy includes an ontology management tool called _pico_." + ] + }, + { + "cell_type": "markdown", + "id": "415d9ee0-6672-482a-a8d7-f0a2f77ed124", + "metadata": {}, + "source": [ + "In this tutorial, you will work, among others, with the SimLAMMPS wrapper. This wrapper only understands data based on the SimLAMMPS ontology, which is included with it. Therefore, you will start by installing such ontology." + ] + }, + { + "cell_type": "markdown", + "id": "98b3f4e3-2943-46dc-8c30-41870e2e2183", + "metadata": {}, + "source": [ + "_pico_ works with so-called \"ontology packages\". Ontology packages are just a pointer to an ontology file with some additional metadata defined on it, such as the namespaces that the ontology includes or a name for the package. You can learn to create your own packages here." + ] + }, + { + "cell_type": "markdown", + "id": "00fcc98d-b3a7-4c1d-9b9f-af3edebd9c01", + "metadata": {}, + "source": [ + "To install the desired ontology use the command `pico install` and provide the path to the ontology package." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "5a9b1ce4-e9bb-4c59-afd6-0e4e733a0bd3", + "metadata": {}, + "outputs": [], + "source": [ + "# if you are running the tutorial online using Binder, then the simlammps\n", + "# ontology is already pre-installed\n", + "\n", + "# otherwise, download `simlammps.ttl` and `simlammps.yml` from \n", + "# https://github.com/simphony/simlammps/tree/v4.0.0/simphony_osp_simlammps\n", + "# and run\n", + "\n", + "#!pico install simlammps.yml" + ] + }, + { + "cell_type": "markdown", + "id": "bd1bd1a5-8cdf-4a46-b86a-f58eb44573ab", + "metadata": {}, + "source": [ + "_pico_ will install the ontology. After the installation is complete, it is listed among the installed ontology packages when running the `pico list` command." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "320f4159-f306-4755-a1e2-c1b5ff97e7ae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Packages:\n", + "\t- simlammps\n", + "Namespaces:\n", + "\t- simphony\n", + "\t- owl\n", + "\t- rdfs\n", + "\t- simlammps\n" + ] + } ], - "text/plain": [ - "" + "source": [ + "!pico list" + ] + }, + { + "cell_type": "markdown", + "id": "489d9c00-fd53-4751-a389-b2bffe9c9517", + "metadata": {}, + "source": [ + "That's all! Everything is ready to start using SimPhoNy. " + ] + }, + { + "cell_type": "markdown", + "id": "7501ee0c-23f5-40c4-962d-2f7cdb392466", + "metadata": {}, + "source": [ + "## Data and sessions" + ] + }, + { + "cell_type": "markdown", + "id": "ede3e762-ce82-477f-aa9f-4a300020de4d", + "metadata": {}, + "source": [ + "The simplest way to start working with some data is the following.\n", + "\n", + "1. Import an installed _ontology namespace_. Namespaces agglomerate the ontology classes, relationships, and attributes included in an ontology. Namespaces come bundled with ontology packages, so that one ontology package can provide several namespaces.\n", + "2. Retrieve a class from the namespace and use it to create an ontology individual.\n", + "3. Assign attributes or connect the individual with others.\n", + "\n", + "In the example below, first the `simlammps` namespace from the previously installed ontology is imported, then two ontology individuals of classes _Atom_ and _Position_ are created. After that, the individual of class Atom is linked to the individual of class Position through the relationship _hasPart_, and finally some coordinates are assigned to the individual of class Position." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d81a8471-2c97-48d3-b2ca-50c7cdf5a780", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import simlammps\n", + "\n", + "atom, position = simlammps.Atom(), simlammps.Position(vector=[1, 0, 3])\n", + "atom[simlammps.hasPart] = position\n", + "\n", + "atom.label = \"My Atom\"\n", + "position.label = \"My Atom's position\"" + ] + }, + { + "cell_type": "markdown", + "id": "586d7063-5034-4cb2-b210-97b8b235ad14", + "metadata": {}, + "source": [ + "SimPhoNy includes a visualization tool that can draw a graph containing any ontology individuals you desire, their attributes, and the relationships connecting them. Using it, the dataset that has just been created may be visualized." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "f214d5c7-85e2-4396-8183-b32202e39968", + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-project.eu_entity#b9074f9e-6bd4-4eef-b8ae-78fd4d1d86cb\n", + "\n", + "My Atom's position\n", + "classes: Position (simlammps)\n", + "Vector: [1 0 3]\n", + "session: 0x55899b8cab40\n", + "\n", + "\n", + "\n", + "https___www.simphony-project.eu_entity#63f477ea-dfc5-48c7-8227-60b71cc65cb6\n", + "\n", + "My Atom\n", + "classes: Atom (simlammps)\n", + "session: 0x55899b8cab40\n", + "\n", + "\n", + "\n", + "https___www.simphony-project.eu_entity#63f477ea-dfc5-48c7-8227-60b71cc65cb6->https___www.simphony-project.eu_entity#b9074f9e-6bd4-4eef-b8ae-78fd4d1d86cb\n", + "\n", + "\n", + "has part (simlammps)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.tools import semantic2dot\n", + "\n", + "semantic2dot(atom, position)" + ] + }, + { + "cell_type": "markdown", + "id": "2cf6770f-8708-4d2a-acc3-b346fea9e826", + "metadata": {}, + "source": [ + "But... Where are actually the atom and the position stored? If a new atom is created running `atom = simlammps.Atom()` again, what happens to the old atom, how can it be retrieved?" + ] + }, + { + "cell_type": "markdown", + "id": "d57e226b-f906-4be7-b434-953c26dae804", + "metadata": {}, + "source": [ + "SimPhoNy stores data in the so-called _sessions_. You may think of a session as a \"box\" were ontology idividuals can be placed. The magic lies within the fact that sessions can provide _views_ into different data sources and software products, thanks to the SimPhoNy Wrapper mechanism. This means that you see a \"box\" containing ontology entitites, but behind the scenes, SimPhoNy is translating this information so that it can be used by the underlying data source or software." + ] + }, + { + "cell_type": "markdown", + "id": "9bb30c91-98df-4a0b-81a0-0d92fe7ae14c", + "metadata": {}, + "source": [ + "But still, this does not clarify the issue. To which session did the atom and the position go? When you do not specify any session, objects are created by default on the so-called _Core Session_, which is the default session of SimPhoNy. You may access the default session at any time by importing it." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b7ff9d9d-faf1-4681-afab-8e34905df95b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.session import core_session\n", + "\n", + "list(core_session)" + ] + }, + { + "cell_type": "markdown", + "id": "0fd68c98-022d-46a8-a50d-8676d81c5f66", + "metadata": {}, + "source": [ + "Now it is clear that the atom and its position are stored on the Core Session. Be aware that the Core Session is only meant to serve as a way to quickly test SimPhoNy or be a transient place to store information, as all of its contents are **lost** when you close the Python shell." + ] + }, + { + "cell_type": "markdown", + "id": "bb7edb1c-a729-4654-abf7-bdab60b09659", + "metadata": {}, + "source": [ + "## Wrappers" + ] + }, + { + "cell_type": "markdown", + "id": "b26c880d-2ec5-4d49-991e-1dc7bad2ba82", + "metadata": {}, + "source": [ + "Wrappers are sessions that are connected to data sources or other software. When you use then, you see a \"box\" filled with ontology entitites, but behind the scenes, they do the necessary computations to store your data on said data sources or transfer it to the software." + ] + }, + { + "cell_type": "markdown", + "id": "6019dc3e-fb81-48af-b120-e767c3e11af5", + "metadata": {}, + "source": [ + "In this example, the SQLite (included with SimPhoNy) and [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrappers are used." + ] + }, + { + "cell_type": "markdown", + "id": "f0fbd5ce-3d2f-4004-a391-a84afae50ed6", + "metadata": {}, + "source": [ + "First, start by creating an SQLite session. In this session, create three atoms, with their respective positions and velocities, and then commit the changes." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "5e467ea3-2e9f-4bf3-a143-eed224e46da9", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import SQLite\n", + "\n", + "with SQLite('atoms.db', create=True) as session:\n", + " \n", + " atom = simlammps.Atom(); atom.label = 'Atom 0'\n", + " position = simlammps.Position(vector=[1, 0, 0]); position.label = 'Position 0'\n", + " velocity = simlammps.Velocity(vector=[0, 1, 0]); velocity.label = 'Velocity 0'\n", + " atom[simlammps.hasPart] = {position, velocity}\n", + " \n", + " atom = simlammps.Atom(); atom.label = 'Atom 1'\n", + " position = simlammps.Position(vector=[1, 0, 1]); position.label = 'Position 1'\n", + " velocity = simlammps.Velocity(vector=[3, 1, 0]); velocity.label = 'Velocity 1'\n", + " atom[simlammps.hasPart] = {position, velocity}\n", + " \n", + " atom = simlammps.Atom(); atom.label = 'Atom 2'\n", + " position = simlammps.Position(vector=[1, 1, 0]); position.label = 'Position 2'\n", + " velocity = simlammps.Velocity(vector=[0, 1, 2]); velocity.label = 'Velocity 2'\n", + " atom[simlammps.hasPart] = {position, velocity}\n", + " \n", + " session.commit()" + ] + }, + { + "cell_type": "markdown", + "id": "6546b0e8-8d72-4ff7-9789-72776aa99d7f", + "metadata": {}, + "source": [ + "When the session is opened again, the atoms are still there!" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "54b46e51-8843-42b6-93f9-00e02fa045ec", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[, , , , , , , , ]\n" + ] + } + ], + "source": [ + "with SQLite('atoms.db', create=False) as session:\n", + " print(list(session))" + ] + }, + { + "cell_type": "markdown", + "id": "1467b0af-4741-469d-be57-e52b1548d0d2", + "metadata": {}, + "source": [ + "The next step is to copy these atoms to a SimLAMMPS session and run a simulation." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "6ba94bf5-4094-455a-82ed-a41cc96916fe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "LAMMPS output is captured by PyLammps wrapper\n", + "LAMMPS (23 Jun 2022 - Update 1)\n", + "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98)\n", + " using 1 OpenMP thread(s) per MPI task\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "--------------------------------------------------------------------------\n", + "The library attempted to open the following supporting CUDA libraries,\n", + "but each of them failed. CUDA-aware support is disabled.\n", + "libcuda.so.1: cannot open shared object file: No such file or directory\n", + "libcuda.dylib: cannot open shared object file: No such file or directory\n", + "/usr/lib64/libcuda.so.1: cannot open shared object file: No such file or directory\n", + "/usr/lib64/libcuda.dylib: cannot open shared object file: No such file or directory\n", + "If you are not interested in CUDA-aware support, then run with\n", + "--mca opal_warn_on_missing_libcuda 0 to suppress this message. If you are interested\n", + "in CUDA-aware support, then try setting LD_LIBRARY_PATH to the location\n", + "of libcuda.so.1 to get passed this issue.\n", + "--------------------------------------------------------------------------\n" + ] + } + ], + "source": [ + "from simphony_osp.wrappers import SimLAMMPS\n", + "\n", + "# open the SQLite database and create a new SimLAMMPS session\n", + "sqlite_session = SQLite('atoms.db', create=False)\n", + "simlammps_session = SimLAMMPS()\n", + "\n", + "# prevent closing the sessions when leaving the contexts after \n", + "# using the `with` statement\n", + "sqlite_session.locked = True\n", + "simlammps_session.locked = True\n", + "\n", + "# copy the individuals from the SQLite session to the SimLAMMPS session\n", + "ontology_individuals_from_database = list(sqlite_session)\n", + "simlammps_session.add(ontology_individuals_from_database);" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "38e1c393-4b09-4fb6-8c84-0d9bc3065a24", + "metadata": {}, + "outputs": [], + "source": [ + "with simlammps_session:\n", + " # a few additional entities that were omitted before for brevity\n", + " # are needed to configure the simulation and are created now\n", + " \n", + " # material\n", + " mass = simlammps.Mass(value=0.2)\n", + " material = simlammps.Material()\n", + " material[simlammps.hasPart] += mass\n", + " for atom in simlammps_session.get(oclass=simlammps.Atom):\n", + " atom[simlammps.hasPart] += material\n", + " \n", + " # simulation box\n", + " box = simlammps.SimulationBox()\n", + " face_x = simlammps.FaceX(vector=(10, 0, 0))\n", + " face_x[simlammps.hasPart] += simlammps.Periodic()\n", + " face_y = simlammps.FaceY(vector=(0, 10, 0))\n", + " face_y[simlammps.hasPart] += simlammps.Periodic()\n", + " face_z = simlammps.FaceZ(vector=(0, 0, 10))\n", + " face_z[simlammps.hasPart] += simlammps.Periodic()\n", + " box[simlammps.hasPart] += {face_x, face_y, face_z}\n", + " \n", + " # molecular dynamics model\n", + " md_nve = simlammps.MolecularDynamics()\n", + "\n", + " # solver component\n", + " sp = simlammps.SolverParameter()\n", + "\n", + " # integration time\n", + " steps = 100\n", + " itime = simlammps.IntegrationTime(steps=steps)\n", + " sp[simlammps.hasPart] += itime\n", + " \n", + " # verlet\n", + " verlet = simlammps.Verlet()\n", + " sp[simlammps.hasPart] += verlet\n", + "\n", + " # define the interatomic force as material relation\n", + " lj = simlammps.LennardJones612(\n", + " cutoffDistance=2.5, energyWellDepth=1.0, vanDerWaalsRadius=1.0\n", + " )\n", + " lj[simlammps.hasPart] += material" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f7dd7981-da6f-4e78-9cc9-fda4902d1796", + "metadata": {}, + "outputs": [], + "source": [ + "# the simulation is now ready to be run\n", + "simlammps_session.compute()" + ] + }, + { + "cell_type": "markdown", + "id": "894eeb42-b253-4fb0-8618-b97e6211fe09", + "metadata": {}, + "source": [ + "After running the simulation, the data in the SQLite database can be overwritten with the new data." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e658666c-7e3b-497f-b224-eefa929526ce", + "metadata": {}, + "outputs": [], + "source": [ + "# finally, the data in the sqlite database can be overwritten\n", + "# with the new data\n", + "sqlite_session.add(\n", + " simlammps_session,\n", + " exists_ok = True,\n", + " merge = False, # overwrite an entity if it already exists\n", + ")\n", + "sqlite_session.commit()\n", + "\n", + "# and both sessions can be closed\n", + "sqlite_session.close(), simlammps_session.close();" + ] + }, + { + "cell_type": "markdown", + "id": "1b98fc6a-2b22-4b1a-b589-d154c6edb83a", + "metadata": {}, + "source": [ + "As expected, if the saved atoms are now examined, their positions and velicities have changed." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "b135c220-b089-4459-a0fa-8253905ee4ba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Atom 0:\n", + " - Position [1.09604332 9.98007699 9.56039398]\n", + " - Velocity [ 0.36107337 0.40331728 -0.30807669]\n", + "Atom 1:\n", + " - Position [2.23711536 0.99949841 1.09814967]\n", + " - Velocity [ 2.68929927 1.9921991 -0.5872734 ]\n", + "Atom 2:\n", + " - Position [1.16684132 1.5204246 1.34145635]\n", + " - Velocity [-0.05037264 0.60448362 2.89535009]\n" + ] + } + ], + "source": [ + "with SQLite('atoms.db', create=False) as session:\n", + " for i, atom in enumerate(session.get(oclass=simlammps.Atom)):\n", + " velocity = atom.get(oclass=simlammps.Velocity).one()\n", + " position = atom.get(oclass=simlammps.Position).one()\n", + " print(\n", + " f\"{atom.label}:\\n\"\n", + " f\" - Position {position.vector}\\n\"\n", + " f\" - Velocity {velocity.vector}\"\n", + " )" + ] + }, + { + "cell_type": "markdown", + "id": "98746142-b5ea-449e-bdd0-92d67f43be0b", + "metadata": {}, + "source": [ + "That's all! This was just a quick overview of the usage and purpose of SimPhoNy. Keep reading the documentation to learn more." ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.tools import semantic2dot\n", - "\n", - "semantic2dot(atom, position)" - ] - }, - { - "cell_type": "markdown", - "id": "2cf6770f-8708-4d2a-acc3-b346fea9e826", - "metadata": {}, - "source": [ - "But... Where are actually the atom and the position stored? If a new atom is created running `atom = simlammps.Atom()` again, what happens to the old atom, how can it be retrieved?" - ] - }, - { - "cell_type": "markdown", - "id": "d57e226b-f906-4be7-b434-953c26dae804", - "metadata": {}, - "source": [ - "SimPhoNy stores data in the so-called _sessions_. You may think of a session as a \"box\" were ontology idividuals can be placed. The magic lies within the fact that sessions can provide _views_ into different data sources and software products, thanks to the SimPhoNy Wrapper mechanism. This means that you see a \"box\" containing ontology entitites, but behind the scenes, SimPhoNy is translating this information so that it can be used by the underlying data source or software." - ] - }, - { - "cell_type": "markdown", - "id": "9bb30c91-98df-4a0b-81a0-0d92fe7ae14c", - "metadata": {}, - "source": [ - "But still, this does not clarify the issue. To which session did the atom and the position go? When you do not specify any session, objects are created by default on the so-called _Core Session_, which is the default session of SimPhoNy. You may access the default session at any time by importing it." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "b7ff9d9d-faf1-4681-afab-8e34905df95b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[,\n", - " ]" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.session import core_session\n", - "\n", - "list(core_session)" - ] - }, - { - "cell_type": "markdown", - "id": "0fd68c98-022d-46a8-a50d-8676d81c5f66", - "metadata": {}, - "source": [ - "Now it is clear that the atom and its position are stored on the Core Session. Be aware that the Core Session is only meant to serve as a way to quickly test SimPhoNy or be a transient place to store information, as all of its contents are **lost** when you close the Python shell." - ] - }, - { - "cell_type": "markdown", - "id": "bb7edb1c-a729-4654-abf7-bdab60b09659", - "metadata": {}, - "source": [ - "## Wrappers" - ] - }, - { - "cell_type": "markdown", - "id": "b26c880d-2ec5-4d49-991e-1dc7bad2ba82", - "metadata": {}, - "source": [ - "Wrappers are sessions that are connected to data sources or other software. When you use then, you see a \"box\" filled with ontology entitites, but behind the scenes, they do the necessary computations to store your data on said data sources or transfer it to the software." - ] - }, - { - "cell_type": "markdown", - "id": "6019dc3e-fb81-48af-b120-e767c3e11af5", - "metadata": {}, - "source": [ - "In this example, the SQLite (included with SimPhoNy) and [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrappers are used." - ] - }, - { - "cell_type": "markdown", - "id": "f0fbd5ce-3d2f-4004-a391-a84afae50ed6", - "metadata": {}, - "source": [ - "First, start by creating an SQLite session. In this session, create three atoms, with their respective positions and velocities, and then commit the changes." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "5e467ea3-2e9f-4bf3-a143-eed224e46da9", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import SQLite\n", - "\n", - "with SQLite('atoms.db', create=True) as session:\n", - " \n", - " atom = simlammps.Atom(); atom.label = 'Atom 0'\n", - " position = simlammps.Position(vector=[1, 0, 0]); position.label = 'Position 0'\n", - " velocity = simlammps.Velocity(vector=[0, 1, 0]); velocity.label = 'Velocity 0'\n", - " atom[simlammps.hasPart] = {position, velocity}\n", - " \n", - " atom = simlammps.Atom(); atom.label = 'Atom 1'\n", - " position = simlammps.Position(vector=[1, 0, 1]); position.label = 'Position 1'\n", - " velocity = simlammps.Velocity(vector=[3, 1, 0]); velocity.label = 'Velocity 1'\n", - " atom[simlammps.hasPart] = {position, velocity}\n", - " \n", - " atom = simlammps.Atom(); atom.label = 'Atom 2'\n", - " position = simlammps.Position(vector=[1, 1, 0]); position.label = 'Position 2'\n", - " velocity = simlammps.Velocity(vector=[0, 1, 2]); velocity.label = 'Velocity 2'\n", - " atom[simlammps.hasPart] = {position, velocity}\n", - " \n", - " session.commit()" - ] - }, - { - "cell_type": "markdown", - "id": "6546b0e8-8d72-4ff7-9789-72776aa99d7f", - "metadata": {}, - "source": [ - "When the session is opened again, the atoms are still there!" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "54b46e51-8843-42b6-93f9-00e02fa045ec", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[, , , , , , , , ]\n" - ] - } - ], - "source": [ - "with SQLite('atoms.db', create=False) as session:\n", - " print(list(session))" - ] - }, - { - "cell_type": "markdown", - "id": "1467b0af-4741-469d-be57-e52b1548d0d2", - "metadata": {}, - "source": [ - "The next step is to copy these atoms to a SimLAMMPS session and run a simulation." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "6ba94bf5-4094-455a-82ed-a41cc96916fe", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "LAMMPS output is captured by PyLammps wrapper\n", - "LAMMPS (23 Jun 2022 - Update 1)\n", - "OMP_NUM_THREADS environment is not set. Defaulting to 1 thread. (src/comm.cpp:98)\n", - " using 1 OpenMP thread(s) per MPI task\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "--------------------------------------------------------------------------\n", - "The library attempted to open the following supporting CUDA libraries,\n", - "but each of them failed. CUDA-aware support is disabled.\n", - "libcuda.so.1: cannot open shared object file: No such file or directory\n", - "libcuda.dylib: cannot open shared object file: No such file or directory\n", - "/usr/lib64/libcuda.so.1: cannot open shared object file: No such file or directory\n", - "/usr/lib64/libcuda.dylib: cannot open shared object file: No such file or directory\n", - "If you are not interested in CUDA-aware support, then run with\n", - "--mca opal_warn_on_missing_libcuda 0 to suppress this message. If you are interested\n", - "in CUDA-aware support, then try setting LD_LIBRARY_PATH to the location\n", - "of libcuda.so.1 to get passed this issue.\n", - "--------------------------------------------------------------------------\n" - ] } - ], - "source": [ - "from simphony_osp.wrappers import SimLAMMPS\n", - "\n", - "# open the SQLite database and create a new SimLAMMPS session\n", - "sqlite_session = SQLite('atoms.db', create=False)\n", - "simlammps_session = SimLAMMPS()\n", - "\n", - "# prevent closing the sessions when leaving the contexts after \n", - "# using the `with` statement\n", - "sqlite_session.locked = True\n", - "simlammps_session.locked = True\n", - "\n", - "# copy the individuals from the SQLite session to the SimLAMMPS session\n", - "ontology_individuals_from_database = list(sqlite_session)\n", - "simlammps_session.add(ontology_individuals_from_database);" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "38e1c393-4b09-4fb6-8c84-0d9bc3065a24", - "metadata": {}, - "outputs": [], - "source": [ - "with simlammps_session:\n", - " # a few additional entities that were omitted before for brevity\n", - " # are needed to configure the simulation and are created now\n", - " \n", - " # material\n", - " mass = simlammps.Mass(value=0.2)\n", - " material = simlammps.Material()\n", - " material[simlammps.hasPart] += mass\n", - " for atom in simlammps_session.get(oclass=simlammps.Atom):\n", - " atom[simlammps.hasPart] += material\n", - " \n", - " # simulation box\n", - " box = simlammps.SimulationBox()\n", - " face_x = simlammps.FaceX(vector=(10, 0, 0))\n", - " face_x[simlammps.hasPart] += simlammps.Periodic()\n", - " face_y = simlammps.FaceY(vector=(0, 10, 0))\n", - " face_y[simlammps.hasPart] += simlammps.Periodic()\n", - " face_z = simlammps.FaceZ(vector=(0, 0, 10))\n", - " face_z[simlammps.hasPart] += simlammps.Periodic()\n", - " box[simlammps.hasPart] += {face_x, face_y, face_z}\n", - " \n", - " # molecular dynamics model\n", - " md_nve = simlammps.MolecularDynamics()\n", - "\n", - " # solver component\n", - " sp = simlammps.SolverParameter()\n", - "\n", - " # integration time\n", - " steps = 100\n", - " itime = simlammps.IntegrationTime(steps=steps)\n", - " sp[simlammps.hasPart] += itime\n", - " \n", - " # verlet\n", - " verlet = simlammps.Verlet()\n", - " sp[simlammps.hasPart] += verlet\n", - "\n", - " # define the interatomic force as material relation\n", - " lj = simlammps.LennardJones612(\n", - " cutoffDistance=2.5, energyWellDepth=1.0, vanDerWaalsRadius=1.0\n", - " )\n", - " lj[simlammps.hasPart] += material" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "f7dd7981-da6f-4e78-9cc9-fda4902d1796", - "metadata": {}, - "outputs": [], - "source": [ - "# the simulation is now ready to be run\n", - "simlammps_session.compute()" - ] - }, - { - "cell_type": "markdown", - "id": "894eeb42-b253-4fb0-8618-b97e6211fe09", - "metadata": {}, - "source": [ - "After running the simulation, the data in the SQLite database can be overwritten with the new data." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "e658666c-7e3b-497f-b224-eefa929526ce", - "metadata": {}, - "outputs": [], - "source": [ - "# finally, the data in the sqlite database can be overwritten\n", - "# with the new data\n", - "sqlite_session.add(\n", - " simlammps_session,\n", - " exists_ok = True,\n", - " merge = False, # overwrite an entity if it already exists\n", - ")\n", - "sqlite_session.commit()\n", - "\n", - "# and both sessions can be closed\n", - "sqlite_session.close(), simlammps_session.close();" - ] - }, - { - "cell_type": "markdown", - "id": "1b98fc6a-2b22-4b1a-b589-d154c6edb83a", - "metadata": {}, - "source": [ - "As expected, if the saved atoms are now examined, their positions and velicities have changed." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "b135c220-b089-4459-a0fa-8253905ee4ba", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Atom 0:\n", - " - Position [1.09604332 9.98007699 9.56039398]\n", - " - Velocity [ 0.36107337 0.40331728 -0.30807669]\n", - "Atom 1:\n", - " - Position [2.23711536 0.99949841 1.09814967]\n", - " - Velocity [ 2.68929927 1.9921991 -0.5872734 ]\n", - "Atom 2:\n", - " - Position [1.16684132 1.5204246 1.34145635]\n", - " - Velocity [-0.05037264 0.60448362 2.89535009]\n" - ] + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.7" } - ], - "source": [ - "with SQLite('atoms.db', create=False) as session:\n", - " for i, atom in enumerate(session.get(oclass=simlammps.Atom)):\n", - " velocity = atom.get(oclass=simlammps.Velocity).one()\n", - " position = atom.get(oclass=simlammps.Position).one()\n", - " print(\n", - " f\"{atom.label}:\\n\"\n", - " f\" - Position {position.vector}\\n\"\n", - " f\" - Velocity {velocity.vector}\"\n", - " )" - ] - }, - { - "cell_type": "markdown", - "id": "98746142-b5ea-449e-bdd0-92d67f43be0b", - "metadata": {}, - "source": [ - "That's all! This was just a quick overview of the usage and purpose of SimPhoNy. Keep reading the documentation to learn more." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.10.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/assertional_knowledge.ipynb b/docs/usage/assertional_knowledge.ipynb index de64e29..ecfd1d2 100644 --- a/docs/usage/assertional_knowledge.ipynb +++ b/docs/usage/assertional_knowledge.ipynb @@ -1,1170 +1,1170 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Assertional knowledge\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fassertional_knowledge.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In an ontological framework, ontology entities are used as a knowledge representation form. Those can be further categorized in two groups: ontology individuals ([assertional knowledge](https://en.wikipedia.org/wiki/Abox)), and ontology classes, relationships, attributes and annotations ([terminological knowledge](https://en.wikipedia.org/wiki/Tbox)). This page **focuses on** how to access, edit and navigate the **assertional knowledge** of an ontology using SimPhoNy." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Such functionality is presented in the form of a tutorial, in which the city namespace from SimPhoNy’s example City ontology, the emmo namespace from the Elementary Multiperspective Material Ontology (EMMO) are used as examples. If you want to follow the tutorial along, please make sure that both ontologies are installed. If it is not the case, you can install them by running the command below." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "# Install the ontologies\n", - "!pico install city emmo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Moreover, this tutorial concentrates on how to interact with [ontology individual objects](../api_reference.md#simphony_osp.ontology.OntologyIndividual). Each ontology individual object represents a single individual in the ontology." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Instantiating ontology individuals" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "On this page, examples are based **exclusively on newly created ontology individuals**. You can learn how to retrieve existing ontology individuals from a data source in the next sections." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To instantiate a new ontology individual, just call an ontology class object as shown below. If the words \"ontology class object\" sound new to you, please read the [previous section](terminological_knowledge.ipynb). " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Certain attributes of the ontology individual can already be set at creation time by passing their values as keyword arguments, where the keyword is any of the attribute labels or its namespace suffix. Such attributes are, specifically, the ones returned by the [attributes property](../api_reference.md#simphony_osp.ontology.OntologyClass.attributes) and the [optional attributes property](../api_reference.md#simphony_osp.ontology.OntologyClass.optional_attributes) of the ontology class being called." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The following attributes of a new Citizen individual can be set using keyword arguments:\n", - " - name\n", - " - age\n" - ] - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.namespaces import city, emmo, owl, rdfs, simphony\n", - "\n", - "print(\n", - " f'The following attributes of a new {city.Citizen} '\n", - " f'individual can be set using keyword arguments:'\n", - ")\n", - "for attribute in set(city.Citizen.attributes) | city.Citizen.optional_attributes:\n", - " print(f' - {attribute}')\n", - "\n", - "city.Citizen(name=\"Test Person\", age=42)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In fact, if any of the attributes is defined in the ontology as _mandatory_ using [ontology axioms](terminological_knowledge.ipynb#Operations-specific-to-ontology-axioms), you will be forced to provide them in the function call (otherwise an exception will be raised)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "In Python, you can pass keyword arguments with spaces or other characters not typically allowed in keyword arguments by unpacking a dictionary in the function call: `city.Citizen(name=\"Test Person\", **{\"age\": 42})`.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "At the moment, it is not possible to instantiate multi-class individuals. We [are aware of this issue](https://github.com/simphony/simphony-osp/issues/669), and planning to include this functionality in a future minor release.\n", - "\n", - "Until this is fixed, the suggested workaround is to instantiate an ontology individual of any class and change the classes _a posteriori_, just as shown below.\n", - " \n", - "```python\n", - "person = owl.Thing()\n", - "\n", - "person.classes = city.Citizen, emmo.Cogniser\n", - "```\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "By default, new ontology individuals are assigned a random IRI from the _simphony-osp.eu_ domain." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.URIRef('https://www.simphony-osp.eu/entity#6b7cf472-9dbe-4d9e-93e2-0f56ee308d27')" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.Citizen(name=\"Test Person\", age=42).identifier" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, it is possible to fix the identifier using the `iri` keyword argument." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.URIRef('http://example.org/entity#test_person')" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.Citizen(\n", - " name=\"Test Person\", age=42,\n", - " iri='http://example.org/entity#test_person'\n", - ").identifier" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "An individual can also be instantiated in a session different from the default one using the `session` keyword argument (see the sessions section)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## [Ontology individual objects](../api_reference.md#simphony_osp.ontology.OntologyIndividual)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ontology individuals are a special type of ontology entities, and thus, the ontology individual objects inherit from [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects), meaning that they share their functionality.\n", - "\n", - "In SimPhoNy, an ontology individual is characterized by\n", - "\n", - "- the information about the ontology individual itself such as the classes it belongs to, its label and its attributes;\n", - "- the connections to other ontology individuals.\n", - "\n", - "Moreover, such information is stored on a so-called _session_ (see [next section](sessions.ipynb))." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As said, ontology individual objects inherit from [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects). Therefore, it is also possible to access their label, identifier, namespace and super- or subclasses. Below you can find an example. Head to the [terminological knowledge](terminological_knowledge.ipynb#Ontology-entity-objects) section for more details. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "Even though ontology individual objects share the functionality of [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects), there are some slight differences to consider:\n", - "\n", - "- The [namespace property](../api_reference.md#simphony_osp.ontology.OntologyEntity.namespace) tipically returns `None`, regardless of the IRI of the ontology individual. This happens because in order to belong to a namespace, an ontology entity needs not only to have an IRI that contains the namespace IRI, but also to belong to the same session. Ontologies installed with [pico](ontology/pico.md) live in their own, separate session.\n", - "- The [superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.superclasses), [direct_superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_superclasses), [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.subclasses) and [direct_subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_subclasses) properties, as well as the [is_subclass_of](../api_reference.md#simphony_osp.ontology.OntologyEntity.is_subclass_of) method refer to the superclasses and subclasses of all the classes the ontology individual belongs to, as illustrated in the example.\n", - "- The properties [label](../api_reference.md#simphony_osp.ontology.OntologyEntity.label), [label_lang](../api_reference.md#simphony_osp.ontology.OntologyEntity.label_lang), [label_literal](../api_reference.md#simphony_osp.ontology.OntologyEntity.label_literal) and [session](../api_reference.md#simphony_osp.ontology.OntologyEntity.session) are **writable**. This means that both the [main label](terminological_knowledge.ipynb#Accessing-an-entity%E2%80%99s-label) of ontology individuals can be changed and the individuals themselves may be moved from one session to another by changing the value of such properties.\n", - " \n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Label: My neighbor (en)\n", - "\n", - "Label literal: rdflib.term.Literal('My neighbor', lang='en')\n", - "\n", - "List of labels: [rdflib.term.Literal('My neighbor', lang='en')]\n", - "\n", - "Identifier: rdflib.term.URIRef('https://www.simphony-osp.eu/entity#03659fa1-5c91-44a0-a73c-f475d3b328fe')\n", - "\n", - "Namespace: None\n", - "\n", - "Superclasses: frozenset({, , , , , , , , , })\n", - "\n", - "Subclasses: frozenset({})\n", - "\n", - "Direct superclasses: frozenset({})\n", - "\n", - "Direct subclasses: frozenset()\n", - "\n", - "Does any of the classes of the individual belong the \"Semiotics\" branch of EMMO? True\n", - "\n", - "Is the entity an individual? True\n" - ] - } - ], - "source": [ - "person = emmo.Cogniser()\n", - "# Instantiate an ontology individual of class Cogniser. According to the EMMO's\n", - "# documentation, a Cogniser is defined as:\n", - "# > An interpreter who establish the connection between an icon an an object \n", - "# > recognizing their resemblance (e.g. logical, pictorial)\n", - "# The following example for a Cogniser is provided:\n", - "# > The scientist that connects an equation to a physical phenomenon.\n", - "\n", - "person.label, person.label_lang = \"My neighbor\", \"en\"\n", - "\n", - "print(\"Label:\", f\"{person.label} ({person.label_lang})\", end='\\n'*2)\n", - "print(\"Label literal:\", person.label_literal.__repr__(), end='\\n'*2)\n", - "print(\"List of labels:\", list(person.iter_labels()).__repr__(), end='\\n'*2)\n", - "print(\"Identifier:\", person.identifier.__repr__(), end='\\n'*2)\n", - "print(\"Namespace:\", person.namespace.__repr__(), end='\\n'*2)\n", - "\n", - "print('Superclasses:', person.superclasses, end='\\n'*2)\n", - "print('Subclasses:', person.subclasses, end='\\n'*2)\n", - "print('Direct superclasses:', person.direct_superclasses, end='\\n'*2)\n", - "print('Direct subclasses:', person.direct_subclasses, end='\\n'*2)\n", - "\n", - "print(\"Does any of the classes of the individual belong the \\\"Semiotics\\\" branch of EMMO?\", person.is_subclass_of(emmo.Semiotics))\n", - "\n", - "from simphony_osp.ontology import OntologyIndividual\n", - "print(\"\\nIs the entity an individual?\", isinstance(person, OntologyIndividual))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In addition, ontology individuals have extra functionality that is specific to them." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For example, there is an extra method to verify whether they are an instance of a specific ontology class (which is just an alias for [is_subclass_of](..#api_reference.md#simphony_osp.ontology.OntologyEntity.is_subclass_of))." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "person.is_a(emmo.Semiotics)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It is also is possible not only to verify the classes that the individual belongs to," - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "frozenset({})" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "person.classes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "but also to **change** them." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "frozenset({,\n", - " })" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "person.classes = city.Citizen, emmo.Cogniser\n", - "\n", - "person.classes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To get the [session](sessions.ipynb) an individual belongs to, use the [session property](../api_reference.md#simphony_osp.ontology.OntologyEntity.session). Remember that this property can be also changed in order to transfer the individual from one session to another." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "person.session" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Managing attributes, relationships and annotations" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Using the index operator `[]`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SimPhoNy features a single, unified syntax based on the Python index `[]` operator to manage the relationships between ontology individuals, the values of the attributes of an individual, and the values of ontology annotations." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For example, assume one wants to create a city with several neighborhoods and inhabitants. The first step is to instantiate the ontology individuals that represent such elements." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "\n", - "neighborhoods = {\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Altstadt', [47.99525, 7.84726]),\n", - " ('Stühlinger', [47.99888, 7.83774]),\n", - " ('Neuburg', [48.00021, 7.86084]),\n", - " ('Herdern', [48.00779, 7.86268]),\n", - " ('Brühl', [48.01684, 7.843]),\n", - " ]\n", - "}\n", - "\n", - "citizen_1 = city.Citizen(name='Nikola', age=35)\n", - "citizen_2 = city.Citizen(name='Lena', age=70)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The next step is connecting them, modifying the values of their attributes and adding annotations.\n", - "\n", - "Let's start trying to declare that the neighborhoods are part of the city and that the citizens are inhabitants of the city using the `city.hasPart` and `city.hasInhabitant` relationships.\n", - "\n", - "The individuals that are already connected to the city through this relationship can be consulted as follows." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "set() " - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "freiburg[city.hasPart]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The above statement yields a [relationship set object](../api_reference.md#simphony_osp.ontology.RelationshipSet). Relationship sets are [set-like](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableSet) objects that manage the ontology individuals that are linked to the given individual and relationship (in this example, `freiburg` and `city.hasPart`). You will notice in the following examples, that relationship set objects have a few extra capabilities that [Python sets](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset) do not have that make the interaction with them more natural." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "Set-like objects are objects compatible with the standard Python sets, meaning that all the methods and functionality from Python sets are available for set-like objects.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In order to attach items through the given relationship, all that is needed is an **in-place** set union." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "set()\n", - "{, , , , }\n" - ] - } - ], - "source": [ - "freiburg[city.hasPart] | neighborhoods # does not attach the neighborhoods\n", - "print(freiburg[city.hasPart])\n", - "freiburg[city.hasPart] |= neighborhoods # attaches the neighborhoods (in-place union)\n", - "print(freiburg[city.hasPart])\n", - "\n", - "freiburg[city.hasInhabitant] += citizen_1, citizen_2 # attaches the citizens\n", - "# the '+=` operator is not available in standard Python sets and is a shorthand for\n", - "# the following operations:\n", - "# - `+= citizen_1, citizen_2` is equivalent to `|= {citizen_1, citizen_2}`\n", - "# - `+= {citizen_1, citizen_2}` is equivalent to `|= {citizen_1, citizen_2}`\n", - "# - `+= [citizen_1, citizen_2]` raises a TypeError (this shortcut only works for tuples and set-like objects)\n", - "# - `+= citizen_3` is equivalent to `|= {citizen_3}\n", - "# the `-=` operator is avilable in standard Python sets, but has been extended\n", - "# to work like in the above examples when used together with non set-like objects." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Exactly in the same way, when ontology attributes or ontology annotations are passed to the index operator `[]`, [attribute sets](../api_reference.md#simphony_osp.ontology.AttributeSet) and [annotation sets](../api_reference.md#simphony_osp.ontology.AnnotationSet) are spawned, which behave similarly to relationship sets." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'Lena', 'Helena'} \n", - "\n", - "{70} \n", - "{55} \n", - "{'Lena was born in Berlin, but moved to Freiburg when she was 28 years old.', 'She likes to go into the woods and get lost in her thoughts.'} \n" - ] - } - ], - "source": [ - "# ATTRIBUTES\n", - "# - assign one more name to Lena\n", - "citizen_2[city['name']] += 'Helena'\n", - "print(citizen_2[city['name']].__repr__(), end='\\n'*2)\n", - "\n", - "# - change the age of Lena (`=` replaces all the values of the attribute)\n", - "print(citizen_2[city.age].__repr__())\n", - "citizen_2[city.age] = 55\n", - "print(citizen_2[city.age].__repr__())\n", - "\n", - "# ANNOTATIONS\n", - "citizen_1[rdfs.comment] = (\n", - " 'Lena was born in Berlin, but moved to Freiburg when she was 28 years old.',\n", - " 'She likes to go into the woods and get lost in her thoughts.'\n", - ")\n", - "print(citizen_1[rdfs.comment].__repr__())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "In SimPhoNy, relationships, attributes and annotations are treated in an ontological sense. This means that when using the corresponding Python object to access or modify them, one is referring not only to such ontology entity, but also to all of its subclasses. You can verify this fact noting that `freiburg[owl.topObjectProperty]` returns all individuals attached to `freiburg`, as all relationships are a subclass of `owl:topObjectProperty`.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Strings can also be used with the index notation `[]` as a shorthand in certain cases" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "- to access the [attributes of any of the classes](terminological_knowledge.ipynb#Ontology-class-objects) that the individual belongs to, or other attributes that have already been assigned to the individual,\n", - "- to access relationships that have already been used to link the inidividual to others,\n", - "- to access annotations whose value has been already assigned." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{, } " - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "freiburg[\"hasInhabitant\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{35} " - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_1[\"age\"]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Therefore the most relevant use-case of passing strings is accessing information from existing individuals, rather than constructing new ones." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The index notation `[]` supports IPython autocompletion for strings. When working on a Jupyter notebook, it is possible to get suggestions for the strings that will work for that specific individual by writing `individual[\"` and pressing TAB.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Even though in this example only a few possibilities of the relationship-, attribute- and annotation sets have been covered, remember that they are compatible with standard Python sets. So hopefully, this introduction should be enough to consider the remaining possibilities on your own: remove elements with `-=`, check if a certain relationship is being used `if freiburg[city.hasInhabitant]:`, loop over elements `for connected_individual in freiburg[city.hasInhabitant]:`, etc.\n", - "\n", - "`del freiburg[city.hasInhabitant]` and `freiburg[city.hasInhabitant] = None` can also be used and are equivalent to `freiburg[city.hasInhabitant] = set()`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When it comes to **accessing single values** from a relationship-, attribute- or annotation set, there are three built-in shortcuts to make it easier than iterating over them:\n", - "\n", - "- `any()` returns an element from the set in a non-deterministic way. Returns `None` if the set is empty.\n", - "- `one()` returns the single element in the set. If the set is empty or has multiple elements, thein the exceptions [ResultEmptyError](../api_reference.md#simphony_osp.ontology.ResultEmptyError) or [MultipleResultsError](../api_reference.md#simphony_osp.ontology.MultipleResultsError) are respectively raised.\n", - "- `all()` returns the set itself, and is therefore redundant. Can be used to improve code readability if needed." - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Nikola\n", - "{'Nikola'}\n", - "None\n", - "set() \n" - ] - } - ], - "source": [ - "# print(citizen_2['name'].one()) # Raises `MultipleResultsError`, as Lena has multiple names.\n", - "print(citizen_1['name'].any())\n", - "print(citizen_1['name'].all())\n", - "\n", - "# print(citizen_2[city.hasChild].one()) # Raises `ResultEmptyError`, as Nikola has not been declared to have children.\n", - "print(citizen_2[city.hasChild].any())\n", - "print(citizen_2[city.hasChild].all().__repr__())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finally, if it is needed to find individuals that are connected through an _inverse relationship_, the `.inverse` attribute of the relationship sets can be used." - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Freiburg'" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_1[city.hasInhabitant].inverse.one()['name'].one()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Using the Python dot notation (attributes only)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The Python dot notation can be used to access and set the attributes of individuals in all cases when both strings can be passed to the index notation `[]` and the string is compatible with the Python syntax (e.g. it contains no spaces). See the [previous section for more details](#Using-the-index-operator-[])." - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('Nikola', 35)" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_1.name, citizen_1.age" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "34" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_1.age = 34\n", - "citizen_1.age" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "mappingproxy({: frozenset({'Nikola'}),\n", - " : frozenset({34})})" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_1.attributes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The dot notation also supports IPython autocompletion.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The dot notation is limited to attributes with a single value. When several values are assigned to the same attribute, a `RuntimeError` is raised." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It is possible to get a dictionary with all the attributes of an individual and its values using the `attributes` attribute." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "mappingproxy({: frozenset({'Helena',\n", - " 'Lena'}),\n", - " : frozenset({55})})" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "citizen_2.attributes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Using the `get`, `iter`, `connect`, and `disconnect` methods (relationships only)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The method [connect](../api_reference.md#simphony_osp.ontology.OntologyIndividual.connect) connects individuals using the given relationship." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "set() \n", - "{, } \n" - ] - } - ], - "source": [ - "# remove the existing connections between Freiburg and its citizens\n", - "del freiburg[city.hasInhabitant]\n", - "print(freiburg[city.hasInhabitant].__repr__())\n", - "\n", - "# use the connect method to restore them\n", - "freiburg.connect(citizen_1, citizen_2, rel=city.hasInhabitant)\n", - "print(freiburg[city.hasInhabitant].__repr__())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The method [disconnect](../api_reference.md#simphony_osp.ontology.OntologyIndividual.disconnect) disconnects ontology individuals. Optionally a relationship and class filter can be given." - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{}\n", - "set()\n", - "{}\n", - "{}\n", - "set()\n" - ] - } - ], - "source": [ - "citizen_3 = city.Citizen(name='Lukas', age=2)\n", - "citizen_1.connect(citizen_3, rel=city.hasChild)\n", - "print(citizen_1[city.hasChild])\n", - "\n", - "citizen_1.disconnect(citizen_3) # disconnects citizen_3\n", - "print(citizen_1[city.hasChild])\n", - "\n", - "citizen_1.connect(citizen_3, rel=city.hasChild)\n", - "\n", - "citizen_1.disconnect(rel=city.worksIn) # does not disconnect citizen_3, as the relationship does not match the filter\n", - "print(citizen_1[city.hasChild])\n", - "citizen_1.disconnect(rel=city.hasChild, oclass=city.Building) # does not disconnect citizen_3, as the its class does not match the filter\n", - "print(citizen_1[city.hasChild])\n", - "citizen_1.disconnect(citizen_3, oclass=city.Citizen) # disconnect works, as the filters match now\n", - "print(citizen_1[city.hasChild])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The method [get](../api_reference.md#simphony_osp.ontology.OntologyIndividual.get) is used to obtain the individuals linked through a given relationship. Filters to restrict the results only to specific individuals, relationships and classes, as well as any combination of them can optinally be provided. The [iter](../api_reference.md#simphony_osp.ontology.OntologyIndividual.iter) method behaves similarly, but returns an interator instead." - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{, , , , , , } \n", - "\n", - "{, } \n", - "\n", - "{, } \n", - "\n", - "\n", - "(, )\n", - "\n", - "None\n", - "None\n", - "\n", - "None\n" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Assertional knowledge\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fassertional_knowledge.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In an ontological framework, ontology entities are used as a knowledge representation form. Those can be further categorized in two groups: ontology individuals ([assertional knowledge](https://en.wikipedia.org/wiki/Abox)), and ontology classes, relationships, attributes and annotations ([terminological knowledge](https://en.wikipedia.org/wiki/Tbox)). This page **focuses on** how to access, edit and navigate the **assertional knowledge** of an ontology using SimPhoNy." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Such functionality is presented in the form of a tutorial, in which the city namespace from SimPhoNy\u2019s example City ontology, the emmo namespace from the Elementary Multiperspective Material Ontology (EMMO) are used as examples. If you want to follow the tutorial along, please make sure that both ontologies are installed. If it is not the case, you can install them by running the command below." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# Install the ontologies\n", + "!pico install city emmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Moreover, this tutorial concentrates on how to interact with [ontology individual objects](../api_reference.md#simphony_osp.ontology.OntologyIndividual). Each ontology individual object represents a single individual in the ontology." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Instantiating ontology individuals" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "On this page, examples are based **exclusively on newly created ontology individuals**. You can learn how to retrieve existing ontology individuals from a data source in the next sections." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To instantiate a new ontology individual, just call an ontology class object as shown below. If the words \"ontology class object\" sound new to you, please read the [previous section](terminological_knowledge.ipynb). " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Certain attributes of the ontology individual can already be set at creation time by passing their values as keyword arguments, where the keyword is any of the attribute labels or its namespace suffix. Such attributes are, specifically, the ones returned by the [attributes property](../api_reference.md#simphony_osp.ontology.OntologyClass.attributes) and the [optional attributes property](../api_reference.md#simphony_osp.ontology.OntologyClass.optional_attributes) of the ontology class being called." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The following attributes of a new Citizen individual can be set using keyword arguments:\n", + " - name\n", + " - age\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.namespaces import city, emmo, owl, rdfs, simphony\n", + "\n", + "print(\n", + " f'The following attributes of a new {city.Citizen} '\n", + " f'individual can be set using keyword arguments:'\n", + ")\n", + "for attribute in set(city.Citizen.attributes) | city.Citizen.optional_attributes:\n", + " print(f' - {attribute}')\n", + "\n", + "city.Citizen(name=\"Test Person\", age=42)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In fact, if any of the attributes is defined in the ontology as _mandatory_ using [ontology axioms](terminological_knowledge.ipynb#Operations-specific-to-ontology-axioms), you will be forced to provide them in the function call (otherwise an exception will be raised)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "In Python, you can pass keyword arguments with spaces or other characters not typically allowed in keyword arguments by unpacking a dictionary in the function call: `city.Citizen(name=\"Test Person\", **{\"age\": 42})`.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "At the moment, it is not possible to instantiate multi-class individuals. We [are aware of this issue](https://github.com/simphony/simphony-osp/issues/669), and planning to include this functionality in a future minor release.\n", + "\n", + "Until this is fixed, the suggested workaround is to instantiate an ontology individual of any class and change the classes _a posteriori_, just as shown below.\n", + " \n", + "```python\n", + "person = owl.Thing()\n", + "\n", + "person.classes = city.Citizen, emmo.Cogniser\n", + "```\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By default, new ontology individuals are assigned a random IRI from the _simphony-osp.eu_ domain." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.URIRef('https://www.simphony-osp.eu/entity#6b7cf472-9dbe-4d9e-93e2-0f56ee308d27')" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.Citizen(name=\"Test Person\", age=42).identifier" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, it is possible to fix the identifier using the `iri` keyword argument." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.URIRef('http://example.org/entity#test_person')" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.Citizen(\n", + " name=\"Test Person\", age=42,\n", + " iri='http://example.org/entity#test_person'\n", + ").identifier" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "An individual can also be instantiated in a session different from the default one using the `session` keyword argument (see the sessions section)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## [Ontology individual objects](../api_reference.md#simphony_osp.ontology.OntologyIndividual)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Ontology individuals are a special type of ontology entities, and thus, the ontology individual objects inherit from [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects), meaning that they share their functionality.\n", + "\n", + "In SimPhoNy, an ontology individual is characterized by\n", + "\n", + "- the information about the ontology individual itself such as the classes it belongs to, its label and its attributes;\n", + "- the connections to other ontology individuals.\n", + "\n", + "Moreover, such information is stored on a so-called _session_ (see [next section](sessions.ipynb))." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As said, ontology individual objects inherit from [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects). Therefore, it is also possible to access their label, identifier, namespace and super- or subclasses. Below you can find an example. Head to the [terminological knowledge](terminological_knowledge.ipynb#Ontology-entity-objects) section for more details. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "Even though ontology individual objects share the functionality of [ontology entity objects](terminological_knowledge.ipynb#Ontology-entity-objects), there are some slight differences to consider:\n", + "\n", + "- The [namespace property](../api_reference.md#simphony_osp.ontology.OntologyEntity.namespace) tipically returns `None`, regardless of the IRI of the ontology individual. This happens because in order to belong to a namespace, an ontology entity needs not only to have an IRI that contains the namespace IRI, but also to belong to the same session. Ontologies installed with [pico](ontology/pico.md) live in their own, separate session.\n", + "- The [superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.superclasses), [direct_superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_superclasses), [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.subclasses) and [direct_subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_subclasses) properties, as well as the [is_subclass_of](../api_reference.md#simphony_osp.ontology.OntologyEntity.is_subclass_of) method refer to the superclasses and subclasses of all the classes the ontology individual belongs to, as illustrated in the example.\n", + "- The properties [label](../api_reference.md#simphony_osp.ontology.OntologyEntity.label), [label_lang](../api_reference.md#simphony_osp.ontology.OntologyEntity.label_lang), [label_literal](../api_reference.md#simphony_osp.ontology.OntologyEntity.label_literal) and [session](../api_reference.md#simphony_osp.ontology.OntologyEntity.session) are **writable**. This means that both the [main label](terminological_knowledge.ipynb#Accessing-an-entity%E2%80%99s-label) of ontology individuals can be changed and the individuals themselves may be moved from one session to another by changing the value of such properties.\n", + " \n", + "
" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Label: My neighbor (en)\n", + "\n", + "Label literal: rdflib.term.Literal('My neighbor', lang='en')\n", + "\n", + "List of labels: [rdflib.term.Literal('My neighbor', lang='en')]\n", + "\n", + "Identifier: rdflib.term.URIRef('https://www.simphony-osp.eu/entity#03659fa1-5c91-44a0-a73c-f475d3b328fe')\n", + "\n", + "Namespace: None\n", + "\n", + "Superclasses: frozenset({, , , , , , , , , })\n", + "\n", + "Subclasses: frozenset({})\n", + "\n", + "Direct superclasses: frozenset({})\n", + "\n", + "Direct subclasses: frozenset()\n", + "\n", + "Does any of the classes of the individual belong the \"Semiotics\" branch of EMMO? True\n", + "\n", + "Is the entity an individual? True\n" + ] + } + ], + "source": [ + "person = emmo.Cogniser()\n", + "# Instantiate an ontology individual of class Cogniser. According to the EMMO's\n", + "# documentation, a Cogniser is defined as:\n", + "# > An interpreter who establish the connection between an icon an an object \n", + "# > recognizing their resemblance (e.g. logical, pictorial)\n", + "# The following example for a Cogniser is provided:\n", + "# > The scientist that connects an equation to a physical phenomenon.\n", + "\n", + "person.label, person.label_lang = \"My neighbor\", \"en\"\n", + "\n", + "print(\"Label:\", f\"{person.label} ({person.label_lang})\", end='\\n'*2)\n", + "print(\"Label literal:\", person.label_literal.__repr__(), end='\\n'*2)\n", + "print(\"List of labels:\", list(person.iter_labels()).__repr__(), end='\\n'*2)\n", + "print(\"Identifier:\", person.identifier.__repr__(), end='\\n'*2)\n", + "print(\"Namespace:\", person.namespace.__repr__(), end='\\n'*2)\n", + "\n", + "print('Superclasses:', person.superclasses, end='\\n'*2)\n", + "print('Subclasses:', person.subclasses, end='\\n'*2)\n", + "print('Direct superclasses:', person.direct_superclasses, end='\\n'*2)\n", + "print('Direct subclasses:', person.direct_subclasses, end='\\n'*2)\n", + "\n", + "print(\"Does any of the classes of the individual belong the \\\"Semiotics\\\" branch of EMMO?\", person.is_subclass_of(emmo.Semiotics))\n", + "\n", + "from simphony_osp.ontology import OntologyIndividual\n", + "print(\"\\nIs the entity an individual?\", isinstance(person, OntologyIndividual))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, ontology individuals have extra functionality that is specific to them." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For example, there is an extra method to verify whether they are an instance of a specific ontology class (which is just an alias for [is_subclass_of](..#api_reference.md#simphony_osp.ontology.OntologyEntity.is_subclass_of))." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "person.is_a(emmo.Semiotics)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is also is possible not only to verify the classes that the individual belongs to," + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "frozenset({})" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "person.classes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "but also to **change** them." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "frozenset({,\n", + " })" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "person.classes = city.Citizen, emmo.Cogniser\n", + "\n", + "person.classes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To get the [session](sessions.ipynb) an individual belongs to, use the [session property](../api_reference.md#simphony_osp.ontology.OntologyEntity.session). Remember that this property can be also changed in order to transfer the individual from one session to another." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "person.session" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Managing attributes, relationships and annotations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Using the index operator `[]`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SimPhoNy features a single, unified syntax based on the Python index `[]` operator to manage the relationships between ontology individuals, the values of the attributes of an individual, and the values of ontology annotations." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For example, assume one wants to create a city with several neighborhoods and inhabitants. The first step is to instantiate the ontology individuals that represent such elements." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "\n", + "neighborhoods = {\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Altstadt', [47.99525, 7.84726]),\n", + " ('St\u00fchlinger', [47.99888, 7.83774]),\n", + " ('Neuburg', [48.00021, 7.86084]),\n", + " ('Herdern', [48.00779, 7.86268]),\n", + " ('Br\u00fchl', [48.01684, 7.843]),\n", + " ]\n", + "}\n", + "\n", + "citizen_1 = city.Citizen(name='Nikola', age=35)\n", + "citizen_2 = city.Citizen(name='Lena', age=70)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The next step is connecting them, modifying the values of their attributes and adding annotations.\n", + "\n", + "Let's start trying to declare that the neighborhoods are part of the city and that the citizens are inhabitants of the city using the `city.hasPart` and `city.hasInhabitant` relationships.\n", + "\n", + "The individuals that are already connected to the city through this relationship can be consulted as follows." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "set() " + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freiburg[city.hasPart]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The above statement yields a [relationship set object](../api_reference.md#simphony_osp.ontology.RelationshipSet). Relationship sets are [set-like](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableSet) objects that manage the ontology individuals that are linked to the given individual and relationship (in this example, `freiburg` and `city.hasPart`). You will notice in the following examples, that relationship set objects have a few extra capabilities that [Python sets](https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset) do not have that make the interaction with them more natural." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "Set-like objects are objects compatible with the standard Python sets, meaning that all the methods and functionality from Python sets are available for set-like objects.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In order to attach items through the given relationship, all that is needed is an **in-place** set union." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set()\n", + "{, , , , }\n" + ] + } + ], + "source": [ + "freiburg[city.hasPart] | neighborhoods # does not attach the neighborhoods\n", + "print(freiburg[city.hasPart])\n", + "freiburg[city.hasPart] |= neighborhoods # attaches the neighborhoods (in-place union)\n", + "print(freiburg[city.hasPart])\n", + "\n", + "freiburg[city.hasInhabitant] += citizen_1, citizen_2 # attaches the citizens\n", + "# the '+=` operator is not available in standard Python sets and is a shorthand for\n", + "# the following operations:\n", + "# - `+= citizen_1, citizen_2` is equivalent to `|= {citizen_1, citizen_2}`\n", + "# - `+= {citizen_1, citizen_2}` is equivalent to `|= {citizen_1, citizen_2}`\n", + "# - `+= [citizen_1, citizen_2]` raises a TypeError (this shortcut only works for tuples and set-like objects)\n", + "# - `+= citizen_3` is equivalent to `|= {citizen_3}\n", + "# the `-=` operator is avilable in standard Python sets, but has been extended\n", + "# to work like in the above examples when used together with non set-like objects." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Exactly in the same way, when ontology attributes or ontology annotations are passed to the index operator `[]`, [attribute sets](../api_reference.md#simphony_osp.ontology.AttributeSet) and [annotation sets](../api_reference.md#simphony_osp.ontology.AnnotationSet) are spawned, which behave similarly to relationship sets." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Lena', 'Helena'} \n", + "\n", + "{70} \n", + "{55} \n", + "{'Lena was born in Berlin, but moved to Freiburg when she was 28 years old.', 'She likes to go into the woods and get lost in her thoughts.'} \n" + ] + } + ], + "source": [ + "# ATTRIBUTES\n", + "# - assign one more name to Lena\n", + "citizen_2[city['name']] += 'Helena'\n", + "print(citizen_2[city['name']].__repr__(), end='\\n'*2)\n", + "\n", + "# - change the age of Lena (`=` replaces all the values of the attribute)\n", + "print(citizen_2[city.age].__repr__())\n", + "citizen_2[city.age] = 55\n", + "print(citizen_2[city.age].__repr__())\n", + "\n", + "# ANNOTATIONS\n", + "citizen_1[rdfs.comment] = (\n", + " 'Lena was born in Berlin, but moved to Freiburg when she was 28 years old.',\n", + " 'She likes to go into the woods and get lost in her thoughts.'\n", + ")\n", + "print(citizen_1[rdfs.comment].__repr__())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "In SimPhoNy, relationships, attributes and annotations are treated in an ontological sense. This means that when using the corresponding Python object to access or modify them, one is referring not only to such ontology entity, but also to all of its subclasses. You can verify this fact noting that `freiburg[owl.topObjectProperty]` returns all individuals attached to `freiburg`, as all relationships are a subclass of `owl:topObjectProperty`.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Strings can also be used with the index notation `[]` as a shorthand in certain cases" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "- to access the [attributes of any of the classes](terminological_knowledge.ipynb#Ontology-class-objects) that the individual belongs to, or other attributes that have already been assigned to the individual,\n", + "- to access relationships that have already been used to link the inidividual to others,\n", + "- to access annotations whose value has been already assigned." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{, } " + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freiburg[\"hasInhabitant\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{35} " + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_1[\"age\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Therefore the most relevant use-case of passing strings is accessing information from existing individuals, rather than constructing new ones." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The index notation `[]` supports IPython autocompletion for strings. When working on a Jupyter notebook, it is possible to get suggestions for the strings that will work for that specific individual by writing `individual[\"` and pressing TAB.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Even though in this example only a few possibilities of the relationship-, attribute- and annotation sets have been covered, remember that they are compatible with standard Python sets. So hopefully, this introduction should be enough to consider the remaining possibilities on your own: remove elements with `-=`, check if a certain relationship is being used `if freiburg[city.hasInhabitant]:`, loop over elements `for connected_individual in freiburg[city.hasInhabitant]:`, etc.\n", + "\n", + "`del freiburg[city.hasInhabitant]` and `freiburg[city.hasInhabitant] = None` can also be used and are equivalent to `freiburg[city.hasInhabitant] = set()`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When it comes to **accessing single values** from a relationship-, attribute- or annotation set, there are three built-in shortcuts to make it easier than iterating over them:\n", + "\n", + "- `any()` returns an element from the set in a non-deterministic way. Returns `None` if the set is empty.\n", + "- `one()` returns the single element in the set. If the set is empty or has multiple elements, thein the exceptions [ResultEmptyError](../api_reference.md#simphony_osp.ontology.ResultEmptyError) or [MultipleResultsError](../api_reference.md#simphony_osp.ontology.MultipleResultsError) are respectively raised.\n", + "- `all()` returns the set itself, and is therefore redundant. Can be used to improve code readability if needed." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Nikola\n", + "{'Nikola'}\n", + "None\n", + "set() \n" + ] + } + ], + "source": [ + "# print(citizen_2['name'].one()) # Raises `MultipleResultsError`, as Lena has multiple names.\n", + "print(citizen_1['name'].any())\n", + "print(citizen_1['name'].all())\n", + "\n", + "# print(citizen_2[city.hasChild].one()) # Raises `ResultEmptyError`, as Nikola has not been declared to have children.\n", + "print(citizen_2[city.hasChild].any())\n", + "print(citizen_2[city.hasChild].all().__repr__())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, if it is needed to find individuals that are connected through an _inverse relationship_, the `.inverse` attribute of the relationship sets can be used." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Freiburg'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_1[city.hasInhabitant].inverse.one()['name'].one()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Using the Python dot notation (attributes only)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The Python dot notation can be used to access and set the attributes of individuals in all cases when both strings can be passed to the index notation `[]` and the string is compatible with the Python syntax (e.g. it contains no spaces). See the [previous section for more details](#Using-the-index-operator-[])." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('Nikola', 35)" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_1.name, citizen_1.age" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "34" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_1.age = 34\n", + "citizen_1.age" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "mappingproxy({: frozenset({'Nikola'}),\n", + " : frozenset({34})})" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_1.attributes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The dot notation also supports IPython autocompletion.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The dot notation is limited to attributes with a single value. When several values are assigned to the same attribute, a `RuntimeError` is raised." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is possible to get a dictionary with all the attributes of an individual and its values using the `attributes` attribute." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "mappingproxy({: frozenset({'Helena',\n", + " 'Lena'}),\n", + " : frozenset({55})})" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "citizen_2.attributes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Using the `get`, `iter`, `connect`, and `disconnect` methods (relationships only)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The method [connect](../api_reference.md#simphony_osp.ontology.OntologyIndividual.connect) connects individuals using the given relationship." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set() \n", + "{, } \n" + ] + } + ], + "source": [ + "# remove the existing connections between Freiburg and its citizens\n", + "del freiburg[city.hasInhabitant]\n", + "print(freiburg[city.hasInhabitant].__repr__())\n", + "\n", + "# use the connect method to restore them\n", + "freiburg.connect(citizen_1, citizen_2, rel=city.hasInhabitant)\n", + "print(freiburg[city.hasInhabitant].__repr__())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The method [disconnect](../api_reference.md#simphony_osp.ontology.OntologyIndividual.disconnect) disconnects ontology individuals. Optionally a relationship and class filter can be given." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n", + "set()\n", + "{}\n", + "{}\n", + "set()\n" + ] + } + ], + "source": [ + "citizen_3 = city.Citizen(name='Lukas', age=2)\n", + "citizen_1.connect(citizen_3, rel=city.hasChild)\n", + "print(citizen_1[city.hasChild])\n", + "\n", + "citizen_1.disconnect(citizen_3) # disconnects citizen_3\n", + "print(citizen_1[city.hasChild])\n", + "\n", + "citizen_1.connect(citizen_3, rel=city.hasChild)\n", + "\n", + "citizen_1.disconnect(rel=city.worksIn) # does not disconnect citizen_3, as the relationship does not match the filter\n", + "print(citizen_1[city.hasChild])\n", + "citizen_1.disconnect(rel=city.hasChild, oclass=city.Building) # does not disconnect citizen_3, as the its class does not match the filter\n", + "print(citizen_1[city.hasChild])\n", + "citizen_1.disconnect(citizen_3, oclass=city.Citizen) # disconnect works, as the filters match now\n", + "print(citizen_1[city.hasChild])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The method [get](../api_reference.md#simphony_osp.ontology.OntologyIndividual.get) is used to obtain the individuals linked through a given relationship. Filters to restrict the results only to specific individuals, relationships and classes, as well as any combination of them can optinally be provided. The [iter](../api_reference.md#simphony_osp.ontology.OntologyIndividual.iter) method behaves similarly, but returns an interator instead." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{, , , , , , } \n", + "\n", + "{, } \n", + "\n", + "{, } \n", + "\n", + "\n", + "(, )\n", + "\n", + "None\n", + "None\n", + "\n", + "None\n" + ] + } + ], + "source": [ + "print(freiburg.get().__repr__(), end='\\n'*2) # returns everything attached to Freiburg (a relationship set)\n", + "\n", + "print(freiburg.get(rel=city.hasInhabitant).__repr__(), end='\\n'*2) # returns only the citizens (a relationship set)\n", + "\n", + "print(freiburg.get(oclass=city.Citizen).__repr__(), end='\\n'*2) # also returns only the citizens (a relationship set)\n", + "\n", + "# filtering specific individuals (can be combined with class and relationship filters)\n", + "print(freiburg.get(citizen_1).__repr__())\n", + "print(freiburg.get(citizen_1, citizen_2).__repr__())\n", + "print(freiburg.get(citizen_1.identifier).__repr__())\n", + "print(freiburg.get('https://example.org/city#unknown_citizen').__repr__())\n", + "print(freiburg.get(citizen_1, rel=city.hasChild).__repr__())\n", + "print(freiburg.get(citizen_1, rel=city.hasInhabitant).__repr__())\n", + "print(freiburg.get(citizen_1, rel=city.hasInhabitant, oclass=city.Building).__repr__())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Using the `get` and `iter` methods, it is also possible to discover the specific relationships that connect two individuals when a superclass of them is given." + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "((,\n", + " ),\n", + " (,\n", + " ),\n", + " (,\n", + " ),\n", + " (,\n", + " ),\n", + " (,\n", + " ),\n", + " (,\n", + " ),\n", + " (,\n", + " ))" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freiburg.get(rel=owl.topObjectProperty, return_rel=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Operations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Operations are actions (written in Python) that can be executed on instances of specific ontology classes that they are defined for." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A great example of the applications of operations is the interaction with file objects in SimPhoNy wrappers that support it, for example, the included dataspace wrapper." + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "from pathlib import Path\n", + "from tempfile import TemporaryDirectory\n", + "from urllib import request\n", + "\n", + "from IPython.display import Image\n", + "\n", + "from simphony_osp.wrappers import Dataspace\n", + "\n", + "dataspace_directory = TemporaryDirectory()\n", + "example_directory = TemporaryDirectory()\n", + "\n", + "# Download a picture of Freiburg using urllib\n", + "# from _Visit Freiburg_ - https://visit.freiburg.de\n", + "url = (\n", + " \"https://visit.freiburg.de/extension/portal-freiburg\"\n", + " \"/var/storage/images/media/bibliothek/teaser-bilder-startseite\"\n", + " \"/freiburg-kunst-kultur-copyright-fwtm-polkowski/225780-1-ger-DE\"\n", + " \"/freiburg-kunst-kultur-copyright-fwtm-polkowski_grid_medium.jpg\"\n", + ")\n", + "file, response = request.urlretrieve(url)\n", + "\n", + "# Open a dataspace session in a temporary directory\n", + "with Dataspace(dataspace_directory.name, True) as session:\n", + " # Create an individual belonging to SimPhoNy's file class\n", + " picture = simphony.File(\n", + " iri='http://example.org/freiburg#my_picture'\n", + " )\n", + " \n", + " # Use the `upload` operation to assign data to the file object\n", + " picture.operations.upload(file)\n", + " \n", + " # Commit the changes\n", + " session.commit()\n", + "\n", + "# Access the saved data and retrieve the Picture using the `download` operation\n", + "with Dataspace(dataspace_directory.name, True) as session:\n", + " picture = session.from_identifier('http://example.org/freiburg#my_picture')\n", + " download_path = Path(example_directory.name) / 'my_picture.jpg'\n", + " picture.operations.download(download_path)\n", + " \n", + "# Uncomment this line to show the downloaded picture\n", + "# (you can do so by running the tutorial yourself using Binder)\n", + "# Image(download_path)" + ] } - ], - "source": [ - "print(freiburg.get().__repr__(), end='\\n'*2) # returns everything attached to Freiburg (a relationship set)\n", - "\n", - "print(freiburg.get(rel=city.hasInhabitant).__repr__(), end='\\n'*2) # returns only the citizens (a relationship set)\n", - "\n", - "print(freiburg.get(oclass=city.Citizen).__repr__(), end='\\n'*2) # also returns only the citizens (a relationship set)\n", - "\n", - "# filtering specific individuals (can be combined with class and relationship filters)\n", - "print(freiburg.get(citizen_1).__repr__())\n", - "print(freiburg.get(citizen_1, citizen_2).__repr__())\n", - "print(freiburg.get(citizen_1.identifier).__repr__())\n", - "print(freiburg.get('https://example.org/city#unknown_citizen').__repr__())\n", - "print(freiburg.get(citizen_1, rel=city.hasChild).__repr__())\n", - "print(freiburg.get(citizen_1, rel=city.hasInhabitant).__repr__())\n", - "print(freiburg.get(citizen_1, rel=city.hasInhabitant, oclass=city.Building).__repr__())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Using the `get` and `iter` methods, it is also possible to discover the specific relationships that connect two individuals when a superclass of them is given." - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "((,\n", - " ),\n", - " (,\n", - " ),\n", - " (,\n", - " ),\n", - " (,\n", - " ),\n", - " (,\n", - " ),\n", - " (,\n", - " ),\n", - " (,\n", - " ))" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" + ], + "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.8.12" } - ], - "source": [ - "freiburg.get(rel=owl.topObjectProperty, return_rel=True)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Operations" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Operations are actions (written in Python) that can be executed on instances of specific ontology classes that they are defined for." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A great example of the applications of operations is the interaction with file objects in SimPhoNy wrappers that support it, for example, the included dataspace wrapper." - ] - }, - { - "cell_type": "code", - "execution_count": 26, - "metadata": {}, - "outputs": [], - "source": [ - "from pathlib import Path\n", - "from tempfile import TemporaryDirectory\n", - "from urllib import request\n", - "\n", - "from IPython.display import Image\n", - "\n", - "from simphony_osp.wrappers import Dataspace\n", - "\n", - "dataspace_directory = TemporaryDirectory()\n", - "example_directory = TemporaryDirectory()\n", - "\n", - "# Download a picture of Freiburg using urllib\n", - "# from _Visit Freiburg_ - https://visit.freiburg.de\n", - "url = (\n", - " \"https://visit.freiburg.de/extension/portal-freiburg\"\n", - " \"/var/storage/images/media/bibliothek/teaser-bilder-startseite\"\n", - " \"/freiburg-kunst-kultur-copyright-fwtm-polkowski/225780-1-ger-DE\"\n", - " \"/freiburg-kunst-kultur-copyright-fwtm-polkowski_grid_medium.jpg\"\n", - ")\n", - "file, response = request.urlretrieve(url)\n", - "\n", - "# Open a dataspace session in a temporary directory\n", - "with Dataspace(dataspace_directory.name, True) as session:\n", - " # Create an individual belonging to SimPhoNy's file class\n", - " picture = simphony.File(\n", - " iri='http://example.org/freiburg#my_picture'\n", - " )\n", - " \n", - " # Use the `upload` operation to assign data to the file object\n", - " picture.operations.upload(file)\n", - " \n", - " # Commit the changes\n", - " session.commit()\n", - "\n", - "# Access the saved data and retrieve the Picture using the `download` operation\n", - "with Dataspace(dataspace_directory.name, True) as session:\n", - " picture = session.from_identifier('http://example.org/freiburg#my_picture')\n", - " download_path = Path(example_directory.name) / 'my_picture.jpg'\n", - " picture.operations.download(download_path)\n", - " \n", - "# Uncomment this line to show the downloaded picture\n", - "# (you can do so by running the tutorial yourself using Binder)\n", - "# Image(download_path)" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/sessions/import_export.ipynb b/docs/usage/sessions/import_export.ipynb index f49d728..530e719 100644 --- a/docs/usage/sessions/import_export.ipynb +++ b/docs/usage/sessions/import_export.ipynb @@ -1,515 +1,515 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "boxed-professional", - "metadata": {}, - "source": [ - "# RDF Import and export" - ] - }, - { - "cell_type": "markdown", - "id": "operational-honey", - "metadata": {}, - "source": [ - "
\n", - " \n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fimport_export.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
\n", - "\n", - "SimPhoNy sessions store the ontology individual information using the [RDF standard](https://www.w3.org/TR/rdf-concepts/) in an [RDF graph object](https://rdflib.readthedocs.io/en/stable/intro_to_graphs.html) from the [RDFLib](https://github.com/RDFLib/rdflib) library. Exporting such RDF graph is possible using the functions [import_file](../../api_reference.md#simphony_osp.tools.import_file) and [export_file](../../api_reference.md#simphony_osp.tools.export_file)." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "94ca2509-eabd-4311-b531-1fd2269d27ad", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.tools import import_file, export_file" - ] - }, - { - "cell_type": "markdown", - "id": "qualified-works", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The full API specifications of the import and export functions can be found on the\n", - "[API reference page](../../api_reference.md).\n", - " \n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "id": "driving-injury", - "metadata": {}, - "source": [ - "In the examples on this page, the [city ontology](../ontologies/ontologies_included.md#the-city-ontology) is used. Make sure the city ontology is installed. If not, run the following command:" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "dying-accreditation", - "metadata": {}, - "outputs": [], - "source": [ - "!pico install city" - ] - }, - { - "cell_type": "markdown", - "id": "lonely-listening", - "metadata": {}, - "source": [ - "Then create a few ontology individuals" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "considered-leonard", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city\n", - "\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "peter = city.Citizen(name=\"Peter\", age=30)\n", - "anne = city.Citizen(name=\"Anne\", age=20)\n", - "freiburg[city.hasInhabitant] += peter, anne" - ] - }, - { - "cell_type": "markdown", - "id": "e15dc482-63aa-4eae-9682-2f32f363bb4c", - "metadata": {}, - "source": [ - "## Exporting individuals" - ] - }, - { - "cell_type": "markdown", - "id": "worth-province", - "metadata": {}, - "source": [ - "The `export_file` function allows to export either all the contents of a session, or select a few ontology individuals to be exported." - ] - }, - { - "cell_type": "markdown", - "id": "cf167dfe-aa6d-4b12-955f-edf3d64cf9b0", - "metadata": {}, - "source": [ - "For example, exporting Freiburg and Peter" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "monthly-anxiety", - "metadata": {}, - "outputs": [], - "source": [ - "export_file({freiburg, peter}, file='./data.ttl', format='turtle')" - ] - }, - { - "cell_type": "markdown", - "id": "795aea94-ded2-43e0-8037-07412a9b93b0", - "metadata": {}, - "source": [ - "creates the file `data.ttl` with the following content." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "outstanding-wound", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@prefix ns1: .\n", - "@prefix xsd: .\n", - "\n", - " a ns1:City ;\n", - " ns1:coordinates \"13YFp0RR93AD@t&xBo{#)k4YS)LtJz\"^^ ;\n", - " ns1:hasInhabitant ;\n", - " ns1:name \"Freiburg\"^^xsd:string .\n", - "\n", - " a ns1:Citizen ;\n", - " ns1:age 30 ;\n", - " ns1:name \"Peter\"^^xsd:string .\n", - "\n" - ] - } - ], - "source": [ - "from sys import platform\n", - "\n", - "if platform == 'win32':\n", - " !more data.ttl\n", - "else:\n", - " !cat data.ttl" - ] - }, - { - "cell_type": "markdown", - "id": "e10d2793-7763-4929-b017-e5e66087b09a", - "metadata": {}, - "source": [ - "Note that when individuals that are connected are **exported together**, their connections are kept in the exported file." - ] - }, - { - "cell_type": "markdown", - "id": "afd633af-b85c-449b-94c7-2ff99a097150", - "metadata": {}, - "source": [ - "If instead, you wish to export all the individuals in a session, then pass the session object to be exported." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "7eb2c80b-42ad-447b-9b46-47365a639cbc", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "@prefix city: .\n", - "@prefix xsd: .\n", - "\n", - " a city:City ;\n", - " city:coordinates \"13YFp0RR93AD@t&xBo{#)k4YS)LtJz\"^^ ;\n", - " city:hasInhabitant ,\n", - " ;\n", - " city:name \"Freiburg\"^^xsd:string .\n", - "\n", - " a city:Citizen ;\n", - " city:age 30 ;\n", - " city:name \"Peter\"^^xsd:string .\n", - "\n", - " a city:Citizen ;\n", - " city:age 20 ;\n", - " city:name \"Anne\"^^xsd:string .\n", - "\n" - ] - } - ], - "source": [ - "from simphony_osp.session import core_session\n", - "\n", - "export_file(core_session, file='./data.ttl', format='turtle')\n", - "\n", - "if platform == 'win32':\n", - " !more data.ttl\n", - "else:\n", - " !cat data.ttl" - ] - }, - { - "cell_type": "markdown", - "id": "offshore-cotton", - "metadata": {}, - "source": [ - "You can change the output format by entering a different value for the parameter `format`. A list of supported formats is available on [this page](../ontologies/supported_formats.html#supported-formats)." - ] - }, - { - "cell_type": "markdown", - "id": "601d4d0d-b00d-4680-9b9f-1c80899cdc03", - "metadata": {}, - "source": [ - "## Importing individuals" - ] - }, - { - "cell_type": "markdown", - "id": "derived-advancement", - "metadata": {}, - "source": [ - "To import data, use the `import_file` method. Let's assume we wish to import the data from the previous example in a new session. The following code will help us achieve our aim:" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "stable-session", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.session import Session\n", - "from simphony_osp.tools import import_file\n", - "\n", - "session = Session(); session.locked = True\n", - "\n", - "with session:\n", - " import_file('./data.ttl')" - ] - }, - { - "cell_type": "markdown", - "id": "virgin-river", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "The format is automatically inferred from the file extension. To specify it explicitly, you can add the `format` parameter, like so: `import_file('./data.ttl', format='turtle')`.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "40390384-0a1c-4920-98af-3f09f03c6bec", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "A `session` keyword argument can be optionally provided. When not specified, data is imported to the default sesion. You can specify the session explicitly like so: `import_file('./data.ttl', session=session)`.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "higher-short", - "metadata": {}, - "source": [ - "Now we can verify the data was indeed imported:" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "suspended-albert", - "metadata": {}, - "outputs": [ - { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#70d74233-989f-4cb2-9b67-3635801b2037\n", - "\n", - "70d74233...037\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#3153c78e-a5ee-4065-913a-776c33c30c9e\n", - "\n", - "3153c78e...c9e\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61\n", - "\n", - "e0eb6516...a61\n", - "classes: City (city)\n", - "coordinates: [47.997791  7.842609]\n", - "name: Freiburg\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61->https___www.simphony-osp.eu_entity#70d74233-989f-4cb2-9b67-3635801b2037\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61->https___www.simphony-osp.eu_entity#3153c78e-a5ee-4065-913a-776c33c30c9e\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cells": [ + { + "cell_type": "markdown", + "id": "boxed-professional", + "metadata": {}, + "source": [ + "# RDF Import and export" + ] + }, + { + "cell_type": "markdown", + "id": "operational-honey", + "metadata": {}, + "source": [ + "
\n", + " \n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fimport_export.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
\n", + "\n", + "SimPhoNy sessions store the ontology individual information using the [RDF standard](https://www.w3.org/TR/rdf-concepts/) in an [RDF graph object](https://rdflib.readthedocs.io/en/stable/intro_to_graphs.html) from the [RDFLib](https://github.com/RDFLib/rdflib) library. Exporting such RDF graph is possible using the functions [import_file](../../api_reference.md#simphony_osp.tools.import_file) and [export_file](../../api_reference.md#simphony_osp.tools.export_file)." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "94ca2509-eabd-4311-b531-1fd2269d27ad", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.tools import import_file, export_file" + ] + }, + { + "cell_type": "markdown", + "id": "qualified-works", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The full API specifications of the import and export functions can be found on the\n", + "[API reference page](../../api_reference.md).\n", + " \n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "id": "driving-injury", + "metadata": {}, + "source": [ + "In the examples on this page, the [city ontology](../ontologies/ontologies_included.md#the-city-ontology) is used. Make sure the city ontology is installed. If not, run the following command:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "dying-accreditation", + "metadata": {}, + "outputs": [], + "source": [ + "!pico install city" + ] + }, + { + "cell_type": "markdown", + "id": "lonely-listening", + "metadata": {}, + "source": [ + "Then create a few ontology individuals" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "considered-leonard", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city\n", + "\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "peter = city.Citizen(name=\"Peter\", age=30)\n", + "anne = city.Citizen(name=\"Anne\", age=20)\n", + "freiburg[city.hasInhabitant] += peter, anne" + ] + }, + { + "cell_type": "markdown", + "id": "e15dc482-63aa-4eae-9682-2f32f363bb4c", + "metadata": {}, + "source": [ + "## Exporting individuals" + ] + }, + { + "cell_type": "markdown", + "id": "worth-province", + "metadata": {}, + "source": [ + "The `export_file` function allows to export either all the contents of a session, or select a few ontology individuals to be exported." + ] + }, + { + "cell_type": "markdown", + "id": "cf167dfe-aa6d-4b12-955f-edf3d64cf9b0", + "metadata": {}, + "source": [ + "For example, exporting Freiburg and Peter" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "monthly-anxiety", + "metadata": {}, + "outputs": [], + "source": [ + "export_file({freiburg, peter}, file='./data.ttl', format='turtle')" + ] + }, + { + "cell_type": "markdown", + "id": "795aea94-ded2-43e0-8037-07412a9b93b0", + "metadata": {}, + "source": [ + "creates the file `data.ttl` with the following content." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "outstanding-wound", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "@prefix ns1: .\n", + "@prefix xsd: .\n", + "\n", + " a ns1:City ;\n", + " ns1:coordinates \"13YFp0RR93AD@t&xBo{#)k4YS)LtJz\"^^ ;\n", + " ns1:hasInhabitant ;\n", + " ns1:name \"Freiburg\"^^xsd:string .\n", + "\n", + " a ns1:Citizen ;\n", + " ns1:age 30 ;\n", + " ns1:name \"Peter\"^^xsd:string .\n", + "\n" + ] + } + ], + "source": [ + "from sys import platform\n", + "\n", + "if platform == 'win32':\n", + " !more data.ttl\n", + "else:\n", + " !cat data.ttl" + ] + }, + { + "cell_type": "markdown", + "id": "e10d2793-7763-4929-b017-e5e66087b09a", + "metadata": {}, + "source": [ + "Note that when individuals that are connected are **exported together**, their connections are kept in the exported file." + ] + }, + { + "cell_type": "markdown", + "id": "afd633af-b85c-449b-94c7-2ff99a097150", + "metadata": {}, + "source": [ + "If instead, you wish to export all the individuals in a session, then pass the session object to be exported." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "7eb2c80b-42ad-447b-9b46-47365a639cbc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "@prefix city: .\n", + "@prefix xsd: .\n", + "\n", + " a city:City ;\n", + " city:coordinates \"13YFp0RR93AD@t&xBo{#)k4YS)LtJz\"^^ ;\n", + " city:hasInhabitant ,\n", + " ;\n", + " city:name \"Freiburg\"^^xsd:string .\n", + "\n", + " a city:Citizen ;\n", + " city:age 30 ;\n", + " city:name \"Peter\"^^xsd:string .\n", + "\n", + " a city:Citizen ;\n", + " city:age 20 ;\n", + " city:name \"Anne\"^^xsd:string .\n", + "\n" + ] + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.session import core_session\n", + "\n", + "export_file(core_session, file='./data.ttl', format='turtle')\n", + "\n", + "if platform == 'win32':\n", + " !more data.ttl\n", + "else:\n", + " !cat data.ttl" + ] + }, + { + "cell_type": "markdown", + "id": "offshore-cotton", + "metadata": {}, + "source": [ + "You can change the output format by entering a different value for the parameter `format`. A list of supported formats is available on [this page](../ontologies/supported_formats.html#supported-formats)." + ] + }, + { + "cell_type": "markdown", + "id": "601d4d0d-b00d-4680-9b9f-1c80899cdc03", + "metadata": {}, + "source": [ + "## Importing individuals" + ] + }, + { + "cell_type": "markdown", + "id": "derived-advancement", + "metadata": {}, + "source": [ + "To import data, use the `import_file` method. Let's assume we wish to import the data from the previous example in a new session. The following code will help us achieve our aim:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "stable-session", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.session import Session\n", + "from simphony_osp.tools import import_file\n", + "\n", + "session = Session(); session.locked = True\n", + "\n", + "with session:\n", + " import_file('./data.ttl')" + ] + }, + { + "cell_type": "markdown", + "id": "virgin-river", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "The format is automatically inferred from the file extension. To specify it explicitly, you can add the `format` parameter, like so: `import_file('./data.ttl', format='turtle')`.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "40390384-0a1c-4920-98af-3f09f03c6bec", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "A `session` keyword argument can be optionally provided. When not specified, data is imported to the default sesion. You can specify the session explicitly like so: `import_file('./data.ttl', session=session)`.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "higher-short", + "metadata": {}, + "source": [ + "Now we can verify the data was indeed imported:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "suspended-albert", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#70d74233-989f-4cb2-9b67-3635801b2037\n", + "\n", + "70d74233...037\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#3153c78e-a5ee-4065-913a-776c33c30c9e\n", + "\n", + "3153c78e...c9e\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61\n", + "\n", + "e0eb6516...a61\n", + "classes: City (city)\n", + "coordinates: [47.997791  7.842609]\n", + "name: Freiburg\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61->https___www.simphony-osp.eu_entity#70d74233-989f-4cb2-9b67-3635801b2037\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#e0eb6516-b2f8-4323-a407-f4a98bf46a61->https___www.simphony-osp.eu_entity#3153c78e-a5ee-4065-913a-776c33c30c9e\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.tools import semantic2dot\n", + "\n", + "semantic2dot(session)" + ] + }, + { + "cell_type": "markdown", + "id": "8b84a2b7-0bd9-4cf4-aa09-a1b2138ba43e", + "metadata": {}, + "source": [ + "## Interpretation of RDF files" + ] + }, + { + "cell_type": "markdown", + "id": "81211841-d564-4974-b0a7-eef4982fa3e4", + "metadata": {}, + "source": [ + "The [ontology languages supported by SimPhoNy](../ontologies/supported_formats.md) can be serialized as RDF files, but the [RDF standard](https://www.w3.org/TR/rdf-concepts/) can store data that does not necessarily have anything to do with an ontology. Moreover, as described in the [introduction to sessions](introduction.ipynb), SimPhoNy sessions have been designed to exlusively store assertional knowledge (ontology individuals). \n", + "\n", + "Due to these factors, SimPhoNy enforces a few constraints when importing and exporting individuals from/to RDF files, that can, however, **also be disabled if desired**.\n", + "\n", + "1. No terminological knowledge can be present in the file. Any RDF triple with predicate `rdf:type` and one of `owl:Class`, `rdfs:Class`, `owl:AnnotationProperty`, `rdf:Property`, `owl:DatatypeProperty`, `owl:ObjectProperty`, `owl:Restriction` as object raises an exception.\n", + "\n", + "2. The subjects of any RDF triple with predicate `rdf:type` and an IRI not listed above as object are considered to be the identifiers of ontology individuals. Therefore, SymPhoNy will look into its installed ontologies for a class matching the object of the triple. If this lookup fails, an exception is raised. This behavior is meant to prevent you from making the mistake of importing data for which you have not installed the corresponding ontology.\n", + "\n", + "3. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate different from `rdf:type` that cannot be recognized as an annotation, relationship nor an attribute, an exception will be raised.\n", + "\n", + "4. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as a relationship, but has an object that cannot be recognized as an ontology individual (for example, because no `rdf:type` has been defined for it), then an exception will be raised.\n", + "\n", + "5. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as a relationship, but has a literal as an object, an exception will be raised.\n", + "\n", + "6. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as an attribute, but has a IRI as an object, an exception will be raised.\n", + "\n", + "7. Any triples whose subject cannot be identified as terminological knowledge, as ontology individuals, or for which (2) does not apply are **not imported**. No warning nor exception of any kind is raised for such triples." + ] + }, + { + "cell_type": "markdown", + "id": "97478c07-c469-4f64-b219-ff1d12e3b322", + "metadata": {}, + "source": [ + "
\n", + "
Warning
\n", + " \n", + "Point (7) implies that using the default options, you can lose data that was originally in the source, **without** warnings nor errors to notify you about it. Keep reading to learn how to prevent it. \n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "29fbacc8-3c05-4f4c-a7e2-f8836c1c7535", + "metadata": {}, + "source": [ + "There are two keyword arguments that can be passed to the import and export functions to bypass these checks.\n", + "\n", + "- `all_triples`: When set to `True`, no exceptions will be raised for points (2)*, (3), (4), (5), (6). Warnings will still be emitted.\n", + "- `all_statements`: When set to `True`, none of the points above apply. All RDF triples are imported, and **no information is lost**. No warnings are emitted." + ] + }, + { + "cell_type": "markdown", + "id": "e3208b1d-bc73-4a8c-a541-dd30f0a970f8", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "\\* To be recognized as an ontology individual, at least one of the types of the subject need to be defined in the [installed ontologies](../ontologies/pico.md). If you use `all_triples=True` when none of the types are defined in the installed ontologies, then (7) applies to such subject (its information is lost).\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "b15e4a71-b146-45da-9b55-e7306725dba0", + "metadata": {}, + "source": [ + "
\n", + "
Warning
\n", + " \n", + "Be careful when using `all_triples` and especially, when using `all_statements`. SimPhoNy's sessions have been designed to work only with ontology individuals. If you use `all_statements=True`, then also classes, relationships, annotations and attributes will be imported to the session, but as SimPhoNy is not ready to deal with this situation, this may lead to errors.\n", + " \n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "id": "00cbc181-d4b3-4c12-847e-5b3c97f88579", + "metadata": {}, + "source": [ + "Below there is sample RDF graph that helps understanding all the cases." + ] + }, + { + "cell_type": "markdown", + "id": "96b841a5-80fa-4a9b-9a07-44bde08c31c0", + "metadata": {}, + "source": [ + "![Sample RDF graph exemplifying cases where the constraints above apply](../../_static/importexport_graph.png)" + ] + }, + { + "cell_type": "markdown", + "id": "d8a3156b-c999-4097-8478-b003f6a357f6", + "metadata": {}, + "source": [ + "1. The triple (`example:Skaters`, `rdf:type`, `owl:Class`) would trigger this case, because it defines terminological knowledge.\n", + "2. The triple (`example:Marco`, `rdf:type`, `foaf:Person`) matches this case, because the namespace `foaf` is not installed.\n", + "3. The triple (`example:Klaus`, `foaf:knows`, `example:Lena`) raises an exception, because the namespace `foaf` is not installed.\n", + "4. The triple (`example:Freiburg`, `city:hasInhabitant`, `example:Rob`) triggers this case, because `example:Rob` does not have any type assigned and therefore, it is not identified as an ontology individual.\n", + "5. The triple (`example:Freiburg`, `city:hasWorker`, `Lena (xsd:string)`) matches this case, as \"has worker\" is a relationship, but the object is a literal.\n", + "6. The triple (`example:Freiburg`, `city:coordinates`, ``) raises an exception, because \"coordinates\" is an attribute, but the object is an IRI.\n", + "7. The triple (`example:Something`, `example:predicate`, `example:Thing`) fits into this case." ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" } - ], - "source": [ - "from simphony_osp.tools import semantic2dot\n", - "\n", - "semantic2dot(session)" - ] - }, - { - "cell_type": "markdown", - "id": "8b84a2b7-0bd9-4cf4-aa09-a1b2138ba43e", - "metadata": {}, - "source": [ - "## Interpretation of RDF files" - ] - }, - { - "cell_type": "markdown", - "id": "81211841-d564-4974-b0a7-eef4982fa3e4", - "metadata": {}, - "source": [ - "The [ontology languages supported by SimPhoNy](../ontologies/supported_formats.md) can be serialized as RDF files, but the [RDF standard](https://www.w3.org/TR/rdf-concepts/) can store data that does not necessarily have anything to do with an ontology. Moreover, as described in the [introduction to sessions](introduction.ipynb), SimPhoNy sessions have been designed to exlusively store assertional knowledge (ontology individuals). \n", - "\n", - "Due to these factors, SimPhoNy enforces a few constraints when importing and exporting individuals from/to RDF files, that can, however, **also be disabled if desired**.\n", - "\n", - "1. No terminological knowledge can be present in the file. Any RDF triple with predicate `rdf:type` and one of `owl:Class`, `rdfs:Class`, `owl:AnnotationProperty`, `rdf:Property`, `owl:DatatypeProperty`, `owl:ObjectProperty`, `owl:Restriction` as object raises an exception.\n", - "\n", - "2. The subjects of any RDF triple with predicate `rdf:type` and an IRI not listed above as object are considered to be the identifiers of ontology individuals. Therefore, SymPhoNy will look into its installed ontologies for a class matching the object of the triple. If this lookup fails, an exception is raised. This behavior is meant to prevent you from making the mistake of importing data for which you have not installed the corresponding ontology.\n", - "\n", - "3. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate different from `rdf:type` that cannot be recognized as an annotation, relationship nor an attribute, an exception will be raised.\n", - "\n", - "4. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as a relationship, but has an object that cannot be recognized as an ontology individual (for example, because no `rdf:type` has been defined for it), then an exception will be raised.\n", - "\n", - "5. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as a relationship, but has a literal as an object, an exception will be raised.\n", - "\n", - "6. If an RDF triple where the subject has been succesfully identified as an ontology individual has a predicate that can be recognized as an attribute, but has a IRI as an object, an exception will be raised.\n", - "\n", - "7. Any triples whose subject cannot be identified as terminological knowledge, as ontology individuals, or for which (2) does not apply are **not imported**. No warning nor exception of any kind is raised for such triples." - ] - }, - { - "cell_type": "markdown", - "id": "97478c07-c469-4f64-b219-ff1d12e3b322", - "metadata": {}, - "source": [ - "
\n", - "
Warning
\n", - " \n", - "Point (7) implies that using the default options, you can lose data that was originally in the source, **without** warnings nor errors to notify you about it. Keep reading to learn how to prevent it. \n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "29fbacc8-3c05-4f4c-a7e2-f8836c1c7535", - "metadata": {}, - "source": [ - "There are two keyword arguments that can be passed to the import and export functions to bypass these checks.\n", - "\n", - "- `all_triples`: When set to `True`, no exceptions will be raised for points (2)*, (3), (4), (5), (6). Warnings will still be emitted.\n", - "- `all_statements`: When set to `True`, none of the points above apply. All RDF triples are imported, and **no information is lost**. No warnings are emitted." - ] - }, - { - "cell_type": "markdown", - "id": "e3208b1d-bc73-4a8c-a541-dd30f0a970f8", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "\\* To be recognized as an ontology individual, at least one of the types of the subject need to be defined in the [installed ontologies](../ontologies/pico.md). If you use `all_triples=True` when none of the types are defined in the installed ontologies, then (7) applies to such subject (its information is lost).\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "b15e4a71-b146-45da-9b55-e7306725dba0", - "metadata": {}, - "source": [ - "
\n", - "
Warning
\n", - " \n", - "Be careful when using `all_triples` and especially, when using `all_statements`. SimPhoNy's sessions have been designed to work only with ontology individuals. If you use `all_statements=True`, then also classes, relationships, annotations and attributes will be imported to the session, but as SimPhoNy is not ready to deal with this situation, this may lead to errors.\n", - " \n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "id": "00cbc181-d4b3-4c12-847e-5b3c97f88579", - "metadata": {}, - "source": [ - "Below there is sample RDF graph that helps understanding all the cases." - ] - }, - { - "cell_type": "markdown", - "id": "96b841a5-80fa-4a9b-9a07-44bde08c31c0", - "metadata": {}, - "source": [ - "![Sample RDF graph exemplifying cases where the constraints above apply](../../_static/importexport_graph.png)" - ] - }, - { - "cell_type": "markdown", - "id": "d8a3156b-c999-4097-8478-b003f6a357f6", - "metadata": {}, - "source": [ - "1. The triple (`example:Skaters`, `rdf:type`, `owl:Class`) would trigger this case, because it defines terminological knowledge.\n", - "2. The triple (`example:Marco`, `rdf:type`, `foaf:Person`) matches this case, because the namespace `foaf` is not installed.\n", - "3. The triple (`example:Klaus`, `foaf:knows`, `example:Lena`) raises an exception, because the namespace `foaf` is not installed.\n", - "4. The triple (`example:Freiburg`, `city:hasInhabitant`, `example:Rob`) triggers this case, because `example:Rob` does not have any type assigned and therefore, it is not identified as an ontology individual.\n", - "5. The triple (`example:Freiburg`, `city:hasWorker`, `Lena (xsd:string)`) matches this case, as \"has worker\" is a relationship, but the object is a literal.\n", - "6. The triple (`example:Freiburg`, `city:coordinates`, ``) raises an exception, because \"coordinates\" is an attribute, but the object is an IRI.\n", - "7. The triple (`example:Something`, `example:predicate`, `example:Thing`) fits into this case." - ] - } - ], - "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.8.12" - }, + ], "metadata": { - "interpreter": { - "hash": "301cd6007de04cbbf15bca26f0bc1cb48004d089278091d760363de622bdd0c8" - } - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "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.8.12" + }, + "metadata": { + "interpreter": { + "hash": "301cd6007de04cbbf15bca26f0bc1cb48004d089278091d760363de622bdd0c8" + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/sessions/introduction.ipynb b/docs/usage/sessions/introduction.ipynb index dff3fc8..4d188fe 100644 --- a/docs/usage/sessions/introduction.ipynb +++ b/docs/usage/sessions/introduction.ipynb @@ -1,216 +1,216 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fintroduction.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In SimPhoNy, [assertional knowledge](../assertional_knowledge.ipynb) is stored in _sessions_. You may think of a session as a \"box\" were [ontology individuals](../assertional_knowledge.ipynb#Ontology-individual-objects) can be placed. But sessions go beyond just storing assertional knowledge. Sessions can be connected to [SimPhoNy Wrappers](../wrappers/index.md). Each wrapper is a piece of software that seamlessly translates the assertional knowledge to a form that is compatible with a specific simulation engine, database, data repository or file format.\n", - "\n", - "In order to keep things simple, this section focuses on sessions that are not connected to any wrapper. All the information stored in such sessions is stored in the computer's volatile memory and lost when the Python shell is closed. After having read this section, you can head to the [next one](../wrappers/index.md) to learn more about SimPhoNy Wrappers." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All ontology individuals in SimPhoNy are stored in a session. The session where an individual is stored is always accesible through the [session](../../api_reference.md#simphony_osp.ontology.OntologyEntity.session) attribute, which is **writable**. In fact, changing this attribute is one of the several ways to transfer an ontology individual between sessions." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ + "cells": [ { - "data": { - "text/plain": [ - "" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fintroduction.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.namespaces import city\n", - "\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "freiburg.session" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "But where are newly created individuals stored? Indeed, when a new individual is created, it has to be stored in a session. It is possible to pass a [session object](../../api_reference.md#simphony_osp.session.Session) to the call using the `session` keyword argument to choose where the individual will be stored." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "(, True, False)" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In SimPhoNy, [assertional knowledge](../assertional_knowledge.ipynb) is stored in _sessions_. You may think of a session as a \"box\" were [ontology individuals](../assertional_knowledge.ipynb#Ontology-individual-objects) can be placed. But sessions go beyond just storing assertional knowledge. Sessions can be connected to [SimPhoNy Wrappers](../wrappers/index.md). Each wrapper is a piece of software that seamlessly translates the assertional knowledge to a form that is compatible with a specific simulation engine, database, data repository or file format.\n", + "\n", + "In order to keep things simple, this section focuses on sessions that are not connected to any wrapper. All the information stored in such sessions is stored in the computer's volatile memory and lost when the Python shell is closed. After having read this section, you can head to the [next one](../wrappers/index.md) to learn more about SimPhoNy Wrappers." ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.session import Session\n", - "\n", - "session_A = Session() # create a new session\n", - "paris = city.City(\n", - " name=\"Paris\", coordinates=[48.85333, 2.34885],\n", - " session=session_A\n", - ")\n", - "session_A, paris in session_A, freiburg in session_A" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "But such argument is optional. When it is not specified, the individual is stored on the so-called _default session_. Every time you work with SimPhoNy in a Python shell, it creates a new session, called _Core Session_ and sets it as the default session. The default session can be changed later to any of your choice. The [Core Session](../../api_reference.md#simphony_osp.session.core_session) can be accessed at any time by importing it from the `simphony_osp.session` module." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "(, True, False)" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All ontology individuals in SimPhoNy are stored in a session. The session where an individual is stored is always accesible through the [session](../../api_reference.md#simphony_osp.ontology.OntologyEntity.session) attribute, which is **writable**. In fact, changing this attribute is one of the several ways to transfer an ontology individual between sessions." ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.session import core_session\n", - "\n", - "core_session, freiburg in core_session, paris in core_session" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "The interface of the [session object](../api_reference.md#simphony_osp.session.Session) has been designed to interact exclusively with ontology individuals, and therefore, this page only shows you how to use sessions to deal with assertional knowledge.\n", - " \n", - "However, there is no technical reason for such limitation. Sessions can actually store any ontology entity (including terminological knowledge). As a curiosity, the entities from the ontologies that you install using [pico](ontologies/pico.md) are stored in a hidden session that is not meant to be directly accessed.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The default session can be temporarily changed using the `with` statement." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "True True\n", - "False True\n" - ] + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.namespaces import city\n", + "\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "freiburg.session" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "But where are newly created individuals stored? Indeed, when a new individual is created, it has to be stored in a session. It is possible to pass a [session object](../../api_reference.md#simphony_osp.session.Session) to the call using the `session` keyword argument to choose where the individual will be stored." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(, True, False)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.session import Session\n", + "\n", + "session_A = Session() # create a new session\n", + "paris = city.City(\n", + " name=\"Paris\", coordinates=[48.85333, 2.34885],\n", + " session=session_A\n", + ")\n", + "session_A, paris in session_A, freiburg in session_A" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "But such argument is optional. When it is not specified, the individual is stored on the so-called _default session_. Every time you work with SimPhoNy in a Python shell, it creates a new session, called _Core Session_ and sets it as the default session. The default session can be changed later to any of your choice. The [Core Session](../../api_reference.md#simphony_osp.session.core_session) can be accessed at any time by importing it from the `simphony_osp.session` module." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(, True, False)" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from simphony_osp.session import core_session\n", + "\n", + "core_session, freiburg in core_session, paris in core_session" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "The interface of the [session object](../api_reference.md#simphony_osp.session.Session) has been designed to interact exclusively with ontology individuals, and therefore, this page only shows you how to use sessions to deal with assertional knowledge.\n", + " \n", + "However, there is no technical reason for such limitation. Sessions can actually store any ontology entity (including terminological knowledge). As a curiosity, the entities from the ontologies that you install using [pico](ontologies/pico.md) are stored in a hidden session that is not meant to be directly accessed.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The default session can be temporarily changed using the `with` statement." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True True\n", + "False True\n" + ] + } + ], + "source": [ + "session_B = Session()\n", + "\n", + "# this will be explained later\n", + "session_A.locked = True\n", + "session_B.locked = True\n", + "\n", + "with session_B:\n", + " london = city.City(name=\"London\", coordinates=[51.50737, -0.12767])\n", + " \n", + "print(paris in session_A, london in session_B)\n", + "\n", + "# Be careful when using the with statement with several session objects:\n", + "# keep in mind that the second will be the one set as default.\n", + "with session_A, session_B:\n", + " default_session = Session.get_default_session()\n", + " print(default_session is session_A, default_session is session_B)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Sessions actually work in a way similar to databases. To start using them, one first has to \"open\" or \"connect\" to them. After that, changes can be performed on the data they contain, but such changes are not made permanent until a \"commit\" is performed. When one finishes working with them, the connection should be \"closed\". Unconfirmed changes are lost when the connection is \"closed\".\n", + "\n", + "In SimPhoNy, all sessions are automatically \"opened\" when they are created. The \"commit\" and \"close\" operations are controlled manually.\n", + "\n", + "In spite of that general rule, for sessions that are not connected to a wrapper, which are the ones being illustrated in this page, the \"commit\" command actually does nothing, as confirmed changes have nowhere else to go and be made permanent. You can think of commits being automatic in this case. These sessions also do not implement the \"close\" command.\n", + "\n", + "Therefore, this general rule has just been introduced in order to present a useful mental model for working with _all_ sessions, which includes [sessions connected to a wrapper](../wrappers/index.md)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Having said that, it is now simpler to understand the purpose of the [locked attribute of session objects](../../api_reference.md#simphony_osp.session.Session.locked) that appears in the last example. The `with` statement not only sets a session as the default, but also _closes_ it when leaving its context. _Locking a session_ with the [locked](../../api_reference.md#simphony_osp.session.Session.locked) attribute prevents the session from being closed if one intents to continue using it. To restore the original behavior, set it to `False`." + ] } - ], - "source": [ - "session_B = Session()\n", - "\n", - "# this will be explained later\n", - "session_A.locked = True\n", - "session_B.locked = True\n", - "\n", - "with session_B:\n", - " london = city.City(name=\"London\", coordinates=[51.50737, -0.12767])\n", - " \n", - "print(paris in session_A, london in session_B)\n", - "\n", - "# Be careful when using the with statement with several session objects:\n", - "# keep in mind that the second will be the one set as default.\n", - "with session_A, session_B:\n", - " default_session = Session.get_default_session()\n", - " print(default_session is session_A, default_session is session_B)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Sessions actually work in a way similar to databases. To start using them, one first has to \"open\" or \"connect\" to them. After that, changes can be performed on the data they contain, but such changes are not made permanent until a \"commit\" is performed. When one finishes working with them, the connection should be \"closed\". Unconfirmed changes are lost when the connection is \"closed\".\n", - "\n", - "In SimPhoNy, all sessions are automatically \"opened\" when they are created. The \"commit\" and \"close\" operations are controlled manually.\n", - "\n", - "In spite of that general rule, for sessions that are not connected to a wrapper, which are the ones being illustrated in this page, the \"commit\" command actually does nothing, as confirmed changes have nowhere else to go and be made permanent. You can think of commits being automatic in this case. These sessions also do not implement the \"close\" command.\n", - "\n", - "Therefore, this general rule has just been introduced in order to present a useful mental model for working with _all_ sessions, which includes [sessions connected to a wrapper](../wrappers/index.md)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Having said that, it is now simpler to understand the purpose of the [locked attribute of session objects](../../api_reference.md#simphony_osp.session.Session.locked) that appears in the last example. The `with` statement not only sets a session as the default, but also _closes_ it when leaving its context. _Locking a session_ with the [locked](../../api_reference.md#simphony_osp.session.Session.locked) attribute prevents the session from being closed if one intents to continue using it. To restore the original behavior, set it to `False`." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.10.7" + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.7" + }, + "toc-showcode": false, + "toc-showtags": true }, - "toc-showcode": false, - "toc-showtags": true - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/sessions/management.ipynb b/docs/usage/sessions/management.ipynb index 1d6320e..a921a94 100644 --- a/docs/usage/sessions/management.ipynb +++ b/docs/usage/sessions/management.ipynb @@ -1,521 +1,521 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Managing the session contents\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fmanagement.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As said, sessions can be though of as a \"box\" that stores ontology individuals. Consequently, adding and removing individuals are among the operations that can be performed on them. \n", - "\n", - "As described in [one of the previous sections](../assertional_knowledge.ipynb), in SimPhoNy, an ontology individual is characterized by\n", - "\n", - "- the information about the ontology individual itself such as the classes it belongs to, its label and its attributes;\n", - "- the connections to other ontology individuals." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The methods [add](../../api_reference.md#simphony_osp.session.Session.add) and [delete](../../api_reference.md#simphony_osp.session.delete) try to accommodate this definition. To see how they work, consider a city example again." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city\n", - "\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "\n", - "neighborhoods = {\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Altstadt', [47.99525, 7.84726]),\n", - " ('Stühlinger', [47.99888, 7.83774]),\n", - " ('Neuburg', [48.00021, 7.86084]),\n", - " ('Herdern', [48.00779, 7.86268]),\n", - " ('Brühl', [48.01684, 7.843]),\n", - " ]\n", - "}\n", - "\n", - "citizen_1 = city.Citizen(name='Nikola', age=35)\n", - "citizen_2 = city.Citizen(name='Lena', age=70)\n", - "\n", - "freiburg[city.hasPart] |= neighborhoods\n", - "freiburg[city.hasInhabitant] += citizen_1, citizen_2" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Managing the session contents\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fmanagement.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As said, sessions can be though of as a \"box\" that stores ontology individuals. Consequently, adding and removing individuals are among the operations that can be performed on them. \n", + "\n", + "As described in [one of the previous sections](../assertional_knowledge.ipynb), in SimPhoNy, an ontology individual is characterized by\n", + "\n", + "- the information about the ontology individual itself such as the classes it belongs to, its label and its attributes;\n", + "- the connections to other ontology individuals." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The methods [add](../../api_reference.md#simphony_osp.session.Session.add) and [delete](../../api_reference.md#simphony_osp.session.delete) try to accommodate this definition. To see how they work, consider a city example again." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#21317ff8-e405-4333-9c2c-a10462e03811\n", - "\n", - "21317ff8...811\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934\n", - "\n", - "cc02ad20...934\n", - "classes: City (city)\n", - "coordinates: [47.997791  7.842609]\n", - "name: Freiburg\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#21317ff8-e405-4333-9c2c-a10462e03811\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#18bb022d-3c87-4d0d-8bde-527ffe5b877c\n", - "\n", - "18bb022d...77c\n", - "classes: Neighborhood (city)\n", - "coordinates: [47.99888  7.83774]\n", - "name: Stühlinger\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#18bb022d-3c87-4d0d-8bde-527ffe5b877c\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#596e4a1d-bb20-4d3f-9d03-05f32a699c41\n", - "\n", - "596e4a1d...c41\n", - "classes: Citizen (city)\n", - "age: 35\n", - "name: Nikola\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#596e4a1d-bb20-4d3f-9d03-05f32a699c41\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#7824a475-52e0-48b3-ac15-95cbe1d11298\n", - "\n", - "7824a475...298\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.01684  7.843  ]\n", - "name: Brühl\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#7824a475-52e0-48b3-ac15-95cbe1d11298\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#ec1484ec-94df-4bfc-bf37-ece246888089\n", - "\n", - "ec1484ec...089\n", - "classes: Neighborhood (city)\n", - "name: Neuburg\n", - "coordinates: [48.00021  7.86084]\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#ec1484ec-94df-4bfc-bf37-ece246888089\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#4070b09c-ab77-439b-8404-5e4fd1e0662e\n", - "\n", - "4070b09c...62e\n", - "classes: Neighborhood (city)\n", - "name: Altstadt\n", - "coordinates: [47.99525  7.84726]\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#4070b09c-ab77-439b-8404-5e4fd1e0662e\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#d136fbd0-3eb8-482b-908f-b5755cd94459\n", - "\n", - "d136fbd0...459\n", - "classes: Neighborhood (city)\n", - "name: Herdern\n", - "coordinates: [48.00779  7.86268]\n", - "session: 0x5608d3a41780\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#d136fbd0-3eb8-482b-908f-b5755cd94459\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city\n", + "\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "\n", + "neighborhoods = {\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Altstadt', [47.99525, 7.84726]),\n", + " ('St\u00fchlinger', [47.99888, 7.83774]),\n", + " ('Neuburg', [48.00021, 7.86084]),\n", + " ('Herdern', [48.00779, 7.86268]),\n", + " ('Br\u00fchl', [48.01684, 7.843]),\n", + " ]\n", + "}\n", + "\n", + "citizen_1 = city.Citizen(name='Nikola', age=35)\n", + "citizen_2 = city.Citizen(name='Lena', age=70)\n", + "\n", + "freiburg[city.hasPart] |= neighborhoods\n", + "freiburg[city.hasInhabitant] += citizen_1, citizen_2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#21317ff8-e405-4333-9c2c-a10462e03811\n", + "\n", + "21317ff8...811\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934\n", + "\n", + "cc02ad20...934\n", + "classes: City (city)\n", + "coordinates: [47.997791  7.842609]\n", + "name: Freiburg\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#21317ff8-e405-4333-9c2c-a10462e03811\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#18bb022d-3c87-4d0d-8bde-527ffe5b877c\n", + "\n", + "18bb022d...77c\n", + "classes: Neighborhood (city)\n", + "coordinates: [47.99888  7.83774]\n", + "name: St\u00fchlinger\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#18bb022d-3c87-4d0d-8bde-527ffe5b877c\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#596e4a1d-bb20-4d3f-9d03-05f32a699c41\n", + "\n", + "596e4a1d...c41\n", + "classes: Citizen (city)\n", + "age: 35\n", + "name: Nikola\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#596e4a1d-bb20-4d3f-9d03-05f32a699c41\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#7824a475-52e0-48b3-ac15-95cbe1d11298\n", + "\n", + "7824a475...298\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.01684  7.843  ]\n", + "name: Br\u00fchl\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#7824a475-52e0-48b3-ac15-95cbe1d11298\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#ec1484ec-94df-4bfc-bf37-ece246888089\n", + "\n", + "ec1484ec...089\n", + "classes: Neighborhood (city)\n", + "name: Neuburg\n", + "coordinates: [48.00021  7.86084]\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#ec1484ec-94df-4bfc-bf37-ece246888089\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#4070b09c-ab77-439b-8404-5e4fd1e0662e\n", + "\n", + "4070b09c...62e\n", + "classes: Neighborhood (city)\n", + "name: Altstadt\n", + "coordinates: [47.99525  7.84726]\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#4070b09c-ab77-439b-8404-5e4fd1e0662e\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#d136fbd0-3eb8-482b-908f-b5755cd94459\n", + "\n", + "d136fbd0...459\n", + "classes: Neighborhood (city)\n", + "name: Herdern\n", + "coordinates: [48.00779  7.86268]\n", + "session: 0x5608d3a41780\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cc02ad20-4c05-4257-8f40-47bb0e243934->https___www.simphony-osp.eu_entity#d136fbd0-3eb8-482b-908f-b5755cd94459\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.tools import semantic2dot # explained in a later section\n", + "\n", + "semantic2dot(freiburg, *neighborhoods, citizen_1, citizen_2)" ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.tools import semantic2dot # explained in a later section\n", - "\n", - "semantic2dot(freiburg, *neighborhoods, citizen_1, citizen_2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Then create a new session to transfer individuals to." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.session import Session\n", - "\n", - "session = Session()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Passing any individual to the method [add](../../api_reference.md#simphony_osp.session.Session.add) of the new session creates a copy of it. The copy contained in the new session is assigned the same identifier as the original." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "([],\n", - " 'Freiburg',\n", - " ,\n", - " set() )" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", + " \n", + "
" ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "freiburg_copy = session.add(freiburg)\n", - "list(session), freiburg_copy.name, freiburg_copy.coordinates, freiburg_copy.get()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In the example above, the variable `freiburg` refers now to the individual in the Core Session, while `freiburg_copy` refers to the copy of the individual that has been created in the new session." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As it can be inferred from the fact that the new session contains only one individual, only the _intrinsic_ information about the individual has been transferred, but not the connections to other ontology individuals nor any intrinsic information of the other ontology individuals themselves." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To keep the connection to another ontology individual, it is necessary to transfer **both of them together**." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "{, , , , } " + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Then create a new session to transfer individuals to." ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "session.clear() # this removes all individuals from the session\n", - "\n", - "copies = session.add(freiburg, neighborhoods) # note that Python iterables of individuals can also be passed to `add` (such as `neighborhoods`)\n", - "freiburg_copy = copies[0] # the order in which individuals were added is respected\n", - "freiburg_copy.get()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As shown in the example, the [clear](../../api_reference.md#simphony_osp.session.Session.clear) method removes all ontology individuals from a session. The [delete](../../api_reference.md#simphony_osp.session.Session.delete) method allows to exactly select the individuals to remove. Both ontology individuals and identifiers can be passed to [delete](../../api_reference.md#simphony_osp.session.Session.delete)." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "[]" + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.session import Session\n", + "\n", + "session = Session()" ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "session.delete(freiburg.identifier, copies[1:])\n", - "list(session)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A special situation arises when one tries to add an ontology individual to a session that already contains an individual with the same identifier." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "session_A = Session(); session_A.locked = True\n", - "with session_A:\n", - " lena_A = city.Citizen(name='Lena', age=70,\n", - " iri='https://example.org/entities#Lena')\n", - "\n", - "session_B = Session(); session_B.locked = True\n", - "with session_B:\n", - " lena_B = city.Citizen(name='Helena', age=31,\n", - " iri='https://example.org/entities#Lena')" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "tags": [ - "raises-exception" - ] - }, - "outputs": [ + }, { - "ename": "RuntimeError", - "evalue": "Some of the added entities already exist on the session.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mSession\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlena_A\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0msession\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlena_B\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# -> Fails, there is already an individual with the same identifier.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;32m~/Dokumente/SimPhoNy/simphony-osp/simphony_osp/session/session.py\u001b[0m in \u001b[0;36madd\u001b[0;34m(self, merge, exists_ok, all_triples, *individuals)\u001b[0m\n\u001b[1;32m 808\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mexists_ok\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 809\u001b[0m ):\n\u001b[0;32m--> 810\u001b[0;31m raise RuntimeError(\n\u001b[0m\u001b[1;32m 811\u001b[0m \u001b[0;34m\"Some of the added entities already exist on the session.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 812\u001b[0m )\n", - "\u001b[0;31mRuntimeError\u001b[0m: Some of the added entities already exist on the session." - ] - } - ], - "source": [ - "with Session() as session:\n", - " session.add(lena_A)\n", - " session.add(lena_B) # -> Fails, there is already an individual with the same identifier." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "When this happens, an exception is raised. It is still possible to copy the individual, but is necessary to decide whether:\n", - "\n", - "- the existing individual should be overwritten (default) or;\n", - "- the new individual should be merged with the existing one." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To apply default action (overwrite), use the keyword argument `exists_ok=True`." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Passing any individual to the method [add](../../api_reference.md#simphony_osp.session.Session.add) of the new session creates a copy of it. The copy contained in the new session is assigned the same identifier as the original." + ] + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "70 Lena\n", - "31 Helena\n" - ] - } - ], - "source": [ - "with Session() as session:\n", - " copy = session.add(lena_A)\n", - " print(copy.age, copy.name)\n", - " copy = session.add(lena_B, exists_ok=True)\n", - " print(copy.age, copy.name)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Overwriting replaces the classes, attributes, attribute values and connections to other ontology individuals." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To merge the new individual with the previous one, use `exists_ok=True, merge=True` instead." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "([],\n", + " 'Freiburg',\n", + " ,\n", + " set() )" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "freiburg_copy = session.add(freiburg)\n", + "list(session), freiburg_copy.name, freiburg_copy.coordinates, freiburg_copy.get()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In the example above, the variable `freiburg` refers now to the individual in the Core Session, while `freiburg_copy` refers to the copy of the individual that has been created in the new session." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As it can be inferred from the fact that the new session contains only one individual, only the _intrinsic_ information about the individual has been transferred, but not the connections to other ontology individuals nor any intrinsic information of the other ontology individuals themselves." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To keep the connection to another ontology individual, it is necessary to transfer **both of them together**." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{, , , , } " + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "session.clear() # this removes all individuals from the session\n", + "\n", + "copies = session.add(freiburg, neighborhoods) # note that Python iterables of individuals can also be passed to `add` (such as `neighborhoods`)\n", + "freiburg_copy = copies[0] # the order in which individuals were added is respected\n", + "freiburg_copy.get()" + ] + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "70 Lena\n", - "{70, 31} {'Helena', 'Lena'}\n" - ] + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As shown in the example, the [clear](../../api_reference.md#simphony_osp.session.Session.clear) method removes all ontology individuals from a session. The [delete](../../api_reference.md#simphony_osp.session.Session.delete) method allows to exactly select the individuals to remove. Both ontology individuals and identifiers can be passed to [delete](../../api_reference.md#simphony_osp.session.Session.delete)." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "session.delete(freiburg.identifier, copies[1:])\n", + "list(session)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A special situation arises when one tries to add an ontology individual to a session that already contains an individual with the same identifier." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "session_A = Session(); session_A.locked = True\n", + "with session_A:\n", + " lena_A = city.Citizen(name='Lena', age=70,\n", + " iri='https://example.org/entities#Lena')\n", + "\n", + "session_B = Session(); session_B.locked = True\n", + "with session_B:\n", + " lena_B = city.Citizen(name='Helena', age=31,\n", + " iri='https://example.org/entities#Lena')" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "tags": [ + "raises-exception" + ] + }, + "outputs": [ + { + "ename": "RuntimeError", + "evalue": "Some of the added entities already exist on the session.", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mSession\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlena_A\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0msession\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlena_B\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# -> Fails, there is already an individual with the same identifier.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m~/Dokumente/SimPhoNy/simphony-osp/simphony_osp/session/session.py\u001b[0m in \u001b[0;36madd\u001b[0;34m(self, merge, exists_ok, all_triples, *individuals)\u001b[0m\n\u001b[1;32m 808\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mexists_ok\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 809\u001b[0m ):\n\u001b[0;32m--> 810\u001b[0;31m raise RuntimeError(\n\u001b[0m\u001b[1;32m 811\u001b[0m \u001b[0;34m\"Some of the added entities already exist on the session.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 812\u001b[0m )\n", + "\u001b[0;31mRuntimeError\u001b[0m: Some of the added entities already exist on the session." + ] + } + ], + "source": [ + "with Session() as session:\n", + " session.add(lena_A)\n", + " session.add(lena_B) # -> Fails, there is already an individual with the same identifier." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When this happens, an exception is raised. It is still possible to copy the individual, but is necessary to decide whether:\n", + "\n", + "- the existing individual should be overwritten (default) or;\n", + "- the new individual should be merged with the existing one." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To apply default action (overwrite), use the keyword argument `exists_ok=True`." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "70 Lena\n", + "31 Helena\n" + ] + } + ], + "source": [ + "with Session() as session:\n", + " copy = session.add(lena_A)\n", + " print(copy.age, copy.name)\n", + " copy = session.add(lena_B, exists_ok=True)\n", + " print(copy.age, copy.name)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Overwriting replaces the classes, attributes, attribute values and connections to other ontology individuals." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To merge the new individual with the previous one, use `exists_ok=True, merge=True` instead." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "70 Lena\n", + "{70, 31} {'Helena', 'Lena'}\n" + ] + } + ], + "source": [ + "with Session() as session:\n", + " copy = session.add(lena_A)\n", + " print(copy.age, copy.name)\n", + " copy = session.add(lena_B, exists_ok=True, merge=True)\n", + " print(copy['age'], copy['name'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Merging combines the classes, atrributes, attribute values and connections of the two individuals." + ] } - ], - "source": [ - "with Session() as session:\n", - " copy = session.add(lena_A)\n", - " print(copy.age, copy.name)\n", - " copy = session.add(lena_B, exists_ok=True, merge=True)\n", - " print(copy['age'], copy['name'])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Merging combines the classes, atrributes, attribute values and connections of the two individuals." - ] - } - ], - "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.8.12" + ], + "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.8.12" + }, + "toc-showcode": false, + "toc-showtags": true }, - "toc-showcode": false, - "toc-showtags": true - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/sessions/queries.ipynb b/docs/usage/sessions/queries.ipynb index ad25146..e403d59 100644 --- a/docs/usage/sessions/queries.ipynb +++ b/docs/usage/sessions/queries.ipynb @@ -1,233 +1,233 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Queries: using the session object\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fqueries.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SimPhoNy's [session object](../../api_reference.md#simphony_osp.session.Session) implements methods that enable the retrieval of the ontology individuals it contains. The queries that can be run using such methods are extremely basic. If you need to run more advanced queries, head to the sections dealing with the [search module](search.ipynb) and [SPARQL](sparql.ipynb)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Consider a similar example from the city ontology again. Remember that by default, newly created individuals created are stored in the [Core Session](introduction.ipynb)." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city, rdfs\n", - "from simphony_osp.session import core_session\n", - "\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "\n", - "neighborhoods = {\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Altstadt', [47.99525, 7.84726]),\n", - " ('Stühlinger', [47.99888, 7.83774]),\n", - " ('Neuburg', [48.00021, 7.86084]),\n", - " ('Herdern', [48.00779, 7.86268]),\n", - " ('Brühl', [48.01684, 7.843]),\n", - " ]\n", - "}\n", - "\n", - "citizen_1 = city.Citizen(name='Nikola', age=35,\n", - " iri='https://example.org/entities#Nikola')\n", - "citizen_2 = city.Citizen(name='Lena', age=70,\n", - " iri='https://example.org/entities#Lena')\n", - "citizen_2[rdfs.label] = 'Helena'\n", - "citizen_3 = city.Citizen(name='Marco', age=36,\n", - " iri='https://example.org/entities#Marco')\n", - "citizen_3[rdfs.label] = 'Marco'\n", - "\n", - "freiburg[city.hasPart] |= neighborhoods\n", - "freiburg[city.hasInhabitant] += citizen_1, citizen_2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As shown in a [previous section](management.ipynb), the session object is iterable. This means that a simple method (althought very inefficient) to retrieve the individuals in the session is just iterating over the session object. It is also possible to know how many individuals are contained in a session using the Python built-in `len`." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ + "cells": [ { - "data": { - "text/plain": [ - "[,\n", - " ,\n", - " ,\n", - " ,\n", - " ,\n", - " ,\n", - " ,\n", - " ]" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Queries: using the session object\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fqueries.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(core_session) # iterates over the session, very slow with big data" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "9" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SimPhoNy's [session object](../../api_reference.md#simphony_osp.session.Session) implements methods that enable the retrieval of the ontology individuals it contains. The queries that can be run using such methods are extremely basic. If you need to run more advanced queries, head to the sections dealing with the [search module](search.ipynb) and [SPARQL](sparql.ipynb)." ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(core_session)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The session object also features a [get](../../api_reference.md#simphony_osp.session.Session.get) method that is similar to the [get method from ontology individuals](../assertional_knowledge.ipynb#Using-the-get,-iter,-connect,-and-disconnect-methods-(relationships-only)). It returns, in fact, a set-like object that manages the individuals contained in the session. Consequently, it is even possible to add and remove individuals from the session using in-place modifcations (although not very practical). The most common use case of the method is just retrieving ontology individuals." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "core_session.get()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Just like for the get method from ontology individuals, it is possible to filter the results to specific individuals (given their identifier is known or they are already available as objects) and classes, as well as any combination of both. " - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider a similar example from the city ontology again. Remember that by default, newly created individuals created are stored in the [Core Session](introduction.ipynb)." ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "core_session.get('https://example.org/entities#Lena')" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "{, } " + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city, rdfs\n", + "from simphony_osp.session import core_session\n", + "\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "\n", + "neighborhoods = {\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Altstadt', [47.99525, 7.84726]),\n", + " ('St\u00fchlinger', [47.99888, 7.83774]),\n", + " ('Neuburg', [48.00021, 7.86084]),\n", + " ('Herdern', [48.00779, 7.86268]),\n", + " ('Br\u00fchl', [48.01684, 7.843]),\n", + " ]\n", + "}\n", + "\n", + "citizen_1 = city.Citizen(name='Nikola', age=35,\n", + " iri='https://example.org/entities#Nikola')\n", + "citizen_2 = city.Citizen(name='Lena', age=70,\n", + " iri='https://example.org/entities#Lena')\n", + "citizen_2[rdfs.label] = 'Helena'\n", + "citizen_3 = city.Citizen(name='Marco', age=36,\n", + " iri='https://example.org/entities#Marco')\n", + "citizen_3[rdfs.label] = 'Marco'\n", + "\n", + "freiburg[city.hasPart] |= neighborhoods\n", + "freiburg[city.hasInhabitant] += citizen_1, citizen_2" ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "core_session.get(oclass=city.Citizen)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finally, if a [label](../terminological_knowledge.ipynb#Accessing-an-entity%E2%80%99s-label) has been given to the individual, then it is also possible to use it as retrieval method." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As shown in a [previous section](management.ipynb), the session object is iterable. This means that a simple method (althought very inefficient) to retrieve the individuals in the session is just iterating over the session object. It is also possible to know how many individuals are contained in a session using the Python built-in `len`." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ,\n", + " ]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(core_session) # iterates over the session, very slow with big data" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(core_session)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The session object also features a [get](../../api_reference.md#simphony_osp.session.Session.get) method that is similar to the [get method from ontology individuals](../assertional_knowledge.ipynb#Using-the-get,-iter,-connect,-and-disconnect-methods-(relationships-only)). It returns, in fact, a set-like object that manages the individuals contained in the session. Consequently, it is even possible to add and remove individuals from the session using in-place modifcations (although not very practical). The most common use case of the method is just retrieving ontology individuals." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "core_session.get()" + ] + }, { - "data": { - "text/plain": [ - "frozenset({})" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Just like for the get method from ontology individuals, it is possible to filter the results to specific individuals (given their identifier is known or they are already available as objects) and classes, as well as any combination of both. " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "core_session.get('https://example.org/entities#Lena')" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{, } " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "core_session.get(oclass=city.Citizen)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally, if a [label](../terminological_knowledge.ipynb#Accessing-an-entity%E2%80%99s-label) has been given to the individual, then it is also possible to use it as retrieval method." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "frozenset({})" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "core_session.from_label('Helena')" ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" } - ], - "source": [ - "core_session.from_label('Helena')" - ] - } - ], - "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.8.12" + ], + "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.8.12" + }, + "toc-showcode": false, + "toc-showtags": true }, - "toc-showcode": false, - "toc-showtags": true - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/sessions/search.ipynb b/docs/usage/sessions/search.ipynb index b1b71f8..fa7aabf 100644 --- a/docs/usage/sessions/search.ipynb +++ b/docs/usage/sessions/search.ipynb @@ -1,1328 +1,1328 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Queries: using the search module\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fsearch.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The search module enables more advanced queries of session's contents when compared to the [methods from the session object](queries.ipynb). It is intended to offer a pythonic approach to querying the session, but still, it has significant efficiency and expresivity limitations. An additional constraint is the topology of the graph that the relationships (and annotations) between the individuals form, as the functions from the module work **traversing the graph from a given initial individual**. Therefore, whenever you require more advanced or more performant queries, use [SPARQL](sparql.ipynb)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SimPhoNy's search module is located under `simphony_osp.tools.search` and can be imported as follows." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.tools import search" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The following functions are available:\n", - "\n", - "- [find](#find)\n", - "- [find_by_identifier](#find_by_identifier)\n", - "- [find_by_class](#find_by_class)\n", - "- [find_by_attribute](#find_by_attribute)\n", - "- [find_relationships](#find_relationships)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A `sparql` function is also provided by the module. However, it is not covered in this section, [but the next one](sparql.ipynb)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To see how these functions work, let's set-up an example with two cities, Freiburg and Paris." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city, owl, rdfs\n", - "from simphony_osp.session import core_session\n", - "\n", - "# Create a city called \"Freiburg\"\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "freiburg_neighborhoods = [\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Altstadt', [47.99525, 7.84726]),\n", - " ('Stühlinger', [47.99888, 7.83774]),\n", - " ('Neuburg', [48.00021, 7.86084]),\n", - " ('Herdern', [48.00779, 7.86268]),\n", - " ('Brühl', [48.01684, 7.843]),\n", - " ]\n", - "]\n", - "freiburg_citizens = {\n", - " city.Citizen(name='Nikola', age=35,\n", - " iri=\"http://example.org/entities#Nikola\"),\n", - " city.Citizen(name='Lena', age=70,\n", - " iri=\"http://example.org/entities#Lena\"),\n", - "}\n", - "freiburg[city.hasPart] |= freiburg_neighborhoods\n", - "freiburg[city.hasInhabitant] |= freiburg_citizens\n", - "\n", - "# Create a city called \"Paris\"\n", - "paris = city.City(name=\"Paris\", coordinates=[48.85333, 2.34885])\n", - "paris_neighborhoods = {\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Louvre', [48.86466, 2.33487]),\n", - " ('Bourse', [48.86864, 2.34146]),\n", - " ('Temple', [48.86101, 2.36037]),\n", - " ('Hôtel-de-Ville', [48.85447, 2.35902]),\n", - " ('Panthéon', [48.84466, 2.3471]),\n", - " ]\n", - "}\n", - "paris_citizens = {\n", - " city.Citizen(name='François', age=32)\n", - "}\n", - "paris[city.hasPart] |= paris_neighborhoods\n", - "paris[city.hasInhabitant] = paris_citizens" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Queries: using the search module\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fsearch.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The search module enables more advanced queries of session's contents when compared to the [methods from the session object](queries.ipynb). It is intended to offer a pythonic approach to querying the session, but still, it has significant efficiency and expresivity limitations. An additional constraint is the topology of the graph that the relationships (and annotations) between the individuals form, as the functions from the module work **traversing the graph from a given initial individual**. Therefore, whenever you require more advanced or more performant queries, use [SPARQL](sparql.ipynb)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SimPhoNy's search module is located under `simphony_osp.tools.search` and can be imported as follows." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.tools import search" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", - "\n", - "3385d37b...466\n", - "classes: Neighborhood (city)\n", - "name: Brühl\n", - "coordinates: [48.01684  7.843  ]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#a6167e38-851e-4fb8-b5a7-c4c0d929e7ef\n", - "\n", - "a6167e38...7ef\n", - "classes: Neighborhood (city)\n", - "name: Louvre\n", - "coordinates: [48.86466  2.33487]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", - "\n", - "db7348a9...315\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", - "\n", - "04ea43f7...d19\n", - "classes: Neighborhood (city)\n", - "name: Stühlinger\n", - "coordinates: [47.99888  7.83774]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", - "\n", - "1fada633...0a7\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.00779  7.86268]\n", - "name: Herdern\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", - "\n", - "67be995a...8c6\n", - "classes: Neighborhood (city)\n", - "coordinates: [47.99525  7.84726]\n", - "name: Altstadt\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", - "\n", - "02c61947...05e\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.00021  7.86084]\n", - "name: Neuburg\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3\n", - "\n", - "618889d2...2b3\n", - "classes: City (city)\n", - "name: Paris\n", - "coordinates: [48.85333  2.34885]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#a6167e38-851e-4fb8-b5a7-c4c0d929e7ef\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#9c142ddc-bdb1-487a-8837-d917cbd527c1\n", - "\n", - "9c142ddc...7c1\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.86101  2.36037]\n", - "name: Temple\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#9c142ddc-bdb1-487a-8837-d917cbd527c1\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#3b4fcff1-062c-4ba3-a2a8-f3b8e26f20cb\n", - "\n", - "3b4fcff1...0cb\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.85447  2.35902]\n", - "name: Hôtel-de-Ville\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#3b4fcff1-062c-4ba3-a2a8-f3b8e26f20cb\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#b1a0e59e-a2a6-430e-9e24-65fac7ee74b5\n", - "\n", - "b1a0e59e...4b5\n", - "classes: Citizen (city)\n", - "age: 32\n", - "name: François\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#b1a0e59e-a2a6-430e-9e24-65fac7ee74b5\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#6486c12a-33b8-4677-aef2-18d2553f9c99\n", - "\n", - "6486c12a...c99\n", - "classes: Neighborhood (city)\n", - "name: Bourse\n", - "coordinates: [48.86864  2.34146]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#6486c12a-33b8-4677-aef2-18d2553f9c99\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#df02e711-9de1-4981-b222-f7e50ed2f798\n", - "\n", - "df02e711...798\n", - "classes: Neighborhood (city)\n", - "name: Panthéon\n", - "coordinates: [48.84466  2.3471 ]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#df02e711-9de1-4981-b222-f7e50ed2f798\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The following functions are available:\n", + "\n", + "- [find](#find)\n", + "- [find_by_identifier](#find_by_identifier)\n", + "- [find_by_class](#find_by_class)\n", + "- [find_by_attribute](#find_by_attribute)\n", + "- [find_relationships](#find_relationships)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A `sparql` function is also provided by the module. However, it is not covered in this section, [but the next one](sparql.ipynb)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To see how these functions work, let's set-up an example with two cities, Freiburg and Paris." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city, owl, rdfs\n", + "from simphony_osp.session import core_session\n", + "\n", + "# Create a city called \"Freiburg\"\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "freiburg_neighborhoods = [\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Altstadt', [47.99525, 7.84726]),\n", + " ('St\u00fchlinger', [47.99888, 7.83774]),\n", + " ('Neuburg', [48.00021, 7.86084]),\n", + " ('Herdern', [48.00779, 7.86268]),\n", + " ('Br\u00fchl', [48.01684, 7.843]),\n", + " ]\n", + "]\n", + "freiburg_citizens = {\n", + " city.Citizen(name='Nikola', age=35,\n", + " iri=\"http://example.org/entities#Nikola\"),\n", + " city.Citizen(name='Lena', age=70,\n", + " iri=\"http://example.org/entities#Lena\"),\n", + "}\n", + "freiburg[city.hasPart] |= freiburg_neighborhoods\n", + "freiburg[city.hasInhabitant] |= freiburg_citizens\n", + "\n", + "# Create a city called \"Paris\"\n", + "paris = city.City(name=\"Paris\", coordinates=[48.85333, 2.34885])\n", + "paris_neighborhoods = {\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Louvre', [48.86466, 2.33487]),\n", + " ('Bourse', [48.86864, 2.34146]),\n", + " ('Temple', [48.86101, 2.36037]),\n", + " ('H\u00f4tel-de-Ville', [48.85447, 2.35902]),\n", + " ('Panth\u00e9on', [48.84466, 2.3471]),\n", + " ]\n", + "}\n", + "paris_citizens = {\n", + " city.Citizen(name='Fran\u00e7ois', age=32)\n", + "}\n", + "paris[city.hasPart] |= paris_neighborhoods\n", + "paris[city.hasInhabitant] = paris_citizens" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", + "\n", + "3385d37b...466\n", + "classes: Neighborhood (city)\n", + "name: Br\u00fchl\n", + "coordinates: [48.01684  7.843  ]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#a6167e38-851e-4fb8-b5a7-c4c0d929e7ef\n", + "\n", + "a6167e38...7ef\n", + "classes: Neighborhood (city)\n", + "name: Louvre\n", + "coordinates: [48.86466  2.33487]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", + "\n", + "db7348a9...315\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", + "\n", + "04ea43f7...d19\n", + "classes: Neighborhood (city)\n", + "name: St\u00fchlinger\n", + "coordinates: [47.99888  7.83774]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", + "\n", + "1fada633...0a7\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.00779  7.86268]\n", + "name: Herdern\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", + "\n", + "67be995a...8c6\n", + "classes: Neighborhood (city)\n", + "coordinates: [47.99525  7.84726]\n", + "name: Altstadt\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", + "\n", + "02c61947...05e\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.00021  7.86084]\n", + "name: Neuburg\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3\n", + "\n", + "618889d2...2b3\n", + "classes: City (city)\n", + "name: Paris\n", + "coordinates: [48.85333  2.34885]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#a6167e38-851e-4fb8-b5a7-c4c0d929e7ef\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#9c142ddc-bdb1-487a-8837-d917cbd527c1\n", + "\n", + "9c142ddc...7c1\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.86101  2.36037]\n", + "name: Temple\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#9c142ddc-bdb1-487a-8837-d917cbd527c1\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#3b4fcff1-062c-4ba3-a2a8-f3b8e26f20cb\n", + "\n", + "3b4fcff1...0cb\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.85447  2.35902]\n", + "name: H\u00f4tel-de-Ville\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#3b4fcff1-062c-4ba3-a2a8-f3b8e26f20cb\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#b1a0e59e-a2a6-430e-9e24-65fac7ee74b5\n", + "\n", + "b1a0e59e...4b5\n", + "classes: Citizen (city)\n", + "age: 32\n", + "name: Fran\u00e7ois\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#b1a0e59e-a2a6-430e-9e24-65fac7ee74b5\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#6486c12a-33b8-4677-aef2-18d2553f9c99\n", + "\n", + "6486c12a...c99\n", + "classes: Neighborhood (city)\n", + "name: Bourse\n", + "coordinates: [48.86864  2.34146]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#6486c12a-33b8-4677-aef2-18d2553f9c99\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#df02e711-9de1-4981-b222-f7e50ed2f798\n", + "\n", + "df02e711...798\n", + "classes: Neighborhood (city)\n", + "name: Panth\u00e9on\n", + "coordinates: [48.84466  2.3471 ]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#618889d2-ee0f-4b7e-8baa-c1ca930402b3->https___www.simphony-osp.eu_entity#df02e711-9de1-4981-b222-f7e50ed2f798\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.tools import semantic2dot # explained in a later section\n", + "\n", + "semantic2dot(freiburg, *freiburg_neighborhoods, *freiburg_citizens,\n", + " paris, *paris_neighborhoods, *paris_citizens)" ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.tools import semantic2dot # explained in a later section\n", - "\n", - "semantic2dot(freiburg, *freiburg_neighborhoods, *freiburg_citizens,\n", - " paris, *paris_neighborhoods, *paris_citizens)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The most important detail to keep in mind is that the functions above do not act on a session object, but on an ontology individual object that has to be provided beforehand. They perform the search by **traversing the relationships and annotations in the graph starting from the given individual**.\n", - " \n", - "This is the precisely the reason why a directed graph with two [weakly connected components](https://en.wikipedia.org/wiki/Connectivity_(graph_theory)) is provided as example: it illustrates that it is impossible to find individuals from one of the components if the search function is called on an individual belonging to another component. Head to the first subsection, dealing with the function [find](#find), to see this behavior in action." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## `find`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The function `find` traverses the graph starting from a given _root_ individual, following only relationships that are a subclass of the _given relationships_, and annotations that are a subclass of the _given annotations_. Along the path, it verifies a given _criterion_ on each ontology individual it finds, and then returns the matching individuals." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To clarify how it works, several calls of increasing difficulty to this function, applied to the graph constructed at the top of this page, are shown as examples." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The simplest call just needs the positional argument `root`. As no relationships nor annotations are provided, all relationships and annotations are followed. Similarly, as no criterion is provided, it is always assumed to be satisfied. " - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The most important detail to keep in mind is that the functions above do not act on a session object, but on an ontology individual object that has to be provided beforehand. They perform the search by **traversing the relationships and annotations in the graph starting from the given individual**.\n", + " \n", + "This is the precisely the reason why a directed graph with two [weakly connected components](https://en.wikipedia.org/wiki/Connectivity_(graph_theory)) is provided as example: it illustrates that it is impossible to find individuals from one of the components if the search function is called on an individual belonging to another component. Head to the first subsection, dealing with the function [find](#find), to see this behavior in action." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## `find`" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", - "\n", - "3385d37b...466\n", - "classes: Neighborhood (city)\n", - "name: Brühl\n", - "coordinates: [48.01684  7.843  ]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", - "\n", - "db7348a9...315\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", - "\n", - "04ea43f7...d19\n", - "classes: Neighborhood (city)\n", - "name: Stühlinger\n", - "coordinates: [47.99888  7.83774]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", - "\n", - "1fada633...0a7\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.00779  7.86268]\n", - "name: Herdern\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", - "\n", - "67be995a...8c6\n", - "classes: Neighborhood (city)\n", - "coordinates: [47.99525  7.84726]\n", - "name: Altstadt\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", - "\n", - "02c61947...05e\n", - "classes: Neighborhood (city)\n", - "coordinates: [48.00021  7.86084]\n", - "name: Neuburg\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", - "\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The function `find` traverses the graph starting from a given _root_ individual, following only relationships that are a subclass of the _given relationships_, and annotations that are a subclass of the _given annotations_. Along the path, it verifies a given _criterion_ on each ontology individual it finds, and then returns the matching individuals." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To clarify how it works, several calls of increasing difficulty to this function, applied to the graph constructed at the top of this page, are shown as examples." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The simplest call just needs the positional argument `root`. As no relationships nor annotations are provided, all relationships and annotations are followed. Similarly, as no criterion is provided, it is always assumed to be satisfied. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", + "\n", + "3385d37b...466\n", + "classes: Neighborhood (city)\n", + "name: Br\u00fchl\n", + "coordinates: [48.01684  7.843  ]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", + "\n", + "db7348a9...315\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#3385d37b-8bb3-48bf-94ea-fcc0397f6466\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", + "\n", + "04ea43f7...d19\n", + "classes: Neighborhood (city)\n", + "name: St\u00fchlinger\n", + "coordinates: [47.99888  7.83774]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#04ea43f7-c381-400b-97f2-8d5b4fb13d19\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", + "\n", + "1fada633...0a7\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.00779  7.86268]\n", + "name: Herdern\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#1fada633-0fd2-47c0-b800-2c27a2d450a7\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", + "\n", + "67be995a...8c6\n", + "classes: Neighborhood (city)\n", + "coordinates: [47.99525  7.84726]\n", + "name: Altstadt\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#67be995a-a882-493b-8f70-ed17067cb8c6\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", + "\n", + "02c61947...05e\n", + "classes: Neighborhood (city)\n", + "coordinates: [48.00021  7.86084]\n", + "name: Neuburg\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->https___www.simphony-osp.eu_entity#02c61947-7684-43a7-9882-086295a5305e\n", + "\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(\n", + " search.find(freiburg)\n", + ")\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(\n", - " search.find(freiburg)\n", - ")\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As it can be seen above, when using `freiburg` as the root object, the result is the subgraph of all ontology individuals reachable from `freiburg`. None of the citizens or neighborhoods of `paris` are returned, as they cannot be reached from the `freiburg` individual." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To increase the complexity of the query, the relationships to be followed can be limited to the subclasses of various selected relationships using the `rel` keyword arugment. For example, let's restrict the search to inhabitants and workers of Freiburg (as well as Freiburg itself)." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As it can be seen above, when using `freiburg` as the root object, the result is the subgraph of all ontology individuals reachable from `freiburg`. None of the citizens or neighborhoods of `paris` are returned, as they cannot be reached from the `freiburg` individual." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", - "\n", - "db7348a9...315\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To increase the complexity of the query, the relationships to be followed can be limited to the subclasses of various selected relationships using the `rel` keyword arugment. For example, let's restrict the search to inhabitants and workers of Freiburg (as well as Freiburg itself)." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", + "\n", + "db7348a9...315\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Nikola\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315->http___example.org_entities#Lena\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(\n", + " search.find(\n", + " freiburg,\n", + " rel=(city.hasInhabitant, city.hasWorker) # if only one relationship has to be considered, just pass it directly (i.e. `rel=city.hasInhabitant`)\n", + " ) \n", + ")\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(\n", - " search.find(\n", - " freiburg,\n", - " rel=(city.hasInhabitant, city.hasWorker) # if only one relationship has to be considered, just pass it directly (i.e. `rel=city.hasInhabitant`)\n", - " ) \n", - ")\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "There is a similar keyword argument `annotation` that can be used to constrain the ontology annotations to follow. Just like for the `rel` argument, it can take as values either a single annotation or several ones. However, in addition, it also accepts boolean values. Setting it to `True` means following all annotations (the default value), while setting it to `False` means following no annotations at all.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The next complexity step is passing a function as search criterion. For example, one may want to restrict the search to persons that are more than 40 years old." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "There is a similar keyword argument `annotation` that can be used to constrain the ontology annotations to follow. Just like for the `rel` argument, it can take as values either a single annotation or several ones. However, in addition, it also accepts boolean values. Setting it to `True` means following all annotations (the default value), while setting it to `False` means following no annotations at all.\n", + "\n", + "
" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The next complexity step is passing a function as search criterion. For example, one may want to restrict the search to persons that are more than 40 years old." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(\n", + " search.find(\n", + " freiburg,\n", + " criterion=lambda individual: individual.is_a(city.Person) and individual.age > 40,\n", + " rel=(city.hasInhabitant, city.hasWorker)\n", + " ) \n", + ")\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(\n", - " search.find(\n", - " freiburg,\n", - " criterion=lambda individual: individual.is_a(city.Person) and individual.age > 40,\n", - " rel=(city.hasInhabitant, city.hasWorker)\n", - " ) \n", - ")\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that `freiburg` itself does not satisfy the given criterion, and thus it is excluded from the results." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That is all! You have mastered the `find` function, although there are still two little details that allow to control the algorithm and the output." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Relaxing the criterion to just requiring the results to be persons and re-running the search with the keyword argument `find_all=False` causes the search to return only the first individual it finds." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that `freiburg` itself does not satisfy the given criterion, and thus it is excluded from the results." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "That is all! You have mastered the `find` function, although there are still two little details that allow to control the algorithm and the output." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Relaxing the criterion to just requiring the results to be persons and re-running the search with the keyword argument `find_all=False` causes the search to return only the first individual it finds." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = search.find(\n", + " freiburg,\n", + " criterion=lambda individual: individual.is_a(city.Person),\n", + " rel=(city.hasInhabitant, city.hasWorker),\n", + " find_all=False,\n", + ") \n", + "\n", + "semantic2dot(found)" ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = search.find(\n", - " freiburg,\n", - " criterion=lambda individual: individual.is_a(city.Person),\n", - " rel=(city.hasInhabitant, city.hasWorker),\n", - " find_all=False,\n", - ") \n", - "\n", - "semantic2dot(found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Lastly, the maximum depth of the search can be adjusted using the `max_depth` parameter. Try setting it to `0`, it should yield no results!" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Lastly, the maximum depth of the search can be adjusted using the `max_depth` parameter. Try setting it to `0`, it should yield no results!" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(\n", + " search.find(\n", + " freiburg,\n", + " criterion=lambda individual: individual.is_a(city.Person),\n", + " rel=(city.hasInhabitant, city.hasWorker),\n", + " max_depth=0,\n", + " ) \n", + ")\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(\n", - " search.find(\n", - " freiburg,\n", - " criterion=lambda individual: individual.is_a(city.Person),\n", - " rel=(city.hasInhabitant, city.hasWorker),\n", - " max_depth=0,\n", - " ) \n", - ")\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## `find_by_identifier`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This function is constructed as a call to [find](#find), but with the criterion fixed to matching the given identifier. \n", - "\n", - "The positional arguments `root` and keyword arguments `rel` and `annotation` behave exactly like in [find](#find). An additional positional argument, `identifier` is required. The keyword arguments `criterion`, `find_all` and `max_depth` are not available, as they are fixed to: matching the given identifier, `False` (as identifiers are unique) and unlimited. \n", - "\n", - "Therefore, this function yields either `None` or a single ontology individual whose identifier matches the given one." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## `find_by_identifier`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This function is constructed as a call to [find](#find), but with the criterion fixed to matching the given identifier. \n", + "\n", + "The positional arguments `root` and keyword arguments `rel` and `annotation` behave exactly like in [find](#find). An additional positional argument, `identifier` is required. The keyword arguments `criterion`, `find_all` and `max_depth` are not available, as they are fixed to: matching the given identifier, `False` (as identifiers are unique) and unlimited. \n", + "\n", + "Therefore, this function yields either `None` or a single ontology individual whose identifier matches the given one." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = search.find_by_identifier(\n", + " freiburg,\n", + " \"http://example.org/entities#Lena\",\n", + " rel=owl.topObjectProperty,\n", + ") \n", + "\n", + "semantic2dot(found)" ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = search.find_by_identifier(\n", - " freiburg,\n", - " \"http://example.org/entities#Lena\",\n", - " rel=owl.topObjectProperty,\n", - ") \n", - "\n", - "semantic2dot(found)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## `find_by_class`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This function is also constructed as a call to [find](#find), but with the criterion fixed to the individual belonging to a specific ontology class. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Just like before, the positional arguments `root` and keyword arguments `rel` and `annotation` behave exactly like in [find](#find). An additional positional argument, `oclass` is required. The keyword arguments `criterion`, `find_all` and `max_depth` are not available, as they are fixed to: the individual belonging to the given class, `True` (as identifiers are unique) and unlimited. " - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Lena\n", - "\n", - "http://example.org/entities#Lena\n", - "classes: Citizen (city)\n", - "name: Lena\n", - "age: 70\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "## `find_by_class`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This function is also constructed as a call to [find](#find), but with the criterion fixed to the individual belonging to a specific ontology class. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Just like before, the positional arguments `root` and keyword arguments `rel` and `annotation` behave exactly like in [find](#find). An additional positional argument, `oclass` is required. The keyword arguments `criterion`, `find_all` and `max_depth` are not available, as they are fixed to: the individual belonging to the given class, `True` (as identifiers are unique) and unlimited. " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Lena\n", + "\n", + "http://example.org/entities#Lena\n", + "classes: Citizen (city)\n", + "name: Lena\n", + "age: 70\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(search.find_by_class(\n", + " freiburg,\n", + " city.Person,\n", + " rel=owl.topObjectProperty,\n", + "))\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(search.find_by_class(\n", - " freiburg,\n", - " city.Person,\n", - " rel=owl.topObjectProperty,\n", - "))\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## `find_by_attribute`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finds individuals that have a matching attribute value. `find_all` is set to `True` and `max_depth` to unlimited.\n", - "\n", - "For example, looking for individuals that are 35 years old yields Nikola." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "http___example.org_entities#Nikola\n", - "\n", - "http://example.org/entities#Nikola\n", - "classes: Citizen (city)\n", - "name: Nikola\n", - "age: 35\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "## `find_by_attribute`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finds individuals that have a matching attribute value. `find_all` is set to `True` and `max_depth` to unlimited.\n", + "\n", + "For example, looking for individuals that are 35 years old yields Nikola." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "http___example.org_entities#Nikola\n", + "\n", + "http://example.org/entities#Nikola\n", + "classes: Citizen (city)\n", + "name: Nikola\n", + "age: 35\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(search.find_by_attribute(\n", + " freiburg,\n", + " city.age,\n", + " 35,\n", + " rel=owl.topObjectProperty,\n", + "))\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(search.find_by_attribute(\n", - " freiburg,\n", - " city.age,\n", - " 35,\n", - " rel=owl.topObjectProperty,\n", - "))\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "## `find_relationships`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In this case, individuals that are attached to any other individual through the given relationship (the _source_ individuals of the relationship) are returned. `find_all` is set to `True` and `max_depth` to unlimited." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", - "\n", - "db7348a9...315\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "## `find_relationships`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In this case, individuals that are attached to any other individual through the given relationship (the _source_ individuals of the relationship) are returned. `find_all` is set to `True` and `max_depth` to unlimited." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", + "\n", + "db7348a9...315\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(search.find_relationships(\n", + " freiburg,\n", + " city.hasInhabitant, # the relationship used as criterion\n", + " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", + "))\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(search.find_relationships(\n", - " freiburg,\n", - " city.hasInhabitant, # the relationship used as criterion\n", - " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", - "))\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that however, by default sub-relationships of the given relationship are not considered. This can be demonstrated using `owl.topObjectProperty` as relationship, as no results are yielded when doing so" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that however, by default sub-relationships of the given relationship are not considered. This can be demonstrated using `owl.topObjectProperty` as relationship, as no results are yielded when doing so" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(search.find_relationships(\n", + " freiburg,\n", + " owl.topObjectProperty, # the relationship used as criterion\n", + " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", + "))\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "found = list(search.find_relationships(\n", - " freiburg,\n", - " owl.topObjectProperty, # the relationship used as criterion\n", - " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", - "))\n", - "\n", - "semantic2dot(*found)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "unless the keyword argument `find_sub_relationships` is set to `True`." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", - "\n", - "db7348a9...315\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x55a55d85c140\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "unless the keyword argument `find_sub_relationships` is set to `True`." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#db7348a9-ae67-4ca2-83a8-7ee647d3a315\n", + "\n", + "db7348a9...315\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x55a55d85c140\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "found = list(search.find_relationships(\n", + " freiburg,\n", + " owl.topObjectProperty, # the relationship used as criterion\n", + " find_sub_relationships=True,\n", + " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", + "))\n", + "\n", + "semantic2dot(*found)" ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" } - ], - "source": [ - "found = list(search.find_relationships(\n", - " freiburg,\n", - " owl.topObjectProperty, # the relationship used as criterion\n", - " find_sub_relationships=True,\n", - " rel=owl.topObjectProperty, # the usual `rel` argument, only this and sub-relationships will be traversed during the search\n", - "))\n", - "\n", - "semantic2dot(*found)" - ] - } - ], - "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.8.12" + ], + "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.8.12" + }, + "toc-showcode": false, + "toc-showtags": true }, - "toc-showcode": false, - "toc-showtags": true - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/sessions/sparql.ipynb b/docs/usage/sessions/sparql.ipynb index cb41683..a096ca5 100644 --- a/docs/usage/sessions/sparql.ipynb +++ b/docs/usage/sessions/sparql.ipynb @@ -1,277 +1,277 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Queries: using SPARQL \n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fsparql.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SimPhoNy sessions store the ontology individual information using the [RDF standard](https://www.w3.org/TR/rdf-concepts/) in an [RDF graph object](https://rdflib.readthedocs.io/en/stable/intro_to_graphs.html) from the [RDFLib](https://github.com/RDFLib/rdflib) library. This means that they are naturally compatible with the [SPARQL 1.1 Query Language](https://www.w3.org/TR/sparql11-query/) for RDF graphs." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SPARQL queries can be invoked both from a function in the search module or from the [sparql method of the session object](../../api_reference.md#simphony_osp.session.Session.sparql). Both are equivalent, except for the fact that a target session can be passed to the function from the search module, whereas for the sparql method of the session object, the target session is fixed." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.tools.search import sparql" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Freiburg and Paris will serve as an example again to showcase this functionality." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city, owl, rdfs\n", - "from simphony_osp.session import core_session\n", - "\n", - "# Create a city called \"Freiburg\"\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "freiburg_neighborhoods = [\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Altstadt', [47.99525, 7.84726]),\n", - " ('Stühlinger', [47.99888, 7.83774]),\n", - " ('Neuburg', [48.00021, 7.86084]),\n", - " ('Herdern', [48.00779, 7.86268]),\n", - " ('Brühl', [48.01684, 7.843]),\n", - " ]\n", - "]\n", - "freiburg_citizens = {\n", - " city.Citizen(name='Nikola', age=35,\n", - " iri=\"http://example.org/entities#Nikola\"),\n", - " city.Citizen(name='Lena', age=70,\n", - " iri=\"http://example.org/entities#Lena\"),\n", - "}\n", - "freiburg[city.hasPart] |= freiburg_neighborhoods\n", - "freiburg[city.hasInhabitant] |= freiburg_citizens\n", - "\n", - "# Create a city called \"Paris\"\n", - "paris = city.City(name=\"Paris\", coordinates=[48.85333, 2.34885])\n", - "paris_neighborhoods = {\n", - " city.Neighborhood(name=name, coordinates=coordinates)\n", - " for name, coordinates in [\n", - " ('Louvre', [48.86466, 2.33487]),\n", - " ('Bourse', [48.86864, 2.34146]),\n", - " ('Temple', [48.86101, 2.36037]),\n", - " ('Hôtel-de-Ville', [48.85447, 2.35902]),\n", - " ('Panthéon', [48.84466, 2.3471]),\n", - " ]\n", - "}\n", - "paris_citizens = {\n", - " city.Citizen(name='François', age=32)\n", - "}\n", - "paris[city.hasPart] |= paris_neighborhoods\n", - "paris[city.hasInhabitant] = paris_citizens" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Start by getting all objects connected to Freiburg. This will return a query result object. Such object inherits from [RDFLib's SPARQLResult object](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.sparql.html#rdflib.plugins.sparql.processor.SPARQLResult). The example below illustrates the its basic functionality. Check RDFLib's documentation to learn all the capabilities of the [SPARQLResult object](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.sparql.html#rdflib.plugins.sparql.processor.SPARQLResult)." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ + "cells": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "10 True\n", - "(rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector')),)\n", - "rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))\n", - "rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))\n", - "None\n", - "{'o': rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))}\n" - ] - } - ], - "source": [ - "result = sparql( # no session specified, uses the default session (Core Session in this example)\n", - " f\"\"\"SELECT ?o WHERE {{\n", - " <{freiburg.identifier}> ?p ?o .\n", - " }}\n", - " \"\"\"\n", - ")\n", - "\n", - "print(\n", - " len(result), # number of rows in the result\n", - " bool(result) # True when at least one match has been found\n", - ")\n", - "\n", - "for row in result: # iterating the result yields ResultRow objects\n", - " print(row.__repr__())\n", - " # ResultRows inherint from tuples\n", - " # the order of the variables passed to the query is respected\n", - " \n", - " print(row[0].__repr__()) # a specific variable can be accessed using either its position,\n", - " print(row['o'].__repr__()) # or name\n", - " \n", - " print(row.get('unknown_variable', None)) # a dict-like `get` method is available\n", - " \n", - " print(row.asdict()) # transforms the row into a dictionary\n", - " \n", - " break # only one result is shown in order not to flood this page" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All results from the query are by default RDFLib objects (e.g. `URIRef`, `Literal`, ...). However, query results from SimPhoNy feature the capability to easily convert the results to other data types using keyword arguments. \n", - "\n", - "For example, to query all the citizens in the session, as well as their name name and age; and obtain the results as ontology individual objects, Python strings and Python integers; use the following." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Queries: using SPARQL \n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fsessions%2Fsparql.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "(, 'Nikola', 35)\n", - "(, 'Lena', 70)\n", - "(, 'François', 32)\n" - ] - } - ], - "source": [ - "from simphony_osp.ontology import OntologyIndividual\n", - "\n", - "result = sparql(\n", - " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", - " ?person rdf:type <{city.Citizen.identifier}> .\n", - " ?person <{city['name'].identifier}> ?name .\n", - " ?person <{city.age.identifier}> ?age .\n", - " }}\n", - " \"\"\"\n", - ")\n", - "\n", - "for row in result(person=OntologyIndividual, name=str, age=int):\n", - " print(row)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "By default, the ontologies installed with [pico](../ontologies/pico.md) are not included in the search. If you wish to make use of the terminological knowledge, pass the keyword argument `ontology=True`. The example below looks for persons instead of citizens, therefore including the terminological knowledge is necessary to obtain the desired results." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SimPhoNy sessions store the ontology individual information using the [RDF standard](https://www.w3.org/TR/rdf-concepts/) in an [RDF graph object](https://rdflib.readthedocs.io/en/stable/intro_to_graphs.html) from the [RDFLib](https://github.com/RDFLib/rdflib) library. This means that they are naturally compatible with the [SPARQL 1.1 Query Language](https://www.w3.org/TR/sparql11-query/) for RDF graphs." + ] + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "Query without ontology: 0 results\n", - "Query with ontology: 3 results\n", - "(, 'Nikola', 35)\n", - "(, 'Lena', 70)\n", - "(, 'François', 32)\n" - ] + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SPARQL queries can be invoked both from a function in the search module or from the [sparql method of the session object](../../api_reference.md#simphony_osp.session.Session.sparql). Both are equivalent, except for the fact that a target session can be passed to the function from the search module, whereas for the sparql method of the session object, the target session is fixed." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.tools.search import sparql" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Freiburg and Paris will serve as an example again to showcase this functionality." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city, owl, rdfs\n", + "from simphony_osp.session import core_session\n", + "\n", + "# Create a city called \"Freiburg\"\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "freiburg_neighborhoods = [\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Altstadt', [47.99525, 7.84726]),\n", + " ('St\u00fchlinger', [47.99888, 7.83774]),\n", + " ('Neuburg', [48.00021, 7.86084]),\n", + " ('Herdern', [48.00779, 7.86268]),\n", + " ('Br\u00fchl', [48.01684, 7.843]),\n", + " ]\n", + "]\n", + "freiburg_citizens = {\n", + " city.Citizen(name='Nikola', age=35,\n", + " iri=\"http://example.org/entities#Nikola\"),\n", + " city.Citizen(name='Lena', age=70,\n", + " iri=\"http://example.org/entities#Lena\"),\n", + "}\n", + "freiburg[city.hasPart] |= freiburg_neighborhoods\n", + "freiburg[city.hasInhabitant] |= freiburg_citizens\n", + "\n", + "# Create a city called \"Paris\"\n", + "paris = city.City(name=\"Paris\", coordinates=[48.85333, 2.34885])\n", + "paris_neighborhoods = {\n", + " city.Neighborhood(name=name, coordinates=coordinates)\n", + " for name, coordinates in [\n", + " ('Louvre', [48.86466, 2.33487]),\n", + " ('Bourse', [48.86864, 2.34146]),\n", + " ('Temple', [48.86101, 2.36037]),\n", + " ('H\u00f4tel-de-Ville', [48.85447, 2.35902]),\n", + " ('Panth\u00e9on', [48.84466, 2.3471]),\n", + " ]\n", + "}\n", + "paris_citizens = {\n", + " city.Citizen(name='Fran\u00e7ois', age=32)\n", + "}\n", + "paris[city.hasPart] |= paris_neighborhoods\n", + "paris[city.hasInhabitant] = paris_citizens" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Start by getting all objects connected to Freiburg. This will return a query result object. Such object inherits from [RDFLib's SPARQLResult object](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.sparql.html#rdflib.plugins.sparql.processor.SPARQLResult). The example below illustrates the its basic functionality. Check RDFLib's documentation to learn all the capabilities of the [SPARQLResult object](https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.sparql.html#rdflib.plugins.sparql.processor.SPARQLResult)." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 True\n", + "(rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector')),)\n", + "rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))\n", + "rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))\n", + "None\n", + "{'o': rdflib.term.Literal('13YFp0RR93AD@t&xBo{#)k4YS)LtJz', datatype=rdflib.term.URIRef('https://www.simphony-osp.eu/types#Vector'))}\n" + ] + } + ], + "source": [ + "result = sparql( # no session specified, uses the default session (Core Session in this example)\n", + " f\"\"\"SELECT ?o WHERE {{\n", + " <{freiburg.identifier}> ?p ?o .\n", + " }}\n", + " \"\"\"\n", + ")\n", + "\n", + "print(\n", + " len(result), # number of rows in the result\n", + " bool(result) # True when at least one match has been found\n", + ")\n", + "\n", + "for row in result: # iterating the result yields ResultRow objects\n", + " print(row.__repr__())\n", + " # ResultRows inherint from tuples\n", + " # the order of the variables passed to the query is respected\n", + " \n", + " print(row[0].__repr__()) # a specific variable can be accessed using either its position,\n", + " print(row['o'].__repr__()) # or name\n", + " \n", + " print(row.get('unknown_variable', None)) # a dict-like `get` method is available\n", + " \n", + " print(row.asdict()) # transforms the row into a dictionary\n", + " \n", + " break # only one result is shown in order not to flood this page" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All results from the query are by default RDFLib objects (e.g. `URIRef`, `Literal`, ...). However, query results from SimPhoNy feature the capability to easily convert the results to other data types using keyword arguments. \n", + "\n", + "For example, to query all the citizens in the session, as well as their name name and age; and obtain the results as ontology individual objects, Python strings and Python integers; use the following." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(, 'Nikola', 35)\n", + "(, 'Lena', 70)\n", + "(, 'Fran\u00e7ois', 32)\n" + ] + } + ], + "source": [ + "from simphony_osp.ontology import OntologyIndividual\n", + "\n", + "result = sparql(\n", + " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", + " ?person rdf:type <{city.Citizen.identifier}> .\n", + " ?person <{city['name'].identifier}> ?name .\n", + " ?person <{city.age.identifier}> ?age .\n", + " }}\n", + " \"\"\"\n", + ")\n", + "\n", + "for row in result(person=OntologyIndividual, name=str, age=int):\n", + " print(row)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "By default, the ontologies installed with [pico](../ontologies/pico.md) are not included in the search. If you wish to make use of the terminological knowledge, pass the keyword argument `ontology=True`. The example below looks for persons instead of citizens, therefore including the terminological knowledge is necessary to obtain the desired results." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Query without ontology: 0 results\n", + "Query with ontology: 3 results\n", + "(, 'Nikola', 35)\n", + "(, 'Lena', 70)\n", + "(, 'Fran\u00e7ois', 32)\n" + ] + } + ], + "source": [ + "result = sparql(\n", + " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", + " ?person rdf:type/rdfs:subClassOf <{city.Person.identifier}> .\n", + " ?person <{city['name'].identifier}> ?name .\n", + " ?person <{city.age.identifier}> ?age .\n", + " }}\n", + " \"\"\",\n", + " ontology=False\n", + ")\n", + "\n", + "print(\"Query without ontology:\", len(result), \"results\")\n", + "\n", + "result = sparql(\n", + " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", + " ?person rdf:type <{city.Citizen.identifier}> .\n", + " ?person <{city['name'].identifier}> ?name .\n", + " ?person <{city.age.identifier}> ?age .\n", + " }}\n", + " \"\"\",\n", + " ontology=True\n", + ")\n", + "\n", + "print(\"Query with ontology:\", len(result), \"results\")\n", + "\n", + "for row in result(person=OntologyIndividual, name=str, age=int):\n", + " print(row)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "When using `ontology=True`, the current version of SimPhoNy assumes that there is virtually no latency between your computer and the session that is being queried. If `ontology=True` is used, for example, with a session connected to a triplestore located on a remote server, the query will be extremely slow.\n", + " \n", + "
" + ] } - ], - "source": [ - "result = sparql(\n", - " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", - " ?person rdf:type/rdfs:subClassOf <{city.Person.identifier}> .\n", - " ?person <{city['name'].identifier}> ?name .\n", - " ?person <{city.age.identifier}> ?age .\n", - " }}\n", - " \"\"\",\n", - " ontology=False\n", - ")\n", - "\n", - "print(\"Query without ontology:\", len(result), \"results\")\n", - "\n", - "result = sparql(\n", - " f\"\"\"SELECT ?person ?name ?age WHERE {{\n", - " ?person rdf:type <{city.Citizen.identifier}> .\n", - " ?person <{city['name'].identifier}> ?name .\n", - " ?person <{city.age.identifier}> ?age .\n", - " }}\n", - " \"\"\",\n", - " ontology=True\n", - ")\n", - "\n", - "print(\"Query with ontology:\", len(result), \"results\")\n", - "\n", - "for row in result(person=OntologyIndividual, name=str, age=int):\n", - " print(row)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "When using `ontology=True`, the current version of SimPhoNy assumes that there is virtually no latency between your computer and the session that is being queried. If `ontology=True` is used, for example, with a session connected to a triplestore located on a remote server, the query will be extremely slow.\n", - " \n", - "
" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "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.10.7" + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.10.7" + }, + "toc-showcode": false, + "toc-showtags": true }, - "toc-showcode": false, - "toc-showtags": true - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/terminological_knowledge.ipynb b/docs/usage/terminological_knowledge.ipynb index e92af53..9f10c38 100644 --- a/docs/usage/terminological_knowledge.ipynb +++ b/docs/usage/terminological_knowledge.ipynb @@ -1,918 +1,918 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Terminological knowledge\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fterminological_knowledge.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In an ontological framework, ontology entities are used as a knowledge representation form. Those can be further categorized in two groups: ontology individuals ([assertional knowledge](https://en.wikipedia.org/wiki/Abox)), and ontology classes, relationships, attributes and annotations ([terminological knowledge](https://en.wikipedia.org/wiki/Tbox)). This page **focuses on** how to access and navigate the **terminological knowledge** of an ontology using SimPhoNy." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Such functionality is presented in the form of a tutorial, in which both the `city` namespace from SimPhoNy's example [City ontology](ontologies/ontologies_included.md#the-city-ontology), and the `emmo` namespace from the [Elementary Multiperspective Material Ontology (EMMO)](ontologies/ontologies_included.md#elementary-multiperspective-material-ontology-emmo) are used as examples.\n", - "\n", - "If you want to follow the tutorial along, please [make sure that such ontologies are installed](ontologies/pico.md#pico-list). If you have not installed them yet, you can do so running the commands below." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# Install the ontologies\n", - "!pico install city emmo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "SimPhoNy does **not** feature the ability to edit the classes, relationships, attributes and\n", - "annotations of ontologies, only to read them. This is the reason why ontologies need to be [installed using pico](ontologies/pico.md#installing-ontologies-pico).\n", - "
\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## [Namespace objects](../api_reference.md#simphony_osp.ontology.OntologyNamespace): accessing entities\n", - "\n", - "To access ontology entities, it is first needed to know the aliases of the installed ontology namespaces. The [pico ontology management tool](ontologies/pico.md#installing-ontologies-pico) to can list the installed namespaces. Note that each namespace is provided by a specific [ontology package](ontologies/packages.md#ontology-packages).\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Packages:\n", - "\t- simlammps\n", - "\t- city\n", - "\t- emmo\n", - "Namespaces:\n", - "\t- simphony\n", - "\t- owl\n", - "\t- rdfs\n", - "\t- simlammps\n", - "\t- city\n", - "\t- emmo\n" - ] - } - ], - "source": [ - "!pico list" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Once the names of the namespaces to be used are known, they can be imported in Python. In this tutorial, the namespaces `city` and `emmo` are imported. Through those imported namespace Python objects, the entities within the namespaces can be accessed:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city, emmo" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The namespace objects are [Python iterables](https://docs.python.org/3/glossary.html). This implies that it is possible to get a list of all the entities available within a namespace running `list(namespace)`. \n", - "\n", - "To get the IRI of a namespace object, use the `iri` property. This will yield an [URIRef object](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#uriref) from the [RDFLib](https://github.com/RDFLib/rdflib) library, that SimPhoNy makes use of." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.URIRef('https://www.simphony-project.eu/city#')" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.iri" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are several ways to reference an ontology entity to be retrieved, which are summarized in the following list.\n", - "\n", - "- By **suffix**. For example, for the namespace `city`, whose [IRI](https://fusion.cs.uni-jena.de/fusion/blog/2016/11/18/iri-uri-url-urn-and-their-differences/) is `http://www.simphony-osp.eu/city#`, requesting the suffix `Citizen` would return the ontology entity with IRI `http://www.simphony-osp.eu/city#Citizen`.\n", - "\n", - "- By **label**. Retrieves the entity by the [_main label_](#Accessing-an-entity’s-label) that has been assigned to it in the ontology using either the `rdfs:label` or `skos:prefLabel` predicates.\n", - "\n", - "[//]: # \"TODO: It is possible to include more properties or change the order of the properties, link to the sessions page. Link also to give more information about the ordering of the properties and which labels are discarded.\"\n", - "\n", - "- By **IRI**. The [IRI](https://fusion.cs.uni-jena.de/fusion/blog/2016/11/18/iri-uri-url-urn-and-their-differences/) of an ontology entity is provided in order to retrieve it." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Although it is not the only possible approach, the **most convenient way** to access an ontology entity is to use the **dot notation** on the imported namespace objects (e.g. `city.Citizen`) to reference it either by suffix or label." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The dot notation supports IPython autocompletion. For example, when working on a Jupyter notebook, once the namespace has been imported, it is possible to get suggestions for the entity names by writing `namespace.` and pressing TAB.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Accessing an ontology entity by suffix or label**\n", - "\n", - "Let's retrieve the _Living Being_ class from the `city` namespace, whose IRI is `https://www.simphony-project.eu/city#LivingBeing`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To retrieve the class using its suffix or its label, just use the dot notation" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.LivingBeing # by suffix" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "However, sometimes the suffix or label contains characters that Python does not accept as attribute names, such as dashes or spaces. In such cases, it is not possible to use the dot notation. An alternative way to retrieve entitites using the Python's index operator `[]` exists" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city['Living Being'] # by label (contains a space)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The index notation also supports IPython autocompletion.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Note that both operations are case-sensitive, and therefore the following would produce an error." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "# city.Livingbeing # -> Fails." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In addition, the namespace object has some advanced methods, [from_suffix](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_suffix), [from_label](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_label) and [get](../api_reference.md#simphony_osp.ontology.OntologyNamespace.get) that can also be used to retrieve entities by suffix or label." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Accessing an ontology entity by IRI**\n", - "\n", - "Let's now retrieve the Integer class from the `emmo` namespace using its IRI `http://emmo.info/emmo#EMMO_f8bd64d5_5d3e_4ad4_a46e_c30714fecb7f`." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To do so, use the method [from_iri](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_iri) of the corresponding namespace object" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "emmo.from_iri('http://emmo.info/emmo#EMMO_f8bd64d5_5d3e_4ad4_a46e_c30714fecb7f')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## [Ontology entity objects](../api_reference.md#simphony_osp.ontology.OntologyEntity)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Accessing an entity's label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Labels are tipically assigned to ontology entities through the `rdfs:label` or `skos:prefLabel` predicates. In particular, it is possible for a single entity to have several labels.\n", - "\n", - "In SimPhoNy, all such labels can be seen, but one label is considered to be the _main_ label. When SimPhoNy has to select exclusively one label among all the available ones, it will first retrieve all the available labels for an entity an then sort them based on the following criteria:\n", - "\n", - "- The predicate used to assign the label. Both `rdfs:label` and `skos:prefLabel` are considered, but labels assigned using `rdfs:label` are preferred to labels assigned to `skos:prefLabel`.\n", - "\n", - "- The language of the label. English labels are preferred to labels with no language assigned to them, and labels with no language to labels in any other language.\n", - "\n", - "So for example, assume that the ontology class " - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.City" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "has as labels (which is actually not the case): _Municipality (language: \"en\", predicate: `skos:prefLabel`)_, _City (language: None, predicate: `rdfs:label`)_, _Città (language: 'it', predicate: `rdfs:label`)_. Then the second one, _City_, would be the main label." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The main label of an ontology entity can be accessed using the _label_ attribute." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'City'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.City.label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "It is also possible to access the language of the main label," - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'en'" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.City.label_lang" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "and even the main label in the form of an [RDFLib Literal](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#literals), which contains both the label itself and its language information." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.Literal('City', lang='en')" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.City.label_literal" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To retrieve all labels as [RDFLib Literals](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#literals), use the [iter_labels](../api_reference.md#simphony_osp.ontology.OntologyEntity.iter_labels) method." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[rdflib.term.Literal('City', lang='en')]" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(city.City.iter_labels())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As you can see, actually the City class has only one label!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Accessing an entity's identifier and namespace" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The identifier (IRI or blank node identifier) of an entity may be accessed using the [identifier](../api_reference.md#simphony_osp.ontology.OntologyEntity.identifier) property." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.URIRef('http://emmo.info/emmo#EMMO_18d180e4_5e3e_42f7_820c_e08951223486')" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "emmo.Real.identifier" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In addition, it is possible to get the namespace object to which the entity belongs using the [namespace](../api_reference.md#simphony_osp.ontology.OntologyEntity.namespace) property." - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "emmo.Equation.namespace" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Accessing super- and subclasses\n", - "\n", - "Using the properties [superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.superclasses) and [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.subclasses) it is easy to navigate the ontology. [Direct superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_superclasses) and [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_subclasses) can also be accessed:" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Superclasses of \"Living Being\": frozenset({, })\n", - "\n", - "Subclasses of \"Living Being\": frozenset({, , })\n", - "\n", - "Direct superclasses of \"Living Being\": frozenset()\n", - "\n", - "Direct subclasses of \"Living Being\": frozenset({})\n", - "\n", - "Is \"Person\" a subclass of \"Living Being\"? True\n", - "Is \"Living Being\" a superclass of \"Person\"? True\n" - ] - } - ], - "source": [ - "from IPython.display import display\n", - "\n", - "print(f\"Superclasses of \\\"Living Being\\\": {city.LivingBeing.superclasses}\", end=\"\\n\"*2)\n", - "print(f\"Subclasses of \\\"Living Being\\\": {city.LivingBeing.subclasses}\", end=\"\\n\"*2)\n", - "\n", - "print(f\"Direct superclasses of \\\"Living Being\\\": {city.LivingBeing.direct_superclasses}\", end=\"\\n\"*2)\n", - "print(f\"Direct subclasses of \\\"Living Being\\\": {city.LivingBeing.direct_subclasses}\", end=\"\\n\"*2)\n", - "\n", - "print(\"Is \\\"Person\\\" a subclass of \\\"Living Being\\\"?\", city.Person.is_subclass_of(city.LivingBeing))\n", - "print(\"Is \\\"Living Being\\\" a superclass of \\\"Person\\\"?\", city.LivingBeing.is_superclass_of(city.Person))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Checking the type of entity\n", - "\n", - "In the terminological knowledge side of the ontology, four types of entities can be defined: [classes](#Operations-specific-to-ontology-class-objects), [relationships](#Operations-specific-to-ontology-relationship-objects), [attributes](#Operations-specific-to-ontology-attribute-objects) and [annotations](#Operations-specific-to-ontology-annotation-objects). There are different Python objects for the different entity types. Both can be used to check to which type an entity belongs:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Is the entity is a class?\n", - "True\n", - "True\n", - "True\n", - "\n", - "Is the entity is a relationship?\n", - "True\n", - "True\n", - "\n", - "Is the entity an attribute?\n", - "True\n", - "True\n", - "\n", - "Is the entity an annotation?\n", - "True\n" - ] - } - ], - "source": [ - "# These are the Python classes for the different types of ontology entities.\n", - "# They all inherit from `simphony_osp.ontology.OntologyEntity`.\n", - "from simphony_osp.namespaces import owl, rdfs\n", - "from simphony_osp.ontology import (\n", - " OntologyAnnotation,\n", - " OntologyAttribute,\n", - " OntologyClass,\n", - " OntologyRelationship,\n", - ")\n", - "\n", - "print(\"\\nIs the entity is a class?\")\n", - "print(isinstance(city.LivingBeing, OntologyClass))\n", - "print(city.LivingBeing.is_subclass_of(owl.Thing))\n", - "print(not city.LivingBeing.is_subclass_of(owl.topObjectProperty)\n", - " and not city.LivingBeing.is_subclass_of(owl.topDataProperty))\n", - "\n", - "print(\"\\nIs the entity is a relationship?\")\n", - "print(isinstance(city.hasInhabitant, OntologyRelationship))\n", - "print(city.hasInhabitant.is_subclass_of(owl.topObjectProperty))\n", - "\n", - "print(\"\\nIs the entity an attribute?\")\n", - "print(isinstance(city['name'], OntologyAttribute))\n", - "print(city['name'].is_subclass_of(owl.topDataProperty))\n", - "\n", - "print(\"\\nIs the entity an annotation?\")\n", - "print(isinstance(rdfs.label, OntologyAnnotation))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All such objects **inherit from the ontology entity object**, and thus, share its common functionality, but each differs in the extra operations they offer." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### [Ontology class objects](../api_reference.md#simphony_osp.ontology.OntologyClass)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "One of the extra functionalities offered by ontology class objects is the access to their attributes. The attributes of an ontology class are those that all instances of a class are expected to share. For example, in OWL ontologies they are defined using the `owl:hasValue`, `owl:someValuesFrom`, `owl:cardinality` or `owl:minCardinality` predicates." - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "mappingproxy({: None,\n", - " : None})" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "city.Citizen.attributes # returns a dictionary whose keys are attributes and whose values are their default values (if defined)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "In addition, SimPhoNy has special support for the `owl:Restriction` and `owl:Composition` classes of the [Web Ontology Language (OWL)](https://en.wikipedia.org/wiki/Web_Ontology_Language) (check the [OWL ontology specification](https://www.w3.org/TR/owl2-syntax/) for more details). Such OWL classes are represented by the Python classes `Restriction` and `Composition`. See [operations specific to ontology axioms](#Operations-specific-to-ontology-axioms) for more information.\n", - "\n", - "For example, in the city ontology, the citizens have a restriction on the name and age attributes: a citizen must have exactly one name and one age. These axioms can be accessed using the `axioms` property, which returns both the restriction and compositions affecting the class." - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('is child of QUANTIFIER.MAX 2',\n", - " 'name QUANTIFIER.EXACTLY 1',\n", - " 'works in QUANTIFIER.MAX 1',\n", - " 'age QUANTIFIER.EXACTLY 1')" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "tuple(str(x) for x in city.Citizen.axioms)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Ontology axioms" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For [restrictions](../api_reference.md#simphony_osp.ontology.Restriction), the quantifier, the target, the restriction type and the relationship/attribute (depending on whether it is a restriction of the relationship type or attribute type) may be accessed." - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "is child of QUANTIFIER.MAX 2\n", - "QUANTIFIER.MAX\n", - "2\n", - "RTYPE.RELATIONSHIP_RESTRICTION\n", - "is child of\n" - ] - } - ], - "source": [ - "from simphony_osp.ontology import RESTRICTION_QUANTIFIER, RESTRICTION_TYPE\n", - "\n", - "restriction = next(iter(city.Citizen.axioms))\n", - "print(restriction)\n", - "print(restriction.quantifier)\n", - "print(restriction.target)\n", - "print(restriction.rtype)\n", - "print(\n", - " restriction.attribute\n", - " if restriction.rtype == RESTRICTION_TYPE.ATTRIBUTE_RESTRICTION else\n", - " restriction.relationship\n", - ") " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For [compositions](../api_reference.md#simphony_osp.ontology.Composition), both the operator and operands can be accesed." - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(SymbolicConstruct OPERATOR.OR Symbol)\n", - "OPERATOR.OR\n", - "(, )\n" - ] - } - ], - "source": [ - "from simphony_osp.ontology import COMPOSITION_OPERATOR, Composition\n", - "\n", - "composition = tuple(x for x in emmo.Integer.axioms if isinstance(x, Composition))[0]\n", - "print(composition)\n", - "print(composition.operator)\n", - "print(composition.operands)" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "tags": [] - }, - "source": [ - "### [Ontology relationship objects](../api_reference.md#simphony_osp.ontology.OntologyRelationship)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can access the inverse of relationships." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "You can get the inverse of a relationship\n", - "None\n" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Terminological knowledge\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fterminological_knowledge.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In an ontological framework, ontology entities are used as a knowledge representation form. Those can be further categorized in two groups: ontology individuals ([assertional knowledge](https://en.wikipedia.org/wiki/Abox)), and ontology classes, relationships, attributes and annotations ([terminological knowledge](https://en.wikipedia.org/wiki/Tbox)). This page **focuses on** how to access and navigate the **terminological knowledge** of an ontology using SimPhoNy." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Such functionality is presented in the form of a tutorial, in which both the `city` namespace from SimPhoNy's example [City ontology](ontologies/ontologies_included.md#the-city-ontology), and the `emmo` namespace from the [Elementary Multiperspective Material Ontology (EMMO)](ontologies/ontologies_included.md#elementary-multiperspective-material-ontology-emmo) are used as examples.\n", + "\n", + "If you want to follow the tutorial along, please [make sure that such ontologies are installed](ontologies/pico.md#pico-list). If you have not installed them yet, you can do so running the commands below." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "# Install the ontologies\n", + "!pico install city emmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "SimPhoNy does **not** feature the ability to edit the classes, relationships, attributes and\n", + "annotations of ontologies, only to read them. This is the reason why ontologies need to be [installed using pico](ontologies/pico.md#installing-ontologies-pico).\n", + "
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## [Namespace objects](../api_reference.md#simphony_osp.ontology.OntologyNamespace): accessing entities\n", + "\n", + "To access ontology entities, it is first needed to know the aliases of the installed ontology namespaces. The [pico ontology management tool](ontologies/pico.md#installing-ontologies-pico) to can list the installed namespaces. Note that each namespace is provided by a specific [ontology package](ontologies/packages.md#ontology-packages).\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Packages:\n", + "\t- simlammps\n", + "\t- city\n", + "\t- emmo\n", + "Namespaces:\n", + "\t- simphony\n", + "\t- owl\n", + "\t- rdfs\n", + "\t- simlammps\n", + "\t- city\n", + "\t- emmo\n" + ] + } + ], + "source": [ + "!pico list" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once the names of the namespaces to be used are known, they can be imported in Python. In this tutorial, the namespaces `city` and `emmo` are imported. Through those imported namespace Python objects, the entities within the namespaces can be accessed:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city, emmo" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The namespace objects are [Python iterables](https://docs.python.org/3/glossary.html). This implies that it is possible to get a list of all the entities available within a namespace running `list(namespace)`. \n", + "\n", + "To get the IRI of a namespace object, use the `iri` property. This will yield an [URIRef object](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#uriref) from the [RDFLib](https://github.com/RDFLib/rdflib) library, that SimPhoNy makes use of." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.URIRef('https://www.simphony-project.eu/city#')" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.iri" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There are several ways to reference an ontology entity to be retrieved, which are summarized in the following list.\n", + "\n", + "- By **suffix**. For example, for the namespace `city`, whose [IRI](https://fusion.cs.uni-jena.de/fusion/blog/2016/11/18/iri-uri-url-urn-and-their-differences/) is `http://www.simphony-osp.eu/city#`, requesting the suffix `Citizen` would return the ontology entity with IRI `http://www.simphony-osp.eu/city#Citizen`.\n", + "\n", + "- By **label**. Retrieves the entity by the [_main label_](#Accessing-an-entity\u2019s-label) that has been assigned to it in the ontology using either the `rdfs:label` or `skos:prefLabel` predicates.\n", + "\n", + "[//]: # \"TODO: It is possible to include more properties or change the order of the properties, link to the sessions page. Link also to give more information about the ordering of the properties and which labels are discarded.\"\n", + "\n", + "- By **IRI**. The [IRI](https://fusion.cs.uni-jena.de/fusion/blog/2016/11/18/iri-uri-url-urn-and-their-differences/) of an ontology entity is provided in order to retrieve it." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Although it is not the only possible approach, the **most convenient way** to access an ontology entity is to use the **dot notation** on the imported namespace objects (e.g. `city.Citizen`) to reference it either by suffix or label." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The dot notation supports IPython autocompletion. For example, when working on a Jupyter notebook, once the namespace has been imported, it is possible to get suggestions for the entity names by writing `namespace.` and pressing TAB.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Accessing an ontology entity by suffix or label**\n", + "\n", + "Let's retrieve the _Living Being_ class from the `city` namespace, whose IRI is `https://www.simphony-project.eu/city#LivingBeing`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To retrieve the class using its suffix or its label, just use the dot notation" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.LivingBeing # by suffix" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "However, sometimes the suffix or label contains characters that Python does not accept as attribute names, such as dashes or spaces. In such cases, it is not possible to use the dot notation. An alternative way to retrieve entitites using the Python's index operator `[]` exists" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city['Living Being'] # by label (contains a space)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The index notation also supports IPython autocompletion.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Note that both operations are case-sensitive, and therefore the following would produce an error." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "# city.Livingbeing # -> Fails." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, the namespace object has some advanced methods, [from_suffix](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_suffix), [from_label](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_label) and [get](../api_reference.md#simphony_osp.ontology.OntologyNamespace.get) that can also be used to retrieve entities by suffix or label." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Accessing an ontology entity by IRI**\n", + "\n", + "Let's now retrieve the Integer class from the `emmo` namespace using its IRI `http://emmo.info/emmo#EMMO_f8bd64d5_5d3e_4ad4_a46e_c30714fecb7f`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To do so, use the method [from_iri](../api_reference.md#simphony_osp.ontology.OntologyNamespace.from_iri) of the corresponding namespace object" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "emmo.from_iri('http://emmo.info/emmo#EMMO_f8bd64d5_5d3e_4ad4_a46e_c30714fecb7f')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## [Ontology entity objects](../api_reference.md#simphony_osp.ontology.OntologyEntity)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Accessing an entity's label" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Labels are tipically assigned to ontology entities through the `rdfs:label` or `skos:prefLabel` predicates. In particular, it is possible for a single entity to have several labels.\n", + "\n", + "In SimPhoNy, all such labels can be seen, but one label is considered to be the _main_ label. When SimPhoNy has to select exclusively one label among all the available ones, it will first retrieve all the available labels for an entity an then sort them based on the following criteria:\n", + "\n", + "- The predicate used to assign the label. Both `rdfs:label` and `skos:prefLabel` are considered, but labels assigned using `rdfs:label` are preferred to labels assigned to `skos:prefLabel`.\n", + "\n", + "- The language of the label. English labels are preferred to labels with no language assigned to them, and labels with no language to labels in any other language.\n", + "\n", + "So for example, assume that the ontology class " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.City" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "has as labels (which is actually not the case): _Municipality (language: \"en\", predicate: `skos:prefLabel`)_, _City (language: None, predicate: `rdfs:label`)_, _Citt\u00e0 (language: 'it', predicate: `rdfs:label`)_. Then the second one, _City_, would be the main label." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The main label of an ontology entity can be accessed using the _label_ attribute." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'City'" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.City.label" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is also possible to access the language of the main label," + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'en'" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.City.label_lang" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "and even the main label in the form of an [RDFLib Literal](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#literals), which contains both the label itself and its language information." + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.Literal('City', lang='en')" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.City.label_literal" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To retrieve all labels as [RDFLib Literals](https://rdflib.readthedocs.io/en/stable/rdf_terms.html#literals), use the [iter_labels](../api_reference.md#simphony_osp.ontology.OntologyEntity.iter_labels) method." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[rdflib.term.Literal('City', lang='en')]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(city.City.iter_labels())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As you can see, actually the City class has only one label!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Accessing an entity's identifier and namespace" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The identifier (IRI or blank node identifier) of an entity may be accessed using the [identifier](../api_reference.md#simphony_osp.ontology.OntologyEntity.identifier) property." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.URIRef('http://emmo.info/emmo#EMMO_18d180e4_5e3e_42f7_820c_e08951223486')" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "emmo.Real.identifier" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, it is possible to get the namespace object to which the entity belongs using the [namespace](../api_reference.md#simphony_osp.ontology.OntologyEntity.namespace) property." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "emmo.Equation.namespace" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Accessing super- and subclasses\n", + "\n", + "Using the properties [superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.superclasses) and [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.subclasses) it is easy to navigate the ontology. [Direct superclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_superclasses) and [subclasses](../api_reference.md#simphony_osp.ontology.OntologyEntity.direct_subclasses) can also be accessed:" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Superclasses of \"Living Being\": frozenset({, })\n", + "\n", + "Subclasses of \"Living Being\": frozenset({, , })\n", + "\n", + "Direct superclasses of \"Living Being\": frozenset()\n", + "\n", + "Direct subclasses of \"Living Being\": frozenset({})\n", + "\n", + "Is \"Person\" a subclass of \"Living Being\"? True\n", + "Is \"Living Being\" a superclass of \"Person\"? True\n" + ] + } + ], + "source": [ + "from IPython.display import display\n", + "\n", + "print(f\"Superclasses of \\\"Living Being\\\": {city.LivingBeing.superclasses}\", end=\"\\n\"*2)\n", + "print(f\"Subclasses of \\\"Living Being\\\": {city.LivingBeing.subclasses}\", end=\"\\n\"*2)\n", + "\n", + "print(f\"Direct superclasses of \\\"Living Being\\\": {city.LivingBeing.direct_superclasses}\", end=\"\\n\"*2)\n", + "print(f\"Direct subclasses of \\\"Living Being\\\": {city.LivingBeing.direct_subclasses}\", end=\"\\n\"*2)\n", + "\n", + "print(\"Is \\\"Person\\\" a subclass of \\\"Living Being\\\"?\", city.Person.is_subclass_of(city.LivingBeing))\n", + "print(\"Is \\\"Living Being\\\" a superclass of \\\"Person\\\"?\", city.LivingBeing.is_superclass_of(city.Person))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Checking the type of entity\n", + "\n", + "In the terminological knowledge side of the ontology, four types of entities can be defined: [classes](#Operations-specific-to-ontology-class-objects), [relationships](#Operations-specific-to-ontology-relationship-objects), [attributes](#Operations-specific-to-ontology-attribute-objects) and [annotations](#Operations-specific-to-ontology-annotation-objects). There are different Python objects for the different entity types. Both can be used to check to which type an entity belongs:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Is the entity is a class?\n", + "True\n", + "True\n", + "True\n", + "\n", + "Is the entity is a relationship?\n", + "True\n", + "True\n", + "\n", + "Is the entity an attribute?\n", + "True\n", + "True\n", + "\n", + "Is the entity an annotation?\n", + "True\n" + ] + } + ], + "source": [ + "# These are the Python classes for the different types of ontology entities.\n", + "# They all inherit from `simphony_osp.ontology.OntologyEntity`.\n", + "from simphony_osp.namespaces import owl, rdfs\n", + "from simphony_osp.ontology import (\n", + " OntologyAnnotation,\n", + " OntologyAttribute,\n", + " OntologyClass,\n", + " OntologyRelationship,\n", + ")\n", + "\n", + "print(\"\\nIs the entity is a class?\")\n", + "print(isinstance(city.LivingBeing, OntologyClass))\n", + "print(city.LivingBeing.is_subclass_of(owl.Thing))\n", + "print(not city.LivingBeing.is_subclass_of(owl.topObjectProperty)\n", + " and not city.LivingBeing.is_subclass_of(owl.topDataProperty))\n", + "\n", + "print(\"\\nIs the entity is a relationship?\")\n", + "print(isinstance(city.hasInhabitant, OntologyRelationship))\n", + "print(city.hasInhabitant.is_subclass_of(owl.topObjectProperty))\n", + "\n", + "print(\"\\nIs the entity an attribute?\")\n", + "print(isinstance(city['name'], OntologyAttribute))\n", + "print(city['name'].is_subclass_of(owl.topDataProperty))\n", + "\n", + "print(\"\\nIs the entity an annotation?\")\n", + "print(isinstance(rdfs.label, OntologyAnnotation))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All such objects **inherit from the ontology entity object**, and thus, share its common functionality, but each differs in the extra operations they offer." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### [Ontology class objects](../api_reference.md#simphony_osp.ontology.OntologyClass)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "One of the extra functionalities offered by ontology class objects is the access to their attributes. The attributes of an ontology class are those that all instances of a class are expected to share. For example, in OWL ontologies they are defined using the `owl:hasValue`, `owl:someValuesFrom`, `owl:cardinality` or `owl:minCardinality` predicates." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "mappingproxy({: None,\n", + " : None})" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.Citizen.attributes # returns a dictionary whose keys are attributes and whose values are their default values (if defined)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "In addition, SimPhoNy has special support for the `owl:Restriction` and `owl:Composition` classes of the [Web Ontology Language (OWL)](https://en.wikipedia.org/wiki/Web_Ontology_Language) (check the [OWL ontology specification](https://www.w3.org/TR/owl2-syntax/) for more details). Such OWL classes are represented by the Python classes `Restriction` and `Composition`. See [operations specific to ontology axioms](#Operations-specific-to-ontology-axioms) for more information.\n", + "\n", + "For example, in the city ontology, the citizens have a restriction on the name and age attributes: a citizen must have exactly one name and one age. These axioms can be accessed using the `axioms` property, which returns both the restriction and compositions affecting the class." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('is child of QUANTIFIER.MAX 2',\n", + " 'name QUANTIFIER.EXACTLY 1',\n", + " 'works in QUANTIFIER.MAX 1',\n", + " 'age QUANTIFIER.EXACTLY 1')" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tuple(str(x) for x in city.Citizen.axioms)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Ontology axioms" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For [restrictions](../api_reference.md#simphony_osp.ontology.Restriction), the quantifier, the target, the restriction type and the relationship/attribute (depending on whether it is a restriction of the relationship type or attribute type) may be accessed." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "is child of QUANTIFIER.MAX 2\n", + "QUANTIFIER.MAX\n", + "2\n", + "RTYPE.RELATIONSHIP_RESTRICTION\n", + "is child of\n" + ] + } + ], + "source": [ + "from simphony_osp.ontology import RESTRICTION_QUANTIFIER, RESTRICTION_TYPE\n", + "\n", + "restriction = next(iter(city.Citizen.axioms))\n", + "print(restriction)\n", + "print(restriction.quantifier)\n", + "print(restriction.target)\n", + "print(restriction.rtype)\n", + "print(\n", + " restriction.attribute\n", + " if restriction.rtype == RESTRICTION_TYPE.ATTRIBUTE_RESTRICTION else\n", + " restriction.relationship\n", + ") " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "For [compositions](../api_reference.md#simphony_osp.ontology.Composition), both the operator and operands can be accesed." + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(SymbolicConstruct OPERATOR.OR Symbol)\n", + "OPERATOR.OR\n", + "(, )\n" + ] + } + ], + "source": [ + "from simphony_osp.ontology import COMPOSITION_OPERATOR, Composition\n", + "\n", + "composition = tuple(x for x in emmo.Integer.axioms if isinstance(x, Composition))[0]\n", + "print(composition)\n", + "print(composition.operator)\n", + "print(composition.operands)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "### [Ontology relationship objects](../api_reference.md#simphony_osp.ontology.OntologyRelationship)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You can access the inverse of relationships." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "You can get the inverse of a relationship\n", + "None\n" + ] + } + ], + "source": [ + "print(\"\\nYou can get the inverse of a relationship\")\n", + "print(city.hasInhabitant.inverse)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### [Ontology attribute objects](../api_reference.md#simphony_osp.ontology.OntologyAttribute)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The datatype of attributes can be accessed." + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "city.age.datatype" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### [Ontology annotation objects](../api_reference.md#simphony_osp.ontology.OntologyAnnotation)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "There is **no specific extra functionality** offered by ontology annotation objects." + ] } - ], - "source": [ - "print(\"\\nYou can get the inverse of a relationship\")\n", - "print(city.hasInhabitant.inverse)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### [Ontology attribute objects](../api_reference.md#simphony_osp.ontology.OntologyAttribute)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The datatype of attributes can be accessed." - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "text/plain": [ - "rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#integer')" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" + ], + "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.8.12" } - ], - "source": [ - "city.age.datatype" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### [Ontology annotation objects](../api_reference.md#simphony_osp.ontology.OntologyAnnotation)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There is **no specific extra functionality** offered by ontology annotation objects." - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/visualization.ipynb b/docs/usage/visualization.ipynb index cb31d3f..9a949c2 100644 --- a/docs/usage/visualization.ipynb +++ b/docs/usage/visualization.ipynb @@ -1,3525 +1,3525 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "5d751f70-0183-4553-8e48-c62eebdc8f75", - "metadata": {}, - "source": [ - "# Visualization" - ] - }, - { - "cell_type": "markdown", - "id": "9a994990-fcda-497a-9e05-beaf9a5d1ddd", - "metadata": {}, - "source": [ - "
\n", - " \n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fvisualization.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "baea79ad-864a-40cf-83e4-27518aa6b8f7", - "metadata": {}, - "source": [ - "SimPhoNy includes two visualization tools:\n", - "\n", - "- [semantic2dot](#semantic2dot) to visualize ontology entities, including both assertional and terminological knowledge,\n", - "- [pretty_print](#pretty_print), used to \"visualize\" ontology individuals as text." - ] - }, - { - "cell_type": "markdown", - "id": "96557eea-a233-4ab0-998c-6b565ad41d2d", - "metadata": {}, - "source": [ - "## `semantic2dot`" - ] - }, - { - "cell_type": "markdown", - "id": "6a84feda-a535-42e9-8833-570169ec2911", - "metadata": {}, - "source": [ - "`semantic2dot` makes use of [Graphviz](https://graphviz.org/) and is located under `simphony_osp.tools.semantic2dot`. It can be used to quickly draw ontologies, as well as ontology individuals. In the representations created by the tool, each ontology entity is represented by a graph node. The relationships between ontology entities are the edges connecting them. The attributes values and classes that individuals belong to are written inside the nodes." - ] - }, - { - "cell_type": "markdown", - "id": "d1d562e8-51e0-4ade-9fc3-3959ec98919b", - "metadata": {}, - "source": [ - "To **draw a namespace** from an installed ontology, import the namespace and pass the namespace object to `semantic2dot`. Several namespace objects can be drawn together in the same picture." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "a06757f3-eb73-4b8f-b5c0-40284d319d9a", - "metadata": {}, - "outputs": [], - "source": [ - "!pico install city foaf" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "784464ff-3280-4ab3-b1ea-5af63284c70c", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.namespaces import city, foaf\n", - "from simphony_osp.tools import semantic2dot" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "136b3f4c-0f9e-4c72-9d7c-19684dec8025", - "metadata": {}, - "outputs": [ + "cells": [ + { + "cell_type": "markdown", + "id": "5d751f70-0183-4553-8e48-c62eebdc8f75", + "metadata": {}, + "source": [ + "# Visualization" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Street\n", - "\n", - "Street (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "Populated Place (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Street->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_sha1\n", - "\n", - "sha1sum (hex) (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "topDataProperty (owl)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_sha1->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasInhabitant\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#encloses\n", - "\n", - "encloses (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasInhabitant->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#coordinates\n", - "\n", - "coordinates (city)\n", - "datatype: https://www.simphony-osp.eu/types#Vector\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#coordinates->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Person\n", - "\n", - "Person (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#LivingBeing\n", - "\n", - "Living Being (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Person->https___www.simphony-osp.eu_city#LivingBeing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_phone\n", - "\n", - "phone (foaf)\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "topObjectProperty (owl)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_phone->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount\n", - "\n", - "Online E-commerce Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "Online Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_icqChatID\n", - "\n", - "ICQ chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_nick\n", - "\n", - "nickname (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_icqChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "Agent (foaf)\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "Thing (owl)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Agent->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_logo\n", - "\n", - "logo (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_logo->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "has worker (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasWorker->https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_gender\n", - "\n", - "gender (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_gender->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_fundedBy\n", - "\n", - "funded by (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_fundedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_PersonalProfileDocument\n", - "\n", - "PersonalProfileDocument (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Document\n", - "\n", - "Document (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_PersonalProfileDocument->http___xmlns.com_foaf_0.1_Document\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Organization\n", - "\n", - "Organization (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Organization->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_familyName\n", - "\n", - "familyName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_familyName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_name\n", - "\n", - "name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#postalCode\n", - "\n", - "postal code (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#number\n", - "\n", - "number (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#postalCode->https___www.simphony-osp.eu_city#number\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_interest\n", - "\n", - "interest (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenName\n", - "\n", - "Given name (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountServiceHomepage\n", - "\n", - "account service homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountServiceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_aimChatID\n", - "\n", - "AIM chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_aimChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "Geographical Place (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#GeographicalPlace->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_weblog\n", - "\n", - "weblog (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_page\n", - "\n", - "page (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_weblog->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_tipjar\n", - "\n", - "tipjar (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_tipjar->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_birthday\n", - "\n", - "birthday (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_birthday->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineGamingAccount\n", - "\n", - "Online Gaming Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineGamingAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_lastName\n", - "\n", - "lastName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_lastName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "is primary topic of (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_primaryTopic\n", - "\n", - "primary topic (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_primaryTopic\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_title\n", - "\n", - "title (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_title->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person\n", - "\n", - "Person (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", - "\n", - "Spatial Thing ()\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person->http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#encloses->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction\n", - "\n", - "depiction (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depicts\n", - "\n", - "depicts (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction->http___xmlns.com_foaf_0.1_depicts\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Document->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_pastProject\n", - "\n", - "past project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_pastProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_primaryTopic->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_img\n", - "\n", - "image (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_img->http___xmlns.com_foaf_0.1_depiction\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_geekcode\n", - "\n", - "geekcode (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_geekcode->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_made\n", - "\n", - "made (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_made->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox_sha1sum\n", - "\n", - "sha1sum of a personal mailbox URI name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox_sha1sum->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_family_name\n", - "\n", - "family_name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_family_name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy\n", - "\n", - "is enclosed by (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineAccount->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_nick->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#City\n", - "\n", - "City (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#City->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountName\n", - "\n", - "account name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalComponent\n", - "\n", - "Architectural Component (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalComponent->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#age\n", - "\n", - "age (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#age->https___www.simphony-osp.eu_city#number\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Building\n", - "\n", - "Building (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalStructure\n", - "\n", - "Architectural Structure (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Building->https___www.simphony-osp.eu_city#ArchitecturalStructure\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker\n", - "\n", - "maker (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker->http___xmlns.com_foaf_0.1_made\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_firstName\n", - "\n", - "firstName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_firstName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#name\n", - "\n", - "name (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#string\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic_interest\n", - "\n", - "topic_interest (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Image\n", - "\n", - "Image (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Image->http___xmlns.com_foaf_0.1_Document\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_myersBriggs\n", - "\n", - "myersBriggs (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_myersBriggs->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_knows\n", - "\n", - "knows (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_knows->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_yahooChatID\n", - "\n", - "Yahoo chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_yahooChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_schoolHomepage\n", - "\n", - "schoolHomepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_schoolHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Group\n", - "\n", - "Group (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Group->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic\n", - "\n", - "topic (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic->http___xmlns.com_foaf_0.1_page\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox\n", - "\n", - "personal mailbox (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_member\n", - "\n", - "member (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_member->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_based_near\n", - "\n", - "based near (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_based_near->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#LivingBeing->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isChildOf\n", - "\n", - "is child of (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "is part of (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isChildOf->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn\n", - "\n", - "works in (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_thumbnail\n", - "\n", - "thumbnail (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_thumbnail->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_skypeID\n", - "\n", - "Skype ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_skypeID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild\n", - "\n", - "has child (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#isChildOf\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_dnaChecksum\n", - "\n", - "DNA checksum (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_dnaChecksum->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineChatAccount\n", - "\n", - "Online Chat Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineChatAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage\n", - "\n", - "homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#PopulatedPlace->https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_page->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Project\n", - "\n", - "Project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Project->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workplaceHomepage\n", - "\n", - "workplace homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workplaceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_jabberID\n", - "\n", - "jabber ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_jabberID->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_focus\n", - "\n", - "focus (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_focus->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Neighborhood\n", - "\n", - "Neighborhood (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Neighborhood->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_LabelProperty\n", - "\n", - "Label Property (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_LabelProperty->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_holdsAccount\n", - "\n", - "account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_holdsAccount->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasMajor\n", - "\n", - "has major (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasMajor->https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_account\n", - "\n", - "account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_account->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_currentProject\n", - "\n", - "current project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_currentProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_status\n", - "\n", - "status (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_status->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workInfoHomepage\n", - "\n", - "work info homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workInfoHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_surname\n", - "\n", - "Surname (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_surname->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depicts->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Floor\n", - "\n", - "Floor (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Floor->https___www.simphony-osp.eu_city#ArchitecturalComponent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_publications\n", - "\n", - "publications (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_publications->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_plan\n", - "\n", - "plan (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_plan->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_msnChatID\n", - "\n", - "MSN chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_msnChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Address\n", - "\n", - "Address (city)\n", - "postal code: None\n", - "number: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Address->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Citizen\n", - "\n", - "Citizen (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Citizen->https___www.simphony-osp.eu_city#Person\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_age\n", - "\n", - "age (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_age->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_theme\n", - "\n", - "theme (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_theme->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_openid\n", - "\n", - "openid (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_openid->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalStructure->https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenname\n", - "\n", - "Given name (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenname->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#number->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isPartOf->https___www.simphony-osp.eu_city#isEnclosedBy\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "id": "9a994990-fcda-497a-9e05-beaf9a5d1ddd", + "metadata": {}, + "source": [ + "
\n", + " \n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fvisualization.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "baea79ad-864a-40cf-83e4-27518aa6b8f7", + "metadata": {}, + "source": [ + "SimPhoNy includes two visualization tools:\n", + "\n", + "- [semantic2dot](#semantic2dot) to visualize ontology entities, including both assertional and terminological knowledge,\n", + "- [pretty_print](#pretty_print), used to \"visualize\" ontology individuals as text." + ] + }, + { + "cell_type": "markdown", + "id": "96557eea-a233-4ab0-998c-6b565ad41d2d", + "metadata": {}, + "source": [ + "## `semantic2dot`" + ] + }, + { + "cell_type": "markdown", + "id": "6a84feda-a535-42e9-8833-570169ec2911", + "metadata": {}, + "source": [ + "`semantic2dot` makes use of [Graphviz](https://graphviz.org/) and is located under `simphony_osp.tools.semantic2dot`. It can be used to quickly draw ontologies, as well as ontology individuals. In the representations created by the tool, each ontology entity is represented by a graph node. The relationships between ontology entities are the edges connecting them. The attributes values and classes that individuals belong to are written inside the nodes." + ] + }, + { + "cell_type": "markdown", + "id": "d1d562e8-51e0-4ade-9fc3-3959ec98919b", + "metadata": {}, + "source": [ + "To **draw a namespace** from an installed ontology, import the namespace and pass the namespace object to `semantic2dot`. Several namespace objects can be drawn together in the same picture." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a06757f3-eb73-4b8f-b5c0-40284d319d9a", + "metadata": {}, + "outputs": [], + "source": [ + "!pico install city foaf" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "784464ff-3280-4ab3-b1ea-5af63284c70c", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.namespaces import city, foaf\n", + "from simphony_osp.tools import semantic2dot" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "136b3f4c-0f9e-4c72-9d7c-19684dec8025", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Street\n", + "\n", + "Street (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "Populated Place (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Street->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_sha1\n", + "\n", + "sha1sum (hex) (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "topDataProperty (owl)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_sha1->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasInhabitant\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#encloses\n", + "\n", + "encloses (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasInhabitant->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#coordinates\n", + "\n", + "coordinates (city)\n", + "datatype: https://www.simphony-osp.eu/types#Vector\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#coordinates->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Person\n", + "\n", + "Person (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#LivingBeing\n", + "\n", + "Living Being (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Person->https___www.simphony-osp.eu_city#LivingBeing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_phone\n", + "\n", + "phone (foaf)\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "topObjectProperty (owl)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_phone->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount\n", + "\n", + "Online E-commerce Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "Online Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_icqChatID\n", + "\n", + "ICQ chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_nick\n", + "\n", + "nickname (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_icqChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "Agent (foaf)\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "Thing (owl)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Agent->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_logo\n", + "\n", + "logo (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_logo->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "has worker (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasWorker->https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_gender\n", + "\n", + "gender (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_gender->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_fundedBy\n", + "\n", + "funded by (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_fundedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_PersonalProfileDocument\n", + "\n", + "PersonalProfileDocument (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Document\n", + "\n", + "Document (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_PersonalProfileDocument->http___xmlns.com_foaf_0.1_Document\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Organization\n", + "\n", + "Organization (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Organization->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_familyName\n", + "\n", + "familyName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_familyName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_name\n", + "\n", + "name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#postalCode\n", + "\n", + "postal code (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#number\n", + "\n", + "number (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#postalCode->https___www.simphony-osp.eu_city#number\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_interest\n", + "\n", + "interest (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenName\n", + "\n", + "Given name (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountServiceHomepage\n", + "\n", + "account service homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountServiceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_aimChatID\n", + "\n", + "AIM chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_aimChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "Geographical Place (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#GeographicalPlace->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_weblog\n", + "\n", + "weblog (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_page\n", + "\n", + "page (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_weblog->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_tipjar\n", + "\n", + "tipjar (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_tipjar->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_birthday\n", + "\n", + "birthday (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_birthday->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineGamingAccount\n", + "\n", + "Online Gaming Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineGamingAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_lastName\n", + "\n", + "lastName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_lastName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "is primary topic of (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_primaryTopic\n", + "\n", + "primary topic (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_primaryTopic\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_title\n", + "\n", + "title (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_title->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person\n", + "\n", + "Person (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", + "\n", + "Spatial Thing ()\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person->http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#encloses->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction\n", + "\n", + "depiction (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depicts\n", + "\n", + "depicts (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction->http___xmlns.com_foaf_0.1_depicts\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Document->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_pastProject\n", + "\n", + "past project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_pastProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_primaryTopic->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_img\n", + "\n", + "image (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_img->http___xmlns.com_foaf_0.1_depiction\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_geekcode\n", + "\n", + "geekcode (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_geekcode->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_made\n", + "\n", + "made (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_made->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox_sha1sum\n", + "\n", + "sha1sum of a personal mailbox URI name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox_sha1sum->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_family_name\n", + "\n", + "family_name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_family_name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy\n", + "\n", + "is enclosed by (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineAccount->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_nick->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#City\n", + "\n", + "City (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#City->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountName\n", + "\n", + "account name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalComponent\n", + "\n", + "Architectural Component (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalComponent->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#age\n", + "\n", + "age (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#age->https___www.simphony-osp.eu_city#number\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Building\n", + "\n", + "Building (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalStructure\n", + "\n", + "Architectural Structure (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Building->https___www.simphony-osp.eu_city#ArchitecturalStructure\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker\n", + "\n", + "maker (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker->http___xmlns.com_foaf_0.1_made\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_firstName\n", + "\n", + "firstName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_firstName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#name\n", + "\n", + "name (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#string\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic_interest\n", + "\n", + "topic_interest (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Image\n", + "\n", + "Image (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Image->http___xmlns.com_foaf_0.1_Document\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_myersBriggs\n", + "\n", + "myersBriggs (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_myersBriggs->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_knows\n", + "\n", + "knows (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_knows->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_yahooChatID\n", + "\n", + "Yahoo chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_yahooChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_schoolHomepage\n", + "\n", + "schoolHomepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_schoolHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Group\n", + "\n", + "Group (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Group->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic\n", + "\n", + "topic (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic->http___xmlns.com_foaf_0.1_page\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox\n", + "\n", + "personal mailbox (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_member\n", + "\n", + "member (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_member->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_based_near\n", + "\n", + "based near (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_based_near->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#LivingBeing->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isChildOf\n", + "\n", + "is child of (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "is part of (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isChildOf->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn\n", + "\n", + "works in (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_thumbnail\n", + "\n", + "thumbnail (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_thumbnail->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_skypeID\n", + "\n", + "Skype ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_skypeID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild\n", + "\n", + "has child (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#isChildOf\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_dnaChecksum\n", + "\n", + "DNA checksum (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_dnaChecksum->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineChatAccount\n", + "\n", + "Online Chat Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineChatAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage\n", + "\n", + "homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#PopulatedPlace->https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_page->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Project\n", + "\n", + "Project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Project->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workplaceHomepage\n", + "\n", + "workplace homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workplaceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_jabberID\n", + "\n", + "jabber ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_jabberID->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_focus\n", + "\n", + "focus (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_focus->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Neighborhood\n", + "\n", + "Neighborhood (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Neighborhood->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_LabelProperty\n", + "\n", + "Label Property (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_LabelProperty->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_holdsAccount\n", + "\n", + "account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_holdsAccount->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasMajor\n", + "\n", + "has major (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasMajor->https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_account\n", + "\n", + "account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_account->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_currentProject\n", + "\n", + "current project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_currentProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_status\n", + "\n", + "status (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_status->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workInfoHomepage\n", + "\n", + "work info homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workInfoHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_surname\n", + "\n", + "Surname (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_surname->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depicts->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Floor\n", + "\n", + "Floor (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Floor->https___www.simphony-osp.eu_city#ArchitecturalComponent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_publications\n", + "\n", + "publications (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_publications->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_plan\n", + "\n", + "plan (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_plan->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_msnChatID\n", + "\n", + "MSN chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_msnChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Address\n", + "\n", + "Address (city)\n", + "postal code: None\n", + "number: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Address->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Citizen\n", + "\n", + "Citizen (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Citizen->https___www.simphony-osp.eu_city#Person\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_age\n", + "\n", + "age (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_age->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_theme\n", + "\n", + "theme (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_theme->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_openid\n", + "\n", + "openid (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_openid->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalStructure->https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenname\n", + "\n", + "Given name (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenname->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#number->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isPartOf->https___www.simphony-osp.eu_city#isEnclosedBy\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "semantic2dot(city, foaf)" ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "semantic2dot(city, foaf)" - ] - }, - { - "cell_type": "markdown", - "id": "24485fc5-634b-425a-bdbb-112f1ffe6eee", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "b104cca5-bf84-47f1-8f9c-8a36aeced0fe", - "metadata": {}, - "source": [ - "It is also possible to **draw the contents of a session**. To do so, pass the session object to `semantic2dot`." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "b7a801ab-31ca-4b20-9c8d-32a0a716f4d4", - "metadata": {}, - "outputs": [ + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "7047ae55...dcf\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", - "\n", - "48927171...334\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "c1816c6e...4fc\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "id": "24485fc5-634b-425a-bdbb-112f1ffe6eee", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "On most web browsers (including mobile ones), you can right-click the picture above and then click \"open in new tab\" to see the picture in its full size.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "b104cca5-bf84-47f1-8f9c-8a36aeced0fe", + "metadata": {}, + "source": [ + "It is also possible to **draw the contents of a session**. To do so, pass the session object to `semantic2dot`." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "b7a801ab-31ca-4b20-9c8d-32a0a716f4d4", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "7047ae55...dcf\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", + "\n", + "48927171...334\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "c1816c6e...4fc\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.session import core_session\n", + "\n", + "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + "peter = city.Citizen(name=\"Peter\", age=30)\n", + "anne = city.Citizen(name=\"Anne\", age=20)\n", + "freiburg[city.hasInhabitant] += peter, anne\n", + "\n", + "semantic2dot(core_session)" ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.session import core_session\n", - "\n", - "freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - "peter = city.Citizen(name=\"Peter\", age=30)\n", - "anne = city.Citizen(name=\"Anne\", age=20)\n", - "freiburg[city.hasInhabitant] += peter, anne\n", - "\n", - "semantic2dot(core_session)" - ] - }, - { - "cell_type": "markdown", - "id": "890a0490-af0b-45c6-b1a7-f811c9526415", - "metadata": {}, - "source": [ - "Another option is to **draw only specific ontology individuals**." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "fb786f44-ad1c-460c-a23c-807466f9d4a1", - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "id": "890a0490-af0b-45c6-b1a7-f811c9526415", + "metadata": {}, + "source": [ + "Another option is to **draw only specific ontology individuals**." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "7047ae55...dcf\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "session: 0x5584dc5dda70\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", - "\n", - "48927171...334\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x5584dc5dda70\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 6, + "id": "fb786f44-ad1c-460c-a23c-807466f9d4a1", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "7047ae55...dcf\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "session: 0x5584dc5dda70\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", + "\n", + "48927171...334\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x5584dc5dda70\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "semantic2dot(freiburg, anne)" ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "semantic2dot(freiburg, anne)" - ] - }, - { - "cell_type": "markdown", - "id": "3b36bfcd-8c65-4390-a16b-eda1b47ac0af", - "metadata": {}, - "source": [ - "Any combination of such three types of object, any number of times can be provided." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "57b0d087-3694-4ef7-a8e7-77148ef1b8bb", - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "id": "3b36bfcd-8c65-4390-a16b-eda1b47ac0af", + "metadata": {}, + "source": [ + "Any combination of such three types of object, any number of times can be provided." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Street\n", - "\n", - "Street (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "Populated Place (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Street->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_sha1\n", - "\n", - "sha1sum (hex) (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "topDataProperty (owl)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_sha1->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasInhabitant\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#encloses\n", - "\n", - "encloses (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasInhabitant->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "is part of (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy\n", - "\n", - "is enclosed by (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isPartOf->https___www.simphony-osp.eu_city#isEnclosedBy\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#coordinates\n", - "\n", - "coordinates (city)\n", - "datatype: https://www.simphony-osp.eu/types#Vector\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#coordinates->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_phone\n", - "\n", - "phone (foaf)\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "topObjectProperty (owl)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_phone->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount\n", - "\n", - "Online E-commerce Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "Online Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_icqChatID\n", - "\n", - "ICQ chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_nick\n", - "\n", - "nickname (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_icqChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "Agent (foaf)\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "Thing (owl)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Agent->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_logo\n", - "\n", - "logo (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_logo->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "has worker (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "has part (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasWorker->https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_gender\n", - "\n", - "gender (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_gender->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_fundedBy\n", - "\n", - "funded by (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_fundedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_PersonalProfileDocument\n", - "\n", - "PersonalProfileDocument (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Document\n", - "\n", - "Document (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_PersonalProfileDocument->http___xmlns.com_foaf_0.1_Document\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "7047ae55...dcf\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "session: 0x5584dc5dda70\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", - "\n", - "48927171...334\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x5584dc5dda70\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "c1816c6e...4fc\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_name\n", - "\n", - "name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Organization\n", - "\n", - "Organization (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Organization->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_familyName\n", - "\n", - "familyName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_familyName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#postalCode\n", - "\n", - "postal code (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#number\n", - "\n", - "number (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#postalCode->https___www.simphony-osp.eu_city#number\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_interest\n", - "\n", - "interest (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenName\n", - "\n", - "Given name (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountServiceHomepage\n", - "\n", - "account service homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountServiceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_aimChatID\n", - "\n", - "AIM chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_aimChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "Geographical Place (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#GeographicalPlace->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_weblog\n", - "\n", - "weblog (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_page\n", - "\n", - "page (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_weblog->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_tipjar\n", - "\n", - "tipjar (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_tipjar->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_birthday\n", - "\n", - "birthday (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_birthday->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineGamingAccount\n", - "\n", - "Online Gaming Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineGamingAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_lastName\n", - "\n", - "lastName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_lastName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "is primary topic of (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_primaryTopic\n", - "\n", - "primary topic (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_primaryTopic\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_title\n", - "\n", - "title (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_title->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person\n", - "\n", - "Person (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", - "\n", - "Spatial Thing ()\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Person->http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#encloses->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction\n", - "\n", - "depiction (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depicts\n", - "\n", - "depicts (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction->http___xmlns.com_foaf_0.1_depicts\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depiction->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Document->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_pastProject\n", - "\n", - "past project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_pastProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_primaryTopic->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_img\n", - "\n", - "image (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_img->http___xmlns.com_foaf_0.1_depiction\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_geekcode\n", - "\n", - "geekcode (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_geekcode->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_made\n", - "\n", - "made (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_made->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox_sha1sum\n", - "\n", - "sha1sum of a personal mailbox URI name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox_sha1sum->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_family_name\n", - "\n", - "family_name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_family_name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isEnclosedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineAccount->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_nick->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#City\n", - "\n", - "City (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#City->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountName\n", - "\n", - "account name (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_accountName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalComponent\n", - "\n", - "Architectural Component (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalComponent->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#age\n", - "\n", - "age (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#integer\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#age->https___www.simphony-osp.eu_city#number\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Building\n", - "\n", - "Building (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalStructure\n", - "\n", - "Architectural Structure (city)\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Building->https___www.simphony-osp.eu_city#ArchitecturalStructure\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker\n", - "\n", - "maker (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker->http___xmlns.com_foaf_0.1_made\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_maker->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_firstName\n", - "\n", - "firstName (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_firstName->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#name\n", - "\n", - "name (city)\n", - "datatype: http://www.w3.org/2001/XMLSchema#string\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#name->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic_interest\n", - "\n", - "topic_interest (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Image\n", - "\n", - "Image (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Image->http___xmlns.com_foaf_0.1_Document\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_myersBriggs\n", - "\n", - "myersBriggs (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_myersBriggs->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_knows\n", - "\n", - "knows (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_knows->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_yahooChatID\n", - "\n", - "Yahoo chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_yahooChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_schoolHomepage\n", - "\n", - "schoolHomepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_schoolHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Group\n", - "\n", - "Group (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Group->http___xmlns.com_foaf_0.1_Agent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic\n", - "\n", - "topic (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic->http___xmlns.com_foaf_0.1_page\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_topic->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox\n", - "\n", - "personal mailbox (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_mbox->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_member\n", - "\n", - "member (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_member->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_based_near\n", - "\n", - "based near (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_based_near->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#LivingBeing\n", - "\n", - "Living Being (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#LivingBeing->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isChildOf\n", - "\n", - "is child of (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#isChildOf->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn\n", - "\n", - "works in (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_thumbnail\n", - "\n", - "thumbnail (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_thumbnail->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_skypeID\n", - "\n", - "Skype ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_skypeID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild\n", - "\n", - "has child (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#isChildOf\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#hasPart\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_dnaChecksum\n", - "\n", - "DNA checksum (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_dnaChecksum->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineChatAccount\n", - "\n", - "Online Chat Account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_OnlineChatAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage\n", - "\n", - "homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_page\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#PopulatedPlace->https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_page->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Project\n", - "\n", - "Project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_Project->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workplaceHomepage\n", - "\n", - "workplace homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workplaceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_jabberID\n", - "\n", - "jabber ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_jabberID->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_focus\n", - "\n", - "focus (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_focus->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Neighborhood\n", - "\n", - "Neighborhood (city)\n", - "coordinates: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Neighborhood->https___www.simphony-osp.eu_city#PopulatedPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_LabelProperty\n", - "\n", - "Label Property (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_LabelProperty->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasMajor\n", - "\n", - "has major (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasMajor->https___www.simphony-osp.eu_city#hasWorker\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_holdsAccount\n", - "\n", - "account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_holdsAccount->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_account\n", - "\n", - "account (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_account->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_currentProject\n", - "\n", - "current project (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_currentProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_status\n", - "\n", - "status (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_status->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workInfoHomepage\n", - "\n", - "work info homepage (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_workInfoHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_surname\n", - "\n", - "Surname (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_surname->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_depicts->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Floor\n", - "\n", - "Floor (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Floor->https___www.simphony-osp.eu_city#ArchitecturalComponent\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_publications\n", - "\n", - "publications (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_publications->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_plan\n", - "\n", - "plan (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_plan->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_msnChatID\n", - "\n", - "MSN chat ID (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_msnChatID->http___xmlns.com_foaf_0.1_nick\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Address\n", - "\n", - "Address (city)\n", - "postal code: None\n", - "number: None\n", - "name: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Address->http___www.w3.org_2002_07_owl#Thing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#isPartOf\n", - "\n", - "inverse\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#encloses\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Citizen\n", - "\n", - "Citizen (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Person\n", - "\n", - "Person (city)\n", - "name: None\n", - "age: None\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Citizen->https___www.simphony-osp.eu_city#Person\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_age\n", - "\n", - "age (foaf)\n", - "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_age->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_theme\n", - "\n", - "theme (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_theme->http___www.w3.org_2002_07_owl#topObjectProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_openid\n", - "\n", - "openid (foaf)\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_openid->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#ArchitecturalStructure->https___www.simphony-osp.eu_city#GeographicalPlace\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenname\n", - "\n", - "Given name (foaf)\n", - "datatype: None\n", - "\n", - "\n", - "\n", - "http___xmlns.com_foaf_0.1_givenname->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#number->http___www.w3.org_2002_07_owl#topDataProperty\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_city#Person->https___www.simphony-osp.eu_city#LivingBeing\n", - "\n", - "\n", - "is_a\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 7, + "id": "57b0d087-3694-4ef7-a8e7-77148ef1b8bb", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Street\n", + "\n", + "Street (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "Populated Place (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Street->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_sha1\n", + "\n", + "sha1sum (hex) (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "topDataProperty (owl)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_sha1->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasInhabitant\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#encloses\n", + "\n", + "encloses (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasInhabitant->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "is part of (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy\n", + "\n", + "is enclosed by (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isPartOf->https___www.simphony-osp.eu_city#isEnclosedBy\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#coordinates\n", + "\n", + "coordinates (city)\n", + "datatype: https://www.simphony-osp.eu/types#Vector\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#coordinates->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_phone\n", + "\n", + "phone (foaf)\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "topObjectProperty (owl)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_phone->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount\n", + "\n", + "Online E-commerce Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "Online Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineEcommerceAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_icqChatID\n", + "\n", + "ICQ chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_nick\n", + "\n", + "nickname (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_icqChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "Agent (foaf)\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "Thing (owl)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Agent->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_logo\n", + "\n", + "logo (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_logo->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "has worker (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "has part (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasWorker->https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_gender\n", + "\n", + "gender (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_gender->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_fundedBy\n", + "\n", + "funded by (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_fundedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_PersonalProfileDocument\n", + "\n", + "PersonalProfileDocument (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Document\n", + "\n", + "Document (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_PersonalProfileDocument->http___xmlns.com_foaf_0.1_Document\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "7047ae55...dcf\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "session: 0x5584dc5dda70\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", + "\n", + "48927171...334\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x5584dc5dda70\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "c1816c6e...4fc\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_name\n", + "\n", + "name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Organization\n", + "\n", + "Organization (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Organization->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_familyName\n", + "\n", + "familyName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_familyName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#postalCode\n", + "\n", + "postal code (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#number\n", + "\n", + "number (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#postalCode->https___www.simphony-osp.eu_city#number\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_interest\n", + "\n", + "interest (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenName\n", + "\n", + "Given name (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountServiceHomepage\n", + "\n", + "account service homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountServiceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_aimChatID\n", + "\n", + "AIM chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_aimChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "Geographical Place (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#GeographicalPlace->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_weblog\n", + "\n", + "weblog (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_page\n", + "\n", + "page (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_weblog->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_tipjar\n", + "\n", + "tipjar (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_tipjar->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_birthday\n", + "\n", + "birthday (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_birthday->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineGamingAccount\n", + "\n", + "Online Gaming Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineGamingAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_lastName\n", + "\n", + "lastName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_lastName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "is primary topic of (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_primaryTopic\n", + "\n", + "primary topic (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_primaryTopic\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_isPrimaryTopicOf->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_title\n", + "\n", + "title (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_title->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person\n", + "\n", + "Person (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", + "\n", + "Spatial Thing ()\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Person->http___www.w3.org_2003_01_geo_wgs84_pos#SpatialThing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#encloses->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction\n", + "\n", + "depiction (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depicts\n", + "\n", + "depicts (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction->http___xmlns.com_foaf_0.1_depicts\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depiction->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Document->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_pastProject\n", + "\n", + "past project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_pastProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_primaryTopic->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_img\n", + "\n", + "image (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_img->http___xmlns.com_foaf_0.1_depiction\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_geekcode\n", + "\n", + "geekcode (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_geekcode->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_made\n", + "\n", + "made (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_made->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox_sha1sum\n", + "\n", + "sha1sum of a personal mailbox URI name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox_sha1sum->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_family_name\n", + "\n", + "family_name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_family_name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isEnclosedBy->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineAccount->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_nick->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#City\n", + "\n", + "City (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#City->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountName\n", + "\n", + "account name (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_accountName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalComponent\n", + "\n", + "Architectural Component (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalComponent->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#age\n", + "\n", + "age (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#integer\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#age->https___www.simphony-osp.eu_city#number\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Building\n", + "\n", + "Building (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalStructure\n", + "\n", + "Architectural Structure (city)\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Building->https___www.simphony-osp.eu_city#ArchitecturalStructure\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker\n", + "\n", + "maker (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker->http___xmlns.com_foaf_0.1_made\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_maker->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_firstName\n", + "\n", + "firstName (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_firstName->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#name\n", + "\n", + "name (city)\n", + "datatype: http://www.w3.org/2001/XMLSchema#string\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#name->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic_interest\n", + "\n", + "topic_interest (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic_interest->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Image\n", + "\n", + "Image (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Image->http___xmlns.com_foaf_0.1_Document\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_myersBriggs\n", + "\n", + "myersBriggs (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_myersBriggs->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_knows\n", + "\n", + "knows (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_knows->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_yahooChatID\n", + "\n", + "Yahoo chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_yahooChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_schoolHomepage\n", + "\n", + "schoolHomepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_schoolHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Group\n", + "\n", + "Group (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Group->http___xmlns.com_foaf_0.1_Agent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic\n", + "\n", + "topic (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic->http___xmlns.com_foaf_0.1_page\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_topic->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox\n", + "\n", + "personal mailbox (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_mbox->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_member\n", + "\n", + "member (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_member->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_based_near\n", + "\n", + "based near (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_based_near->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#LivingBeing\n", + "\n", + "Living Being (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#LivingBeing->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isChildOf\n", + "\n", + "is child of (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#isChildOf->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn\n", + "\n", + "works in (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#worksIn->https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_thumbnail\n", + "\n", + "thumbnail (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_thumbnail->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_skypeID\n", + "\n", + "Skype ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_skypeID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild\n", + "\n", + "has child (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#isChildOf\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasChild->https___www.simphony-osp.eu_city#hasPart\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_dnaChecksum\n", + "\n", + "DNA checksum (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_dnaChecksum->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineChatAccount\n", + "\n", + "Online Chat Account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_OnlineChatAccount->http___xmlns.com_foaf_0.1_OnlineAccount\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage\n", + "\n", + "homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_homepage->http___xmlns.com_foaf_0.1_page\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#PopulatedPlace->https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_page->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Project\n", + "\n", + "Project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_Project->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workplaceHomepage\n", + "\n", + "workplace homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workplaceHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_jabberID\n", + "\n", + "jabber ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_jabberID->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_focus\n", + "\n", + "focus (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_focus->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Neighborhood\n", + "\n", + "Neighborhood (city)\n", + "coordinates: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Neighborhood->https___www.simphony-osp.eu_city#PopulatedPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_LabelProperty\n", + "\n", + "Label Property (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_LabelProperty->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasMajor\n", + "\n", + "has major (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasMajor->https___www.simphony-osp.eu_city#hasWorker\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_holdsAccount\n", + "\n", + "account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_holdsAccount->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_account\n", + "\n", + "account (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_account->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_currentProject\n", + "\n", + "current project (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_currentProject->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_status\n", + "\n", + "status (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_status->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workInfoHomepage\n", + "\n", + "work info homepage (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_workInfoHomepage->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_surname\n", + "\n", + "Surname (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_surname->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_depicts->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Floor\n", + "\n", + "Floor (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Floor->https___www.simphony-osp.eu_city#ArchitecturalComponent\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_publications\n", + "\n", + "publications (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_publications->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_plan\n", + "\n", + "plan (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_plan->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_msnChatID\n", + "\n", + "MSN chat ID (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_msnChatID->http___xmlns.com_foaf_0.1_nick\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Address\n", + "\n", + "Address (city)\n", + "postal code: None\n", + "number: None\n", + "name: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Address->http___www.w3.org_2002_07_owl#Thing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#isPartOf\n", + "\n", + "inverse\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#hasPart->https___www.simphony-osp.eu_city#encloses\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Citizen\n", + "\n", + "Citizen (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Person\n", + "\n", + "Person (city)\n", + "name: None\n", + "age: None\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Citizen->https___www.simphony-osp.eu_city#Person\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_age\n", + "\n", + "age (foaf)\n", + "datatype: http://www.w3.org/2000/01/rdf-schema#Literal\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_age->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_theme\n", + "\n", + "theme (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_theme->http___www.w3.org_2002_07_owl#topObjectProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_openid\n", + "\n", + "openid (foaf)\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_openid->http___xmlns.com_foaf_0.1_isPrimaryTopicOf\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#ArchitecturalStructure->https___www.simphony-osp.eu_city#GeographicalPlace\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenname\n", + "\n", + "Given name (foaf)\n", + "datatype: None\n", + "\n", + "\n", + "\n", + "http___xmlns.com_foaf_0.1_givenname->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#number->http___www.w3.org_2002_07_owl#topDataProperty\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_city#Person->https___www.simphony-osp.eu_city#LivingBeing\n", + "\n", + "\n", + "is_a\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "semantic2dot(foaf, city, core_session, freiburg, anne)" ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "semantic2dot(foaf, city, core_session, freiburg, anne)" - ] - }, - { - "cell_type": "markdown", - "id": "a0f3bdff-0968-4b02-ae5f-78fa7de3977a", - "metadata": {}, - "source": [ - "A relationship can optionally be passed to `semantic2dot` so that it automatically calls the [find](sessions/search.ipynb#find) method from the search module on all ontology individuals and includes the additional individuals in the picture. " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "d349b9be-5671-40c5-93c6-e4ff82492544", - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "id": "a0f3bdff-0968-4b02-ae5f-78fa7de3977a", + "metadata": {}, + "source": [ + "A relationship can optionally be passed to `semantic2dot` so that it automatically calls the [find](sessions/search.ipynb#find) method from the search module on all ontology individuals and includes the additional individuals in the picture. " + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "7047ae55...dcf\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", - "\n", - "48927171...334\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "session: 0x5584dc5dda70\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "c1816c6e...4fc\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 8, + "id": "d349b9be-5671-40c5-93c6-e4ff82492544", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "7047ae55...dcf\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334\n", + "\n", + "48927171...334\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "session: 0x5584dc5dda70\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "c1816c6e...4fc\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#48927171-fd87-42d7-9f40-be7a4f9b7334->https___www.simphony-osp.eu_entity#c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.namespaces import owl\n", + "\n", + "semantic2dot(freiburg, rel=owl.topObjectProperty)" ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.namespaces import owl\n", - "\n", - "semantic2dot(freiburg, rel=owl.topObjectProperty)" - ] - }, - { - "cell_type": "markdown", - "id": "5b542461-bc0f-47fe-ad1d-2adcc3ed4f74", - "metadata": {}, - "source": [ - "`semantic2dot` automatically renders its output as `svg` image files on Jupyter notebooks. However, it is possible to save the generated figures in `gv` (Graphviz) and `png` formats using the `render` method." - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "af12838d-b442-4f7c-bd11-1f31e2c90917", - "metadata": {}, - "outputs": [], - "source": [ - "semantic2dot(freiburg, rel=owl.topObjectProperty).render(\"./picture.gv\")" - ] - }, - { - "cell_type": "markdown", - "id": "dbaa3d0f-55d9-40a4-97b8-37cfa558c120", - "metadata": {}, - "source": [ - "After running the code above, two files, `picture.gv` and `picture.gv.png`, are generated in the current directory." - ] - }, - { - "cell_type": "markdown", - "id": "daf75786-220c-4794-8ca4-7cbc3f309700", - "metadata": {}, - "source": [ - "## `pretty_print`" - ] - }, - { - "cell_type": "markdown", - "id": "cb148ab2-71c1-45e9-95d1-4a348a7f18d1", - "metadata": {}, - "source": [ - "`pretty_print` is located under `simphony_osp.tools.pretty_print`. It generates a tree-like, text-based representation stemming from a given ontology individual, that includes the IRI, ontology classes and attributes of the involved individuals, as well as the relationships connecting them." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "b28f51f3-8488-4721-a968-f594c7b79d0c", - "metadata": {}, - "outputs": [ + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "- Ontology individual:\n", - " identifier: 48927171-fd87-42d7-9f40-be7a4f9b7334\n", - " type: City (city)\n", - " superclasses: City (city), Populated Place (city), Thing (owl), Geographical Place (city)\n", - " values: \u0000coordinates: [47.997791 7.842609]\n", - " \u0000name: Freiburg\n", - " |_Relationship has inhabitant (city):\n", - " - Ontology individual of class Citizen\n", - " . identifier: 7047ae55-f831-44bc-aa25-6f654c17cdcf\n", - " . \u0000age: 20\n", - " . \u0000name: Anne\n", - " - Ontology individual of class Citizen\n", - " identifier: c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", - " \u0000age: 30\n", - " \u0000name: Peter\n" - ] - } - ], - "source": [ - "from simphony_osp.tools import pretty_print\n", - "\n", - "pretty_print(freiburg)" - ] - }, - { - "cell_type": "markdown", - "id": "350de02f-7ef3-4644-9396-eb4e25fe2cef", - "metadata": {}, - "source": [ - "`pretty_print` recursively finds the ontology individuals that are connected to the given one using the [find](sessions/search.ipynb#find) method from the search module. By default, all relationships are followed, but the relationships to follow can be restricted using the keyword argument `rel`. In the example below, the search has been restricted to several relationships that do not exist between `freiburg` and its citizens. Therefore, only `freiburg` is displayed as output." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "78c2e666-1706-40cb-8c7f-98f124313358", - "metadata": {}, - "outputs": [ + "cell_type": "markdown", + "id": "5b542461-bc0f-47fe-ad1d-2adcc3ed4f74", + "metadata": {}, + "source": [ + "`semantic2dot` automatically renders its output as `svg` image files on Jupyter notebooks. However, it is possible to save the generated figures in `gv` (Graphviz) and `png` formats using the `render` method." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "af12838d-b442-4f7c-bd11-1f31e2c90917", + "metadata": {}, + "outputs": [], + "source": [ + "semantic2dot(freiburg, rel=owl.topObjectProperty).render(\"./picture.gv\")" + ] + }, + { + "cell_type": "markdown", + "id": "dbaa3d0f-55d9-40a4-97b8-37cfa558c120", + "metadata": {}, + "source": [ + "After running the code above, two files, `picture.gv` and `picture.gv.png`, are generated in the current directory." + ] + }, + { + "cell_type": "markdown", + "id": "daf75786-220c-4794-8ca4-7cbc3f309700", + "metadata": {}, + "source": [ + "## `pretty_print`" + ] + }, + { + "cell_type": "markdown", + "id": "cb148ab2-71c1-45e9-95d1-4a348a7f18d1", + "metadata": {}, + "source": [ + "`pretty_print` is located under `simphony_osp.tools.pretty_print`. It generates a tree-like, text-based representation stemming from a given ontology individual, that includes the IRI, ontology classes and attributes of the involved individuals, as well as the relationships connecting them." + ] + }, { - "name": "stdout", - "output_type": "stream", - "text": [ - "- Ontology individual:\n", - " identifier: 48927171-fd87-42d7-9f40-be7a4f9b7334\n", - " type: City (city)\n", - " superclasses: City (city), Populated Place (city), Thing (owl), Geographical Place (city)\n", - " values: \u0000coordinates: [47.997791 7.842609]\n", - " \u0000name: Freiburg\n" - ] + "cell_type": "code", + "execution_count": 11, + "id": "b28f51f3-8488-4721-a968-f594c7b79d0c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- Ontology individual:\n", + " identifier: 48927171-fd87-42d7-9f40-be7a4f9b7334\n", + " type: City (city)\n", + " superclasses: City (city), Populated Place (city), Thing (owl), Geographical Place (city)\n", + " values: \u0000coordinates: [47.997791 7.842609]\n", + " \u0000name: Freiburg\n", + " |_Relationship has inhabitant (city):\n", + " - Ontology individual of class Citizen\n", + " . identifier: 7047ae55-f831-44bc-aa25-6f654c17cdcf\n", + " . \u0000age: 20\n", + " . \u0000name: Anne\n", + " - Ontology individual of class Citizen\n", + " identifier: c1816c6e-c441-408f-b0cc-d99641d4f4fc\n", + " \u0000age: 30\n", + " \u0000name: Peter\n" + ] + } + ], + "source": [ + "from simphony_osp.tools import pretty_print\n", + "\n", + "pretty_print(freiburg)" + ] + }, + { + "cell_type": "markdown", + "id": "350de02f-7ef3-4644-9396-eb4e25fe2cef", + "metadata": {}, + "source": [ + "`pretty_print` recursively finds the ontology individuals that are connected to the given one using the [find](sessions/search.ipynb#find) method from the search module. By default, all relationships are followed, but the relationships to follow can be restricted using the keyword argument `rel`. In the example below, the search has been restricted to several relationships that do not exist between `freiburg` and its citizens. Therefore, only `freiburg` is displayed as output." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "78c2e666-1706-40cb-8c7f-98f124313358", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "- Ontology individual:\n", + " identifier: 48927171-fd87-42d7-9f40-be7a4f9b7334\n", + " type: City (city)\n", + " superclasses: City (city), Populated Place (city), Thing (owl), Geographical Place (city)\n", + " values: \u0000coordinates: [47.997791 7.842609]\n", + " \u0000name: Freiburg\n" + ] + } + ], + "source": [ + "pretty_print(freiburg, rel=(city.hasWorker, city.hasMajor))" + ] + } + ], + "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.8.12" } - ], - "source": [ - "pretty_print(freiburg, rel=(city.hasWorker, city.hasMajor))" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/wrappers/dataspace.ipynb b/docs/usage/wrappers/dataspace.ipynb index 8f1198f..e9b9cc9 100644 --- a/docs/usage/wrappers/dataspace.ipynb +++ b/docs/usage/wrappers/dataspace.ipynb @@ -1,125 +1,125 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "adac961d-4e63-40e0-a660-314840baf196", - "metadata": {}, - "source": [ - "# Dataspace\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fdataspace.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] + "cells": [ + { + "cell_type": "markdown", + "id": "adac961d-4e63-40e0-a660-314840baf196", + "metadata": {}, + "source": [ + "# Dataspace\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fdataspace.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "d2616b4a-a2c9-4fca-a600-4f4aee48c488", + "metadata": {}, + "source": [ + "| **Capability** \t| **Support** \t|\n", + "|:-----------:\t|:-----------:\t|\n", + "| Persistence \t| \u2713 \t|\n", + "| Files \t| \u2713 \t|\n", + "| Simulation \t| \u2717 \t|\n", + "| Cache \t| \u2717 \t|" + ] + }, + { + "cell_type": "markdown", + "id": "3374e864-787b-4c38-94b1-5a98323dcfb3", + "metadata": {}, + "source": [ + "The Dataspace wrapper combines the functionality of the [SQLite](sqlite.ipynb) wrapper with support for files. Given a path on your computer, it creates an SQLite database file where the ontology individual data is stored, as well as a `files` subfolder where raw files associated with \"File\" individuals are stored. " + ] + }, + { + "cell_type": "markdown", + "id": "71c97194-337c-441b-9837-00e0b0ecede8", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "Head to the [assertional knowledge](../assertional_knowledge.ipynb#Operations) section for an example on how to work with files.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "f94d11d6-4300-44ae-b584-ae7eb7c753ba", + "metadata": {}, + "source": [ + "The Dataspace wrapper is included with SimPhoNy and located under `simphony_osp.wrappers.Dataspace`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "1bbf781c-fbcb-49e9-9fd1-fd7274d0ace5", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import Dataspace" + ] + }, + { + "cell_type": "markdown", + "id": "d676ceed-1682-4611-a75f-cc1bd4a112a3", + "metadata": {}, + "source": [ + "\u2800" + ] + }, + { + "cell_type": "markdown", + "id": "b00f9ca6-0e08-4d2a-9a4e-1f92cc88e4b2", + "metadata": {}, + "source": [ + "**Configuration**" + ] + }, + { + "cell_type": "markdown", + "id": "ed7977ed-1a71-4c19-bda6-79524450cc65", + "metadata": {}, + "source": [ + "The [configuration string](introduction.ipynb) for the Dataspace wrapper is a path to a folder in your computer. To use the wrapper, just call it providing the [two arguments that SimPhoNy wrappers require](introduction.ipynb): the configuration string and the `create` argument." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "d8eda9b6-1acb-45f5-9ee5-666e74f9821b", + "metadata": {}, + "outputs": [], + "source": [ + "dataspace = Dataspace('dataspace', True)" + ] + } + ], + "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.8.12" + } }, - { - "cell_type": "markdown", - "id": "d2616b4a-a2c9-4fca-a600-4f4aee48c488", - "metadata": {}, - "source": [ - "| **Capability** \t| **Support** \t|\n", - "|:-----------:\t|:-----------:\t|\n", - "| Persistence \t| ✓ \t|\n", - "| Files \t| ✓ \t|\n", - "| Simulation \t| ✗ \t|\n", - "| Cache \t| ✗ \t|" - ] - }, - { - "cell_type": "markdown", - "id": "3374e864-787b-4c38-94b1-5a98323dcfb3", - "metadata": {}, - "source": [ - "The Dataspace wrapper combines the functionality of the [SQLite](sqlite.ipynb) wrapper with support for files. Given a path on your computer, it creates an SQLite database file where the ontology individual data is stored, as well as a `files` subfolder where raw files associated with \"File\" individuals are stored. " - ] - }, - { - "cell_type": "markdown", - "id": "71c97194-337c-441b-9837-00e0b0ecede8", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "Head to the [assertional knowledge](../assertional_knowledge.ipynb#Operations) section for an example on how to work with files.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "f94d11d6-4300-44ae-b584-ae7eb7c753ba", - "metadata": {}, - "source": [ - "The Dataspace wrapper is included with SimPhoNy and located under `simphony_osp.wrappers.Dataspace`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "1bbf781c-fbcb-49e9-9fd1-fd7274d0ace5", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import Dataspace" - ] - }, - { - "cell_type": "markdown", - "id": "d676ceed-1682-4611-a75f-cc1bd4a112a3", - "metadata": {}, - "source": [ - "⠀" - ] - }, - { - "cell_type": "markdown", - "id": "b00f9ca6-0e08-4d2a-9a4e-1f92cc88e4b2", - "metadata": {}, - "source": [ - "**Configuration**" - ] - }, - { - "cell_type": "markdown", - "id": "ed7977ed-1a71-4c19-bda6-79524450cc65", - "metadata": {}, - "source": [ - "The [configuration string](introduction.ipynb) for the Dataspace wrapper is a path to a folder in your computer. To use the wrapper, just call it providing the [two arguments that SimPhoNy wrappers require](introduction.ipynb): the configuration string and the `create` argument." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "d8eda9b6-1acb-45f5-9ee5-666e74f9821b", - "metadata": {}, - "outputs": [], - "source": [ - "dataspace = Dataspace('dataspace', True)" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/wrappers/introduction.ipynb b/docs/usage/wrappers/introduction.ipynb index e1806ee..b46aeef 100644 --- a/docs/usage/wrappers/introduction.ipynb +++ b/docs/usage/wrappers/introduction.ipynb @@ -1,452 +1,452 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fintroduction.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "SimPhoNy Wrappers are pieces of software that seamlessly translate [assertional knowledge](../assertional_knowledge.ipynb) to a form that is compatible with a specific simulation engine, database, data repository or file format. The way to interact with wrappers is through a [session object](../../api_reference.md#simphony_osp.session.Session) that is connected to them. Therefore, before continuing, make sure that you have read the [previous section on sessions](../sessions/index.md)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A few wrappers are included with SimPhoNy, but generally, they must be [installed separately](../introduction/installation.md#Wrapper-installation). The included wrappers are:\n", - "\n", - "- [SQLite wrapper](sqlite.ipynb)\n", - "- [SQLAlchemy wrapper](sqlalchemy.ipynb)\n", - "- [Dataspace wrapper](dataspace.ipynb)\n", - "- [Remote wrapper](remote.ipynb)\n", - "\n", - "After installation, wrappers are available under the `simphony_osp.wrappers` module." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "The `simphony_osp.wrappers` module supports IPython autocompletion. When working on a Jupyter notebook, it is possible to get the installed wrappers as suggestions writing `from simphony_osp.wrappers import ` and pressing TAB.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Wraper capabilities" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Even though from the user's perspective all wrappers are used in the same way, their capabilities may vary with respect to the following points, and thus, have an influence on how the wrapper is used." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Persistence**\n", - "\n", - "Not all wrapper sessions persist the data that you pass to them. Wrappers that interact with databases, such as the included [SQLite wrapper](sqlite.ipynb) and [SQLAlchemy wrapper](sqlalchemy.ipynb) will persist it in the database, but for example, most simulation wrappers do not persist the information anywhere. When using the latter, you are typically expected to load ontology individuals to the session in order to configure the simulation, run it, and then copy ontology individuals back from the simulation wrapper to somewhere else. The contents of the wrapper session are discarded after the session is closed." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Files**\n", - "\n", - "SimPhoNy allows to mix assertional knowledge with files in the same session. Files are represented by ontology individuals that belong to the class \"File\" from the `simphony` namespace (included with SimPhoNy). Head to the [assertional knowledge](../assertional_knowledge.ipynb#Operations) section for an example on how to work with files.\n", - "\n", - "However, this functionality only works in some wrapper sessions that support it. When transferring file individuals, raw files will **not** be transferred together with them to wrapper sessions that do not support files. Therefore, always be mindful when transferring file individuals to prevent data loss." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "Think twice before deleting a \"File\" individual that has raw files attached to it. Do you have a copy in another session **that supports files**? If not, then by doing so you are deleting your raw file. \n", - "\n", - "If you delete a file individual by mistake, remember that changes will not be applied until you commit them. Consider closing the session without committing the changes.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Simulation**\n", - "\n", - "SimPhoNy wrappers interact with different kinds of software. Wrapper sessions can have a method `compute` (more on it [later](#Operating-wrapper-sessions)) that serves to fire up the transformation of the data contained in them (e.g. run a simulation). However, such a method makes no sense, for example, for wrappers that interact with databases. Thus, not all wrapper sessions have this method defined." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Cache**" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Wrapper developers can choose to opt-in for a caching feature that is built-in in SimPhoNy. Imagine that you are operating a database wrapper that connects to a remote server. Every time you perform an action in SimPhoNy, data needs to be transferred to the database and back, introducing latency. The caching feature keeps a [Least Recently Used (LRU)](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU) cache of ontology individuals so that in many situations this transfer can be omitted." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Operating wrapper sessions" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As described on the [introduction to sessions](../sessions/introduction.ipynb), sessions, and as a consequence also wrappers, work in a way similar to databases. To start using them, one first has to “open” or “connect” to them. After that, changes can be performed on the data they contain, but such changes are not made permanent until a “commit” is performed. When one finishes working with them, the connection should be “closed”. Unconfirmed changes are lost when the connection is “closed”." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's see how to manage a wrapper session using the SQLite wrapper as example." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import SQLite" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To initialize a session linked to a wrapper, call the imported object. Wrappers take two positional arguments: the `configuration_string` and the `create` argument.\n", - "\n", - "The configuration string lets the wrapper know which resource to \"open\" or to \"connect to\". For the SQLite wrapper, it is the path of an SQLite database file. The `create` arguments can be set to `True` to ask the wrapper to create the resource specified by the configuration string if it does not already exist." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ + "cells": [ { - "data": { - "text/plain": [ - "" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Introduction\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fintroduction.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "sqlite = SQLite('database.db', True)\n", - "sqlite.clear() # just in case you already ran this notebook\n", - "sqlite.locked = True # was explained in the \"introduction to sessions\" section\n", - "sqlite" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ + }, { - "data": { - "text/plain": [ - "0" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "SimPhoNy Wrappers are pieces of software that seamlessly translate [assertional knowledge](../assertional_knowledge.ipynb) to a form that is compatible with a specific simulation engine, database, data repository or file format. The way to interact with wrappers is through a [session object](../../api_reference.md#simphony_osp.session.Session) that is connected to them. Therefore, before continuing, make sure that you have read the [previous section on sessions](../sessions/index.md)." ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len(sqlite)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "Some wrappers may accept additional keyword arguments.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "As you can see, the `sqlite` object that has been created is just a normal session that can store ontology individuals. The wrapper session is **automatically \"opened\" when it is created**." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A few wrappers are included with SimPhoNy, but generally, they must be [installed separately](../introduction/installation.md#Wrapper-installation). The included wrappers are:\n", + "\n", + "- [SQLite wrapper](sqlite.ipynb)\n", + "- [SQLAlchemy wrapper](sqlalchemy.ipynb)\n", + "- [Dataspace wrapper](dataspace.ipynb)\n", + "- [Remote wrapper](remote.ipynb)\n", + "\n", + "After installation, wrappers are available under the `simphony_osp.wrappers` module." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "The `simphony_osp.wrappers` module supports IPython autocompletion. When working on a Jupyter notebook, it is possible to get the installed wrappers as suggestions writing `from simphony_osp.wrappers import ` and pressing TAB.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Wraper capabilities" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Even though from the user's perspective all wrappers are used in the same way, their capabilities may vary with respect to the following points, and thus, have an influence on how the wrapper is used." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Persistence**\n", + "\n", + "Not all wrapper sessions persist the data that you pass to them. Wrappers that interact with databases, such as the included [SQLite wrapper](sqlite.ipynb) and [SQLAlchemy wrapper](sqlalchemy.ipynb) will persist it in the database, but for example, most simulation wrappers do not persist the information anywhere. When using the latter, you are typically expected to load ontology individuals to the session in order to configure the simulation, run it, and then copy ontology individuals back from the simulation wrapper to somewhere else. The contents of the wrapper session are discarded after the session is closed." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Files**\n", + "\n", + "SimPhoNy allows to mix assertional knowledge with files in the same session. Files are represented by ontology individuals that belong to the class \"File\" from the `simphony` namespace (included with SimPhoNy). Head to the [assertional knowledge](../assertional_knowledge.ipynb#Operations) section for an example on how to work with files.\n", + "\n", + "However, this functionality only works in some wrapper sessions that support it. When transferring file individuals, raw files will **not** be transferred together with them to wrapper sessions that do not support files. Therefore, always be mindful when transferring file individuals to prevent data loss." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "Think twice before deleting a \"File\" individual that has raw files attached to it. Do you have a copy in another session **that supports files**? If not, then by doing so you are deleting your raw file. \n", + "\n", + "If you delete a file individual by mistake, remember that changes will not be applied until you commit them. Consider closing the session without committing the changes.\n", + "\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Simulation**\n", + "\n", + "SimPhoNy wrappers interact with different kinds of software. Wrapper sessions can have a method `compute` (more on it [later](#Operating-wrapper-sessions)) that serves to fire up the transformation of the data contained in them (e.g. run a simulation). However, such a method makes no sense, for example, for wrappers that interact with databases. Thus, not all wrapper sessions have this method defined." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Cache**" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Wrapper developers can choose to opt-in for a caching feature that is built-in in SimPhoNy. Imagine that you are operating a database wrapper that connects to a remote server. Every time you perform an action in SimPhoNy, data needs to be transferred to the database and back, introducing latency. The caching feature keeps a [Least Recently Used (LRU)](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU) cache of ontology individuals so that in many situations this transfer can be omitted." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Operating wrapper sessions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As described on the [introduction to sessions](../sessions/introduction.ipynb), sessions, and as a consequence also wrappers, work in a way similar to databases. To start using them, one first has to \u201copen\u201d or \u201cconnect\u201d to them. After that, changes can be performed on the data they contain, but such changes are not made permanent until a \u201ccommit\u201d is performed. When one finishes working with them, the connection should be \u201cclosed\u201d. Unconfirmed changes are lost when the connection is \u201cclosed\u201d." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's see how to manage a wrapper session using the SQLite wrapper as example." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import SQLite" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To initialize a session linked to a wrapper, call the imported object. Wrappers take two positional arguments: the `configuration_string` and the `create` argument.\n", + "\n", + "The configuration string lets the wrapper know which resource to \"open\" or to \"connect to\". For the SQLite wrapper, it is the path of an SQLite database file. The `create` arguments can be set to `True` to ask the wrapper to create the resource specified by the configuration string if it does not already exist." + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab\n", - "\n", - "8866b5c9...0ab\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", - "\n", - "56191885...b16\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", - "\n", - "cdfc0dbc...7a2\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "sqlite = SQLite('database.db', True)\n", + "sqlite.clear() # just in case you already ran this notebook\n", + "sqlite.locked = True # was explained in the \"introduction to sessions\" section\n", + "sqlite" ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from simphony_osp.namespaces import city\n", - "from simphony_osp.tools import semantic2dot\n", - "\n", - "with sqlite:\n", - " freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", - " peter = city.Citizen(name=\"Peter\", age=30)\n", - " anne = city.Citizen(name=\"Anne\", age=20)\n", - " freiburg[city.hasInhabitant] += peter, anne\n", - " \n", - "semantic2dot(sqlite)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To confirm the set of changes that have been performed, it is necessary to \"commit\" them. Remember that **uncommitted changes are lost** after closing the session or the Python shell." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "sqlite.commit()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "After the job is done, the session should be \"closed\" to free the resource that is being used. In the SQLite case, to close the database file." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "sqlite.close()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The city and its citizens have been successfully saved to the database file. If the wrapper is used to reopen the database, the saved individuals will be available in the resulting session object." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(sqlite)" + ] + }, { - "data": { - "image/svg+xml": [ - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "SimPhoNy semantic2dot\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab\n", - "\n", - "8866b5c9...0ab\n", - "classes: City (city)\n", - "name: Freiburg\n", - "coordinates: [47.997791  7.842609]\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", - "\n", - "56191885...b16\n", - "classes: Citizen (city)\n", - "age: 30\n", - "name: Peter\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", - "\n", - "cdfc0dbc...7a2\n", - "classes: Citizen (city)\n", - "age: 20\n", - "name: Anne\n", - "\n", - "\n", - "\n", - "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", - "\n", - "\n", - "has inhabitant (city)\n", - "\n", - "\n", - "\n" + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "Some wrappers may accept additional keyword arguments.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As you can see, the `sqlite` object that has been created is just a normal session that can store ontology individuals. The wrapper session is **automatically \"opened\" when it is created**." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab\n", + "\n", + "8866b5c9...0ab\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", + "\n", + "56191885...b16\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", + "\n", + "cdfc0dbc...7a2\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } ], - "text/plain": [ - "" + "source": [ + "from simphony_osp.namespaces import city\n", + "from simphony_osp.tools import semantic2dot\n", + "\n", + "with sqlite:\n", + " freiburg = city.City(name=\"Freiburg\", coordinates=[47.997791, 7.842609])\n", + " peter = city.Citizen(name=\"Peter\", age=30)\n", + " anne = city.Citizen(name=\"Anne\", age=20)\n", + " freiburg[city.hasInhabitant] += peter, anne\n", + " \n", + "semantic2dot(sqlite)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To confirm the set of changes that have been performed, it is necessary to \"commit\" them. Remember that **uncommitted changes are lost** after closing the session or the Python shell." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "sqlite.commit()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After the job is done, the session should be \"closed\" to free the resource that is being used. In the SQLite case, to close the database file." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "sqlite.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The city and its citizens have been successfully saved to the database file. If the wrapper is used to reopen the database, the saved individuals will be available in the resulting session object." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "SimPhoNy semantic2dot\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab\n", + "\n", + "8866b5c9...0ab\n", + "classes: City (city)\n", + "name: Freiburg\n", + "coordinates: [47.997791  7.842609]\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", + "\n", + "56191885...b16\n", + "classes: Citizen (city)\n", + "age: 30\n", + "name: Peter\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#56191885-e60c-4347-a3aa-f0337b9a4b16\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", + "\n", + "cdfc0dbc...7a2\n", + "classes: Citizen (city)\n", + "age: 20\n", + "name: Anne\n", + "\n", + "\n", + "\n", + "https___www.simphony-osp.eu_entity#8866b5c9-f8e5-42df-bcb1-43777aba30ab->https___www.simphony-osp.eu_entity#cdfc0dbc-675e-4a77-92db-50ff964a37a2\n", + "\n", + "\n", + "has inhabitant (city)\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from IPython.display import display\n", + "\n", + "with SQLite('database.db', True) as sqlite:\n", + " display(semantic2dot(sqlite))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Wrappers sessions that interact with simulation engines have an additional method, `compute`, that commits the uncommitted data, executes the simulation and updates the session to reflect the new status of the individuals involved. Depending on the wrapper, the `compute` method may accept keyword arguments. The [quickstart](../../introduction/quickstart.ipynb#Wrappers) tutorial demonstrates the use of the `compute` method with the [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrapper, as well as how transfer of ontology individuals between different wrappers, which is done in exactly the same way as [between sessions](../sessions/management.ipynb). " ] - }, - "metadata": {}, - "output_type": "display_data" } - ], - "source": [ - "from IPython.display import display\n", - "\n", - "with SQLite('database.db', True) as sqlite:\n", - " display(semantic2dot(sqlite))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Wrappers sessions that interact with simulation engines have an additional method, `compute`, that commits the uncommitted data, executes the simulation and updates the session to reflect the new status of the individuals involved. Depending on the wrapper, the `compute` method may accept keyword arguments. The [quickstart](../../introduction/quickstart.ipynb#Wrappers) tutorial demonstrates the use of the `compute` method with the [SimLAMMPS](https://github.com/simphony/simphony-osp-simlammps) wrapper, as well as how transfer of ontology individuals between different wrappers, which is done in exactly the same way as [between sessions](../sessions/management.ipynb). " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" + ], + "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.8.12" + } }, - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4 + "nbformat": 4, + "nbformat_minor": 4 } diff --git a/docs/usage/wrappers/remote.ipynb b/docs/usage/wrappers/remote.ipynb index 9bc25ab..719cd6a 100644 --- a/docs/usage/wrappers/remote.ipynb +++ b/docs/usage/wrappers/remote.ipynb @@ -1,200 +1,200 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "be3d28d9-ce12-456a-a3d9-1d3433b4b365", - "metadata": {}, - "source": [ - "# Remote\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fremote.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] + "cells": [ + { + "cell_type": "markdown", + "id": "be3d28d9-ce12-456a-a3d9-1d3433b4b365", + "metadata": {}, + "source": [ + "# Remote\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fremote.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "a19a1bbc-33b1-41aa-a9f3-5e26f64b977d", + "metadata": {}, + "source": [ + "| **Capability** \t| **Support** \t|\n", + "|:-----------:\t|:-----------:\t|\n", + "| Persistence \t| \u2713* \t|\n", + "| Files \t| \u2713* \t|\n", + "| Simulation \t| \u2713* \t|\n", + "| Cache \t| \u2713 \t|" + ] + }, + { + "cell_type": "markdown", + "id": "911cbd6c-5401-403a-b789-8192e68c33d7", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + " \n", + "\\* Capabilities are supported on the client-side, but the wrapper session running on the server needs to support them as well.\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "636a3794-9070-4072-b8a6-acaad4b7ab95", + "metadata": {}, + "source": [ + "The Remote Wrapper is a special type of wrapper used to interact with a wrapper session that lives in a remote server. For example, a [Dataspace](dataspace.ipynb) wrapper session could be started on a remote server to let a single user store his/her data there. The Remote wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.Remote`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ec1eac03-b22c-4ade-b289-d071ef84aa86", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import Remote" + ] + }, + { + "cell_type": "markdown", + "id": "77132ffd-2e92-48d8-8405-abd5a82baa8c", + "metadata": {}, + "source": [ + "\u2800" + ] + }, + { + "cell_type": "markdown", + "id": "192a82ff-6a2c-4a5d-bd66-95eb75365bc7", + "metadata": {}, + "source": [ + "**Configuration**" + ] + }, + { + "cell_type": "markdown", + "id": "b80236fd-2c4d-4d1f-88df-83984c4d82a9", + "metadata": {}, + "source": [ + "The [configuration string](introduction.ipynb) for the Remote wrapper is a [URI](https://www.ietf.org/rfc/rfc3986.txt) pointing to the server that hosts the remote wrapper session." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d7d4b9eb-b9fc-4604-b5ae-57be1442aa0e", + "metadata": {}, + "outputs": [], + "source": [ + "# needed to use the wrapper on a Jupyter notebook\n", + "import nest_asyncio\n", + "nest_asyncio.apply()\n", + "\n", + "remote = Remote('ws://username:password@127.0.0.1:4008', True)\n", + "# If you are running this page on Binder, do not run this cell until the server is running.\n", + "# Wait a few seconds after launching the server so that it has enough time to initialize." + ] + }, + { + "cell_type": "markdown", + "id": "e256fd5b-7e19-4253-870a-58f426f368e0", + "metadata": {}, + "source": [ + "When the remote wrapper session is closed, only the connection is closed. The server will keep its wrapper session open and wait for a user to connect again." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "62ef6ffc-7f93-4c88-91e3-cdaf12dfc94a", + "metadata": {}, + "outputs": [], + "source": [ + "remote.close()" + ] + }, + { + "cell_type": "markdown", + "id": "c5b6d34e-561e-40f7-a825-34c987eb9cec", + "metadata": {}, + "source": [ + "## Server setup" + ] + }, + { + "cell_type": "markdown", + "id": "8b9dca67-553a-4350-8d6f-b0eee192da14", + "metadata": {}, + "source": [ + "To quickly fire up a server, use the function `simphony_osp.tools.host`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c45d29a3-cb57-4e6c-a668-f00a1328fabf", + "metadata": {}, + "outputs": [], + "source": [ + "import multiprocess as multiprocessing # patched version of multiprocessing to work in Binder, use normal multiprocessing in your machine\n", + "\n", + "def launch_server():\n", + " from simphony_osp.tools import host\n", + " from simphony_osp.wrappers import Dataspace\n", + " \n", + " host(\n", + " Dataspace,\n", + " \"dataspace\",\n", + " True,\n", + " hostname=\"127.0.0.1\", # hostname to listen on\n", + " port=4008, # port to listen on\n", + " username=\"username\",\n", + " password=\"password\",\n", + " )\n", + " \n", + "multiprocessing.set_start_method(\"spawn\") # needed for the example to work in Binder\n", + "server = multiprocessing.Process(target=launch_server)\n", + "server.start()" + ] + }, + { + "cell_type": "markdown", + "id": "5fcb7efa-cd51-4a68-8b18-de7361276358", + "metadata": {}, + "source": [ + "
\n", + "
Note
\n", + "\n", + "The server on this example works for just one user. SimPhoNy does not include a method to spawn a server that can be used by multiple users.\n", + " \n", + "However, if you take a look at [SimPhoNy's source code](https://github.com/simphony/simphony-osp/blob/v4.0.0/simphony_osp/tools/remote.py#L9), you will realize that most of the pieces of the puzzle are already there, so it would be relatively simple to modify the `host` function to achieve such goal.\n", + " \n", + "
" + ] + } + ], + "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.8.12" + } }, - { - "cell_type": "markdown", - "id": "a19a1bbc-33b1-41aa-a9f3-5e26f64b977d", - "metadata": {}, - "source": [ - "| **Capability** \t| **Support** \t|\n", - "|:-----------:\t|:-----------:\t|\n", - "| Persistence \t| ✓* \t|\n", - "| Files \t| ✓* \t|\n", - "| Simulation \t| ✓* \t|\n", - "| Cache \t| ✓ \t|" - ] - }, - { - "cell_type": "markdown", - "id": "911cbd6c-5401-403a-b789-8192e68c33d7", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - " \n", - "\\* Capabilities are supported on the client-side, but the wrapper session running on the server needs to support them as well.\n", - " \n", - "
" - ] - }, - { - "cell_type": "markdown", - "id": "636a3794-9070-4072-b8a6-acaad4b7ab95", - "metadata": {}, - "source": [ - "The Remote Wrapper is a special type of wrapper used to interact with a wrapper session that lives in a remote server. For example, a [Dataspace](dataspace.ipynb) wrapper session could be started on a remote server to let a single user store his/her data there. The Remote wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.Remote`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "ec1eac03-b22c-4ade-b289-d071ef84aa86", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import Remote" - ] - }, - { - "cell_type": "markdown", - "id": "77132ffd-2e92-48d8-8405-abd5a82baa8c", - "metadata": {}, - "source": [ - "⠀" - ] - }, - { - "cell_type": "markdown", - "id": "192a82ff-6a2c-4a5d-bd66-95eb75365bc7", - "metadata": {}, - "source": [ - "**Configuration**" - ] - }, - { - "cell_type": "markdown", - "id": "b80236fd-2c4d-4d1f-88df-83984c4d82a9", - "metadata": {}, - "source": [ - "The [configuration string](introduction.ipynb) for the Remote wrapper is a [URI](https://www.ietf.org/rfc/rfc3986.txt) pointing to the server that hosts the remote wrapper session." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "d7d4b9eb-b9fc-4604-b5ae-57be1442aa0e", - "metadata": {}, - "outputs": [], - "source": [ - "# needed to use the wrapper on a Jupyter notebook\n", - "import nest_asyncio\n", - "nest_asyncio.apply()\n", - "\n", - "remote = Remote('ws://username:password@127.0.0.1:4008', True)\n", - "# If you are running this page on Binder, do not run this cell until the server is running.\n", - "# Wait a few seconds after launching the server so that it has enough time to initialize." - ] - }, - { - "cell_type": "markdown", - "id": "e256fd5b-7e19-4253-870a-58f426f368e0", - "metadata": {}, - "source": [ - "When the remote wrapper session is closed, only the connection is closed. The server will keep its wrapper session open and wait for a user to connect again." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "62ef6ffc-7f93-4c88-91e3-cdaf12dfc94a", - "metadata": {}, - "outputs": [], - "source": [ - "remote.close()" - ] - }, - { - "cell_type": "markdown", - "id": "c5b6d34e-561e-40f7-a825-34c987eb9cec", - "metadata": {}, - "source": [ - "## Server setup" - ] - }, - { - "cell_type": "markdown", - "id": "8b9dca67-553a-4350-8d6f-b0eee192da14", - "metadata": {}, - "source": [ - "To quickly fire up a server, use the function `simphony_osp.tools.host`." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "c45d29a3-cb57-4e6c-a668-f00a1328fabf", - "metadata": {}, - "outputs": [], - "source": [ - "import multiprocess as multiprocessing # patched version of multiprocessing to work in Binder, use normal multiprocessing in your machine\n", - "\n", - "def launch_server():\n", - " from simphony_osp.tools import host\n", - " from simphony_osp.wrappers import Dataspace\n", - " \n", - " host(\n", - " Dataspace,\n", - " \"dataspace\",\n", - " True,\n", - " hostname=\"127.0.0.1\", # hostname to listen on\n", - " port=4008, # port to listen on\n", - " username=\"username\",\n", - " password=\"password\",\n", - " )\n", - " \n", - "multiprocessing.set_start_method(\"spawn\") # needed for the example to work in Binder\n", - "server = multiprocessing.Process(target=launch_server)\n", - "server.start()" - ] - }, - { - "cell_type": "markdown", - "id": "5fcb7efa-cd51-4a68-8b18-de7361276358", - "metadata": {}, - "source": [ - "
\n", - "
Note
\n", - "\n", - "The server on this example works for just one user. SimPhoNy does not include a method to spawn a server that can be used by multiple users.\n", - " \n", - "However, if you take a look at [SimPhoNy's source code](https://github.com/simphony/simphony-osp/blob/v4.0.0/simphony_osp/tools/remote.py#L9), you will realize that most of the pieces of the puzzle are already there, so it would be relatively simple to modify the `host` function to achieve such goal.\n", - " \n", - "
" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/wrappers/sqlalchemy.ipynb b/docs/usage/wrappers/sqlalchemy.ipynb index 6f17a86..c9c6239 100644 --- a/docs/usage/wrappers/sqlalchemy.ipynb +++ b/docs/usage/wrappers/sqlalchemy.ipynb @@ -1,117 +1,117 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "82d9ed3a-e587-4a3b-9de1-ac2a1f89feaf", - "metadata": {}, - "source": [ - "# SQLAlchemy\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fsqlalchemy.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] + "cells": [ + { + "cell_type": "markdown", + "id": "82d9ed3a-e587-4a3b-9de1-ac2a1f89feaf", + "metadata": {}, + "source": [ + "# SQLAlchemy\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fsqlalchemy.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "dea73729-6ffb-4b06-9c4c-d24ed1a4310e", + "metadata": {}, + "source": [ + "| **Capability** \t| **Support** \t|\n", + "|:-----------:\t|:-----------:\t|\n", + "| Persistence \t| \u2713 \t|\n", + "| Files \t| \u2717 \t|\n", + "| Simulation \t| \u2717 \t|\n", + "| Cache \t| \u2717 \t|" + ] + }, + { + "cell_type": "markdown", + "id": "326fdb5a-01e1-4c1b-adfe-cc369513bdef", + "metadata": {}, + "source": [ + "The SQLAlchemy wrapper can store ontology individuals using several tables on any of the database backends suported by [SQLAlchemy](https://www.sqlalchemy.org/). It is based on the [rdflib-sqlalchemy](https://github.com/RDFLib/rdflib-sqlalchemy) package. The wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.SQLAlchemy`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "1a77b8c1-1df7-4ea2-be35-99e895d9702f", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import SQLAlchemy" + ] + }, + { + "cell_type": "markdown", + "id": "df69fe31-34e2-4d7b-ac42-d402bdeb0121", + "metadata": {}, + "source": [ + "\u2800" + ] + }, + { + "cell_type": "markdown", + "id": "42f1a5ab-746f-46a0-b461-e5fd7670f4d5", + "metadata": {}, + "source": [ + "**Configuration**" + ] + }, + { + "cell_type": "markdown", + "id": "c62ac54c-ab0f-4335-ad7f-2f781bd9db8d", + "metadata": {}, + "source": [ + "The [configuration string](introduction.ipynb) for the SQLAlchemy wrapper is an [SQLAlchemy Database URL](https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls). To use the wrapper, just provide such an URL and the `create` argument." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "ec2b9121-09e2-4804-9ec5-b7c3ac90d308", + "metadata": {}, + "outputs": [], + "source": [ + "sqlalchemy = SQLAlchemy('sqlite:///database.db', True)" + ] + }, + { + "cell_type": "markdown", + "id": "3a88d725-3fd6-4ba0-ac15-6540b95a40ea", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "Check the [SQLAlchemy documentation](https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls) to learn how to construct database URLs.\n", + " \n", + "
" + ] + } + ], + "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.8.12" + } }, - { - "cell_type": "markdown", - "id": "dea73729-6ffb-4b06-9c4c-d24ed1a4310e", - "metadata": {}, - "source": [ - "| **Capability** \t| **Support** \t|\n", - "|:-----------:\t|:-----------:\t|\n", - "| Persistence \t| ✓ \t|\n", - "| Files \t| ✗ \t|\n", - "| Simulation \t| ✗ \t|\n", - "| Cache \t| ✗ \t|" - ] - }, - { - "cell_type": "markdown", - "id": "326fdb5a-01e1-4c1b-adfe-cc369513bdef", - "metadata": {}, - "source": [ - "The SQLAlchemy wrapper can store ontology individuals using several tables on any of the database backends suported by [SQLAlchemy](https://www.sqlalchemy.org/). It is based on the [rdflib-sqlalchemy](https://github.com/RDFLib/rdflib-sqlalchemy) package. The wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.SQLAlchemy`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "1a77b8c1-1df7-4ea2-be35-99e895d9702f", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import SQLAlchemy" - ] - }, - { - "cell_type": "markdown", - "id": "df69fe31-34e2-4d7b-ac42-d402bdeb0121", - "metadata": {}, - "source": [ - "⠀" - ] - }, - { - "cell_type": "markdown", - "id": "42f1a5ab-746f-46a0-b461-e5fd7670f4d5", - "metadata": {}, - "source": [ - "**Configuration**" - ] - }, - { - "cell_type": "markdown", - "id": "c62ac54c-ab0f-4335-ad7f-2f781bd9db8d", - "metadata": {}, - "source": [ - "The [configuration string](introduction.ipynb) for the SQLAlchemy wrapper is an [SQLAlchemy Database URL](https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls). To use the wrapper, just provide such an URL and the `create` argument." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "ec2b9121-09e2-4804-9ec5-b7c3ac90d308", - "metadata": {}, - "outputs": [], - "source": [ - "sqlalchemy = SQLAlchemy('sqlite:///database.db', True)" - ] - }, - { - "cell_type": "markdown", - "id": "3a88d725-3fd6-4ba0-ac15-6540b95a40ea", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "Check the [SQLAlchemy documentation](https://docs.sqlalchemy.org/en/14/core/engines.html#database-urls) to learn how to construct database URLs.\n", - " \n", - "
" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 } diff --git a/docs/usage/wrappers/sqlite.ipynb b/docs/usage/wrappers/sqlite.ipynb index 4ced195..53feb30 100644 --- a/docs/usage/wrappers/sqlite.ipynb +++ b/docs/usage/wrappers/sqlite.ipynb @@ -1,117 +1,117 @@ { - "cells": [ - { - "cell_type": "markdown", - "id": "9cf4e7aa-0b22-408a-a7d4-83b851eac5fa", - "metadata": {}, - "source": [ - "# SQLite\n", - "\n", - "
\n", - "\n", - "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fsqlite.ipynb \"Click to run this tutorial yourself!\")\n", - " \n", - "
" - ] + "cells": [ + { + "cell_type": "markdown", + "id": "9cf4e7aa-0b22-408a-a7d4-83b851eac5fa", + "metadata": {}, + "source": [ + "# SQLite\n", + "\n", + "
\n", + "\n", + "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/simphony/docs/v4.0.0?filepath=docs%2Fusage%2Fwrappers%2Fsqlite.ipynb \"Click to run this tutorial yourself!\")\n", + " \n", + "
" + ] + }, + { + "cell_type": "markdown", + "id": "d014a1f8-e537-4afe-8084-7a4dd0ff9e00", + "metadata": {}, + "source": [ + "| **Capability** \t| **Support** \t|\n", + "|:-----------:\t|:-----------:\t|\n", + "| Persistence \t| \u2713 \t|\n", + "| Files \t| \u2717 \t|\n", + "| Simulation \t| \u2717 \t|\n", + "| Cache \t| \u2717 \t|" + ] + }, + { + "cell_type": "markdown", + "id": "bc186ceb-7aa2-449f-8e9a-2ed642fb7d8f", + "metadata": {}, + "source": [ + "The SQLite wrapper can store ontology individuals using several tables in an SQLite database file. It is actually just a special case of the more feature-rich [SQLAlchemy wrapper](sqlalchemy.ipynb). The SQLite wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.SQLite`." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "69c4415c-db20-48d6-ad4e-b5d9c22a47bc", + "metadata": {}, + "outputs": [], + "source": [ + "from simphony_osp.wrappers import SQLite" + ] + }, + { + "cell_type": "markdown", + "id": "a3bfb046-5ed1-4233-ae73-d34c761309c5", + "metadata": {}, + "source": [ + "\u2800" + ] + }, + { + "cell_type": "markdown", + "id": "df7e30b1-27a6-41e9-bff7-4a816cf6166e", + "metadata": {}, + "source": [ + "**Configuration**" + ] + }, + { + "cell_type": "markdown", + "id": "ae96af5e-6646-44cb-b942-02b3b8d15fa2", + "metadata": {}, + "source": [ + "The [configuration string](introduction.ipynb) for the SQLite wrapper is the path to the database file to be used. To use the wrapper, just call it providing the [two arguments that SimPhoNy wrappers require](introduction.ipynb): the configuration string and the `create` argument." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7d2406f2-741a-4ab7-84e2-add188732537", + "metadata": {}, + "outputs": [], + "source": [ + "sqlite = SQLite('database.db', True)" + ] + }, + { + "cell_type": "markdown", + "id": "279c98e7-71d7-4449-a1b7-d0869a2e6c4c", + "metadata": {}, + "source": [ + "
\n", + "
Tip
\n", + " \n", + "Keep in mind that the SQLite wrapper really just calls the [SQLAlchemy wrapper](sqlalchemy.ipynb) adding the suffix `sqlite:///` to the given configuration string.\n", + " \n", + "
" + ] + } + ], + "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.8.12" + } }, - { - "cell_type": "markdown", - "id": "d014a1f8-e537-4afe-8084-7a4dd0ff9e00", - "metadata": {}, - "source": [ - "| **Capability** \t| **Support** \t|\n", - "|:-----------:\t|:-----------:\t|\n", - "| Persistence \t| ✓ \t|\n", - "| Files \t| ✗ \t|\n", - "| Simulation \t| ✗ \t|\n", - "| Cache \t| ✗ \t|" - ] - }, - { - "cell_type": "markdown", - "id": "bc186ceb-7aa2-449f-8e9a-2ed642fb7d8f", - "metadata": {}, - "source": [ - "The SQLite wrapper can store ontology individuals using several tables in an SQLite database file. It is actually just a special case of the more feature-rich [SQLAlchemy wrapper](sqlalchemy.ipynb). The SQLite wrapper is included with SimPhoNy and available under `simphony_osp.wrappers.SQLite`." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "69c4415c-db20-48d6-ad4e-b5d9c22a47bc", - "metadata": {}, - "outputs": [], - "source": [ - "from simphony_osp.wrappers import SQLite" - ] - }, - { - "cell_type": "markdown", - "id": "a3bfb046-5ed1-4233-ae73-d34c761309c5", - "metadata": {}, - "source": [ - "⠀" - ] - }, - { - "cell_type": "markdown", - "id": "df7e30b1-27a6-41e9-bff7-4a816cf6166e", - "metadata": {}, - "source": [ - "**Configuration**" - ] - }, - { - "cell_type": "markdown", - "id": "ae96af5e-6646-44cb-b942-02b3b8d15fa2", - "metadata": {}, - "source": [ - "The [configuration string](introduction.ipynb) for the SQLite wrapper is the path to the database file to be used. To use the wrapper, just call it providing the [two arguments that SimPhoNy wrappers require](introduction.ipynb): the configuration string and the `create` argument." - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "7d2406f2-741a-4ab7-84e2-add188732537", - "metadata": {}, - "outputs": [], - "source": [ - "sqlite = SQLite('database.db', True)" - ] - }, - { - "cell_type": "markdown", - "id": "279c98e7-71d7-4449-a1b7-d0869a2e6c4c", - "metadata": {}, - "source": [ - "
\n", - "
Tip
\n", - " \n", - "Keep in mind that the SQLite wrapper really just calls the [SQLAlchemy wrapper](sqlalchemy.ipynb) adding the suffix `sqlite:///` to the given configuration string.\n", - " \n", - "
" - ] - } - ], - "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.8.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 + "nbformat": 4, + "nbformat_minor": 5 }