Skip to content

Commit

Permalink
commit hashing notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
TShapinsky committed May 9, 2024
1 parent 867c2e8 commit 66eeb9f
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 additions & 0 deletions notebooks/hashing.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from rdflib import Graph, Namespace\n",
"import time\n",
"from buildingmotif.namespaces import BRICK, A\n",
"from buildingmotif.utils import approximate_graph_hash\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"g = Graph().parse('../tests/unit/fixtures/smallOffice_brick.ttl')\n",
"MODEL = Namespace(\"urn:model#\")\n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ttl serialize time: 0.02885890007019043\n",
"n3 serialize time: 0.02724599838256836\n",
"xml serialize time: 0.009903907775878906\n",
"nt serialize time: 0.0031800270080566406\n",
"trig serialize time: 0.0222320556640625\n",
"json-ld serialize time: 0.01989889144897461\n",
"hext serialize time: 0.0049059391021728516\n"
]
}
],
"source": [
"begin = time.time()\n",
"g.serialize(format=\"ttl\")\n",
"end = time.time()\n",
"print(f\"ttl serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"n3\")\n",
"end = time.time()\n",
"print(f\"n3 serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"xml\")\n",
"end = time.time()\n",
"print(f\"xml serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"nt\")\n",
"end = time.time()\n",
"print(f\"nt serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"trig\")\n",
"end = time.time()\n",
"print(f\"trig serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"json-ld\")\n",
"end = time.time()\n",
"print(f\"json-ld serialize time: {end - begin}\")\n",
"\n",
"begin = time.time()\n",
"g.serialize(format=\"hext\")\n",
"end = time.time()\n",
"print(f\"hext serialize time: {end - begin}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"6727799026531355694\n",
"-4781114786451684549\n",
"5257158006352705709\n"
]
}
],
"source": [
"g.add((MODEL[\"a\"], A, BRICK[\"AHU\"]))\n",
"g.serialize('before.nt', format='nt')\n",
"# print(hash(g.serialize(format='nt')))\n",
"print(approximate_graph_hash(g))\n",
"triple = (MODEL[\"b\"], A, BRICK[\"Sensor\"])\n",
"g.add(triple)\n",
"# g.serialize('after.nt', format='nt')\n",
"# print(hash(g.serialize(format='nt')))\n",
"print(approximate_graph_hash(g))\n",
"g.remove(triple)\n",
"g.serialize('before_after.nt', format='nt')\n",
"# print(hash(g.serialize(format='nt')))\n",
"print(approximate_graph_hash(g))\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"triple = (MODEL[\"b\"], A, BRICK[\"Sensor\"])\n",
"g.add((MODEL[\"a\"], A, BRICK[\"AHU\"]))\n",
"before = approximate_graph_hash(g)\n",
"while True:\n",
" g.add(triple)\n",
" approximate_graph_hash(g)\n",
" g.remove(triple)\n",
" assert before == approximate_graph_hash(g)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 66eeb9f

Please sign in to comment.