\n",
"
\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",
"
\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",
"
\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({