Skip to content

Commit

Permalink
Edit demo notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
nanglo123 committed Sep 16, 2024
1 parent 6bf8b89 commit d47f3fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 44 deletions.
56 changes: 17 additions & 39 deletions notebooks/Add_ontology_subtree_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"source": [
"## Query for the added node\n",
"\n",
"We also query for any relations where the added node is the target of the relation under relation type ```subclass_of```. Children terminology have a directed ```subclass_of``` relation towards the parent term in the ncbitaxonomy. The absence of any relation information where ```ncbitaxon:9871``` is the target node under relation type ```subclass_of``` shows that we only added the node."
"We also query for any relations where the added node is the target of the relation under relation type ```subclass_of```. Children terminology have a directed ```subclass_of``` relation towards the parent term in the ncbitaxonomy. The absence of any relation information where ```ncbitaxon:9871``` is the target node under relation type ```subclass_of``` shows that we only added the node of interest."
]
},
{
Expand Down Expand Up @@ -139,7 +139,7 @@
"id": "8aede484-2e9d-4955-ac5d-ab6149b14edc",
"metadata": {},
"source": [
"## Add the ontology subtree full of terms under the term"
"## Add the ontology subtree full of terms under the specified term"
]
},
{
Expand Down Expand Up @@ -171,7 +171,7 @@
"metadata": {},
"source": [
"## Relationship info has been added\n",
"We now see that there is a plethora of relationship info added where ```ncbitaxon:9871``` is the target node now under relation type ```subclass_of```. The number of relations added under this constraint is 5 because there are 5 direct ncbitaxonomy terms under ```ncbitaxon:9871```. "
"We now see that there are a number of relationship information added where ```ncbitaxon:9871``` is the target node under relation type ```subclass_of``` now. The number of relations added under this constraint is 5 because there are 5 direct ncbitaxonomy terms under ```ncbitaxon:9871```. "
]
},
{
Expand All @@ -194,9 +194,17 @@
"print(f\"The number of relations added to the EPI DKG where the target node has curie 'ncbitaxon:9871' and the relation type is 'subclass_of' is {len(result)}\")"
]
},
{
"cell_type": "markdown",
"id": "a0566fb6-e1b4-4b00-8b1b-b682b8ad60e7",
"metadata": {},
"source": [
"## Show one relation that has been added"
]
},
{
"cell_type": "code",
"execution_count": 137,
"execution_count": 152,
"id": "bb1c69f4-c028-4e2f-9d87-f5da8dfa6803",
"metadata": {},
"outputs": [
Expand All @@ -205,50 +213,20 @@
"output_type": "stream",
"text": [
"Source Node: <Node element_id='3099' labels=frozenset() properties={'xref_types': [''], 'xrefs': ['gc_id:1'], 'name': 'unclassified Odocoileus', 'obsolete': False, 'id': 'ncbitaxon:2625720', 'type': 'class'}>\n",
"\n"
]
},
{
"ename": "AttributeError",
"evalue": "'subclass_of' object has no attribute 'properties'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[137], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSource Node: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m0\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m) \n\u001b[1;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m()\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRelation Type: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m1\u001b[39m]\u001b[38;5;241m.\u001b[39mtype\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[43mresult\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mproperties\u001b[49m\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m()\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mTarget Node: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult[\u001b[38;5;241m0\u001b[39m][\u001b[38;5;241m2\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'subclass_of' object has no attribute 'properties'"
"\n",
"Relation Type: subclass_of, {'pred': 'rdfs:subClassOf', 'source': 'ncbitaxon', 'version': '', 'graph': 'ncbitaxon'}\n",
"\n",
"Target Node: <Node element_id='3098' labels=frozenset() properties={'property_values': ['NCBITaxon:genus'], 'xref_types': [''], 'property_predicates': ['has_rank'], 'obsolete': False, 'xrefs': ['gc_id:1'], 'name': 'Odocoileus', 'id': 'ncbitaxon:9871', 'type': 'class'}>\n"
]
}
],
"source": [
"print(f\"Source Node: {result[0][0]}\") \n",
"print()\n",
"print(f\"Relation Type: {result[0][1].type}, {result[0][1].properties}\")\n",
"print(f\"Relation Type: {result[0][1].type}, {result[0][1]._properties}\")\n",
"print()\n",
"print(f\"Target Node: {result[0][2]}\")"
]
},
{
"cell_type": "code",
"execution_count": 146,
"id": "3d3d71c8-75e9-4f6d-862c-0519808328af",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'subclass_of' object has no attribute 'properties'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[146], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mresult\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mproperties\u001b[49m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'subclass_of' object has no attribute 'properties'"
]
}
],
"source": [
"result[0][1].properties"
]
}
],
"metadata": {
Expand Down
11 changes: 6 additions & 5 deletions notebooks/Extend_DKG_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,25 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 10,
"id": "2c3452bf-5bc3-43ca-9623-e8860fc7e0a5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"200"
"'{\"detail\":[{\"loc\":[\"body\"],\"msg\":\"value is not a valid dict\",\"type\":\"type_error.dict\"}]}'"
]
},
"execution_count": 4,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"response = requests.post(\"http://localhost:8771/api/add_nodes\", json=node_list)\n",
"response.status_code"
"response = requests.post(\"http://localhost:8000/api/relations\", json=node_list)\n",
"response.status_code\n",
"response.text"
]
},
{
Expand Down

0 comments on commit d47f3fe

Please sign in to comment.