Skip to content

Commit

Permalink
Documentation of dot notation to change the value of attributes (#110)
Browse files Browse the repository at this point in the history
* Modified a few sentences and examples to make it clear that attribute values can be modified using the dot notation.

* Remark: `uid`, `iri` and `oclass` cannot be modified.

Authored-by: kysrpex <[email protected]>
Authored-by: José Manuel Domínguez <[email protected]>
  • Loading branch information
create-issue-branch[bot] authored Apr 6, 2021
1 parent 56972bb commit 9a1cd89
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions docs/source/jupyter/cuds-api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"\n",
"- `iri`: The [Internationalized Resource Identifier](https://fusion.cs.uni-jena.de/fusion/blog/2016/11/18/iri-uri-url-urn-and-their-differences/) of the CUDS object. It consists of a CUDS namespace prefix and the unique ID of the CUDS object. This will be further clarified in the tutorial.\n",
"\n",
"- **attributes**: The values of the ontology attributes of an individual (also known as [data properties](https://www.w3.org/TR/owl2-syntax/#Data_Properties) in [OWL](https://en.wikipedia.org/wiki/Web_Ontology_Language)) may also be accessed as python properties of the CUDS objects. For example: `cuds_object.name`.\n",
"- **attributes**: The values of the ontology attributes of an individual (also known as [data properties](https://www.w3.org/TR/owl2-syntax/#Data_Properties) in [OWL](https://en.wikipedia.org/wiki/Web_Ontology_Language)) may also be accessed and modified as python properties of the CUDS objects. For example: `cuds_object.name = \"Bob\"`.\n",
"\n",
"There are some advanced functionalities NOT covered in this tutorial. Among them, we highlight the `update` method, which is covered in the [wrapper tutorial](multiple-wrappers.ipynb), where it can be seen in action. For a complete list of available methods and properties, check the API reference. That whole set of methods and attributes constitutes the CUDS [API](https://en.wikipedia.org/wiki/API).\n",
"\n",
Expand Down Expand Up @@ -94,11 +94,11 @@
"name": "stdout",
"output_type": "stream",
"text": [
"INFO 2021-03-30 14:35:45,372 [osp.core.ontology.installation]: Will install the following namespaces: ['city']\n",
"INFO 2021-03-30 14:35:45,392 [osp.core.ontology.yml.yml_parser]: Parsing YAML ontology file /home/jose/.local/lib/python3.9/site-packages/osp/core/ontology/docs/city.ontology.yml\n",
"INFO 2021-03-30 14:35:45,431 [osp.core.ontology.yml.yml_parser]: You can now use `from osp.core.namespaces import city`.\n",
"INFO 2021-03-30 14:35:45,431 [osp.core.ontology.parser]: Loaded 202 ontology triples in total\n",
"INFO 2021-03-30 14:35:45,450 [osp.core.ontology.installation]: Installation successful\n"
"INFO 2021-04-01 13:40:41,433 [osp.core.ontology.installation]: Will install the following namespaces: ['city']\n",
"INFO 2021-04-01 13:40:41,448 [osp.core.ontology.yml.yml_parser]: Parsing YAML ontology file /home/jose/.local/lib/python3.9/site-packages/osp/core/ontology/docs/city.ontology.yml\n",
"INFO 2021-04-01 13:40:41,476 [osp.core.ontology.yml.yml_parser]: You can now use `from osp.core.namespaces import city`.\n",
"INFO 2021-04-01 13:40:41,476 [osp.core.ontology.parser]: Loaded 202 ontology triples in total\n",
"INFO 2021-04-01 13:40:41,491 [osp.core.ontology.installation]: Installation successful\n"
]
}
],
Expand Down Expand Up @@ -181,9 +181,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"uid of c: 039579cc-ce24-4a74-be89-e24adad58205\n",
"uid of p1: 3b35ca2b-d245-4e49-928d-f3da0c894989\n",
"uid of p2: a2e9b4c8-aab5-4354-94d8-b9b9374f1663\n"
"uid of c: e0b721ae-6004-4834-80f1-e6e979952d1f\n",
"uid of p1: 63874785-0de6-43ad-8669-999482501ad1\n",
"uid of p2: 39c7334f-ef62-4dbc-ae2e-390d7f3ca641\n"
]
}
],
Expand Down Expand Up @@ -222,9 +222,9 @@
"name": "stdout",
"output_type": "stream",
"text": [
"IRI of c: http://www.osp-core.com/cuds#039579cc-ce24-4a74-be89-e24adad58205\n",
"IRI of p1: http://www.osp-core.com/cuds#3b35ca2b-d245-4e49-928d-f3da0c894989\n",
"IRI of p2: http://www.osp-core.com/cuds#a2e9b4c8-aab5-4354-94d8-b9b9374f1663\n"
"IRI of c: http://www.osp-core.com/cuds#e0b721ae-6004-4834-80f1-e6e979952d1f\n",
"IRI of p1: http://www.osp-core.com/cuds#63874785-0de6-43ad-8669-999482501ad1\n",
"IRI of p2: http://www.osp-core.com/cuds#39c7334f-ef62-4dbc-ae2e-390d7f3ca641\n"
]
}
],
Expand Down Expand Up @@ -264,6 +264,13 @@
"print(\"oclass of p2: \" + str(p2.oclass))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `uid`, `iri` and `oclass` properties **cannot be modified**."
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -274,7 +281,7 @@
}
},
"source": [
"Finally, the values of the ontology attributes of an individual can be easily accessed using the dot notation."
"Finally, the values of the ontology attributes of an individual can be easily **accessed and modified** using the dot notation."
]
},
{
Expand All @@ -295,14 +302,21 @@
"text": [
"Name of c: Freiburg. Coordinates of c: [47 7].\n",
"Name of p1: Peter\n",
"Name of p2: Anne\n"
"Name of p2: Anne\n",
"\n",
"Change the name of Peter.\n",
"Name of p1: Bob.\n"
]
}
],
"source": [
"print(f\"Name of c: {c.name}. Coordinates of c: {c.coordinates}.\" )\n",
"print(\"Name of p1: \" + str(p1.name))\n",
"print(\"Name of p2: \" + str(p2.name))"
"print(\"Name of p2: \" + str(p2.name))\n",
"\n",
"print(f\"\\nChange the name of {p1.name}.\")\n",
"p1.name = \"Bob\"\n",
"print(f\"Name of p1: {p1.name}.\")"
]
},
{
Expand Down Expand Up @@ -333,7 +347,7 @@
{
"data": {
"text/plain": [
"<city.Citizen: a2e9b4c8-aab5-4354-94d8-b9b9374f1663, CoreSession: @0x7f8ac96867f0>"
"<city.Citizen: 39c7334f-ef62-4dbc-ae2e-390d7f3ca641, CoreSession: @0x7f3a5778ef70>"
]
},
"execution_count": 8,
Expand Down Expand Up @@ -371,8 +385,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"uid: 3b35ca2b-d245-4e49-928d-f3da0c894989\n",
"uid: a2e9b4c8-aab5-4354-94d8-b9b9374f1663\n"
"uid: 63874785-0de6-43ad-8669-999482501ad1\n",
"uid: 39c7334f-ef62-4dbc-ae2e-390d7f3ca641\n"
]
}
],
Expand All @@ -399,7 +413,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"city.Citizen: 3b35ca2b-d245-4e49-928d-f3da0c894989\n",
"city.Citizen: 63874785-0de6-43ad-8669-999482501ad1\n",
"None\n"
]
}
Expand Down Expand Up @@ -427,7 +441,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[<city.Citizen: 3b35ca2b-d245-4e49-928d-f3da0c894989, CoreSession: @0x7f8ac96867f0>, <city.Citizen: a2e9b4c8-aab5-4354-94d8-b9b9374f1663, CoreSession: @0x7f8ac96867f0>]\n"
"[<city.Citizen: 63874785-0de6-43ad-8669-999482501ad1, CoreSession: @0x7f3a5778ef70>, <city.Citizen: 39c7334f-ef62-4dbc-ae2e-390d7f3ca641, CoreSession: @0x7f3a5778ef70>]\n"
]
}
],
Expand All @@ -451,7 +465,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"city.Citizen: 3b35ca2b-d245-4e49-928d-f3da0c894989\n",
"city.Citizen: 63874785-0de6-43ad-8669-999482501ad1\n",
"None\n"
]
}
Expand Down Expand Up @@ -550,7 +564,7 @@
"output_type": "stream",
"text": [
"- Cuds object named <Freiburg>:\n",
" uuid: 039579cc-ce24-4a74-be89-e24adad58205\n",
" uuid: e0b721ae-6004-4834-80f1-e6e979952d1f\n",
" type: city.City\n",
" superclasses: city.City, city.GeographicalPlace, city.PopulatedPlace, cuba.Entity\n",
" values: coordinates: [47 7]\n",
Expand All @@ -559,26 +573,26 @@
"\n",
" |_Relationship city.hasInhabitant:\n",
" | - city.Citizen cuds object named <Anne>:\n",
" | uuid: a2e9b4c8-aab5-4354-94d8-b9b9374f1663\n",
" | uuid: 39c7334f-ef62-4dbc-ae2e-390d7f3ca641\n",
" | age: 25\n",
" |_Relationship city.hasPart:\n",
" - city.Neighborhood cuds object named <neighborhood 0>:\n",
" . uuid: 87ae7cd8-be6d-488f-98f1-9b86775ec2d1\n",
" . uuid: 79eec4f9-55c5-464d-b6c3-dc4382e55476\n",
" . coordinates: [0 0]\n",
" - city.Neighborhood cuds object named <neighborhood 1>:\n",
" . uuid: ec36bad9-a394-4ae8-a6c3-4402cef8b54f\n",
" . uuid: 50fa8dac-2f5f-4b2c-ab8a-24f7f1b41f2c\n",
" . coordinates: [0 0]\n",
" - city.Neighborhood cuds object named <neighborhood 2>:\n",
" . uuid: 7545167d-b53d-4521-9ebb-166acfa8985d\n",
" . uuid: f6c20bfa-c29b-46bb-a5f5-8bc88b3e3621\n",
" . coordinates: [0 0]\n",
" - city.Neighborhood cuds object named <neighborhood 3>:\n",
" . uuid: 2bc52e16-eba4-40fb-b1e6-244bb1dae16c\n",
" . uuid: e161ea1c-40d8-4556-93ad-dfd4d178d669\n",
" . coordinates: [0 0]\n",
" - city.Neighborhood cuds object named <neighborhood 4>:\n",
" . uuid: 0e789051-d1be-444f-83cd-00eb042633a0\n",
" . uuid: a3af8db2-28cd-457b-84ed-b420be5212c2\n",
" . coordinates: [0 0]\n",
" - city.Neighborhood cuds object named <neighborhood 5>:\n",
" uuid: fa54102e-2ede-4761-989a-d2825bffc8ba\n",
" uuid: 8de47383-4416-44be-99dc-e5903b1d14dd\n",
" coordinates: [0 0]\n"
]
}
Expand Down

0 comments on commit 9a1cd89

Please sign in to comment.