Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

docs(cookbook): make notebook 07 setup deterministic

taoche3ed31b9182c4
diff --git a/cookbook/introduction/07_Building_Knowledge_Graphs.ipynb b/cookbook/introduction/07_Building_Knowledge_Graphs.ipynb
index 74d0aeaa..4c4930b1 100644
--- a/cookbook/introduction/07_Building_Knowledge_Graphs.ipynb
+++ b/cookbook/introduction/07_Building_Knowledge_Graphs.ipynb
@@ -42,7 +42,18 @@
"cell_type": "code",
"metadata": {},
"source": [
- "!pip install semantica\n"
+ "%pip install semantica\n",
+ "\n",
+ "# spaCy models are distributed separately from the spaCy library. This lesson\n",
+ "# relies on the English model to recognize standalone places such as Cupertino.\n",
+ "import sys\n",
+ "import subprocess\n",
+ "import spacy\n",
+ "\n",
+ "try:\n",
+ " spacy.load(\"en_core_web_sm\")\n",
+ "except OSError:\n",
+ " subprocess.check_call([sys.executable, \"-m\", \"spacy\", \"download\", \"en_core_web_sm\"])\n"
],
"execution_count": null,
"outputs": []
@@ -176,6 +187,13 @@
" target = canonical_id[relationship[\"target\"]]\n",
" print(f\" {resolved_names[source]} --{relationship['type']}--> {resolved_names[target]}\")\n",
"\n",
+ "canonical_entities = {(entity[\"name\"], entity[\"type\"]) for entity in resolved_entities}\n",
+ "assert canonical_entities == {\n",
+ " (\"Apple Inc.\", \"ORG\"),\n",
+ " (\"Tim Cook\", \"PERSON\"),\n",
+ " (\"Cupertino\", \"GPE\"),\n",
+ " (\"California\", \"GPE\"),\n",
+ "}\n",
"assert len(resolved_entities) == 4"
],
"execution_count": null,