From 13ad11c2c7bb5750f13522a121ba7f9df4864d32 Mon Sep 17 00:00:00 2001 From: docktermj Date: Fri, 27 Sep 2024 14:27:07 -0400 Subject: [PATCH] #85 Savepoint --- rootfs/etc/supervisord.conf | 2 +- rootfs/notebooks/hello_world.ipynb | 90 ++++++++++++++++++++++-- rootfs/notebooks/load_truthsets.ipynb | 60 ++++++++++++---- src/senzing_quickstart/hello_world.py | 27 ++++++- src/senzing_quickstart/load_truthsets.py | 29 ++++++-- src/senzing_quickstart/method_help.py | 12 +++- 6 files changed, 192 insertions(+), 28 deletions(-) diff --git a/rootfs/etc/supervisord.conf b/rootfs/etc/supervisord.conf index c90e553..fe06c46 100644 --- a/rootfs/etc/supervisord.conf +++ b/rootfs/etc/supervisord.conf @@ -157,7 +157,7 @@ stdout_logfile_maxbytes=0 stderr_logfile_maxbytes=0 [program:jupyter-lab] -command = jupyter lab --allow-root +command = jupyter lab --allow-root --NotebookApp.token='' directory = /notebooks stderr_logfile = /dev/stderr stdout_logfile = /dev/stdout diff --git a/rootfs/notebooks/hello_world.ipynb b/rootfs/notebooks/hello_world.ipynb index 0d22928..3fc412b 100644 --- a/rootfs/notebooks/hello_world.ipynb +++ b/rootfs/notebooks/hello_world.ipynb @@ -10,9 +10,17 @@ "The following is a quick test of connectivity to Senzing using Python over gRPC.\n" ] }, + { + "cell_type": "markdown", + "id": "06b6ced9-6728-496b-b037-e5740fb5b99c", + "metadata": {}, + "source": [ + "Import python packages." + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "68ee0170-b9bf-4552-b218-497cc46a3dbd", "metadata": {}, "outputs": [], @@ -20,12 +28,84 @@ "import json\n", "\n", "import grpc\n", - "from senzing_grpc import SzAbstractFactory\n", - "\n", + "from senzing_grpc import SzAbstractFactory" + ] + }, + { + "cell_type": "markdown", + "id": "563342b8-10f2-4eef-a887-21e6471076a5", + "metadata": {}, + "source": [ + "Create an abstract factory for accessing Senzing via gRPC." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "79b07536-ec75-4288-b5e7-22427f510c5b", + "metadata": {}, + "outputs": [], + "source": [ "sz_abstract_factory = SzAbstractFactory(\n", " grpc_channel=grpc.insecure_channel(\"localhost:8261\")\n", - ")\n", - "sz_product = sz_abstract_factory.create_sz_product()\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "b1b455d7-7d09-4c64-bdfe-abada6d72d1c", + "metadata": {}, + "source": [ + "Create a Senzing object." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "be478e8e-a16c-4c05-9f01-7bda4025d953", + "metadata": {}, + "outputs": [], + "source": [ + "sz_product = sz_abstract_factory.create_sz_product()" + ] + }, + { + "cell_type": "markdown", + "id": "0b832dd8-02fb-46a7-9556-b42bd7fafb34", + "metadata": {}, + "source": [ + "Use Senzing object." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "02e3e512-4492-4d52-8bd3-1bc8f08b8a97", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\n", + " \"PRODUCT_NAME\": \"Senzing API\",\n", + " \"VERSION\": \"4.0.0\",\n", + " \"BUILD_VERSION\": \"4.0.0.24237\",\n", + " \"BUILD_DATE\": \"2024-08-24\",\n", + " \"BUILD_NUMBER\": \"2024_08_24__08_53\",\n", + " \"COMPATIBILITY_VERSION\": {\n", + " \"CONFIG_VERSION\": \"11\"\n", + " },\n", + " \"SCHEMA_VERSION\": {\n", + " \"ENGINE_SCHEMA_VERSION\": \"4.0\",\n", + " \"MINIMUM_REQUIRED_SCHEMA_VERSION\": \"4.0\",\n", + " \"MAXIMUM_REQUIRED_SCHEMA_VERSION\": \"4.99\"\n", + " }\n", + "}\n" + ] + } + ], + "source": [ "print(json.dumps(json.loads(sz_product.get_version()), indent=2))" ] } diff --git a/rootfs/notebooks/load_truthsets.ipynb b/rootfs/notebooks/load_truthsets.ipynb index cd5e592..6842d5d 100644 --- a/rootfs/notebooks/load_truthsets.ipynb +++ b/rootfs/notebooks/load_truthsets.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "de03a1c2-d7b1-40a9-8154-1df47cd49fef", "metadata": {}, "outputs": [], @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "ff9189d1-852d-46b0-9e2e-36f524c9038e", "metadata": {}, "outputs": [], @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "04555a6e-9c48-4a9b-b8b0-e7285b602fc8", "metadata": {}, "outputs": [], @@ -109,10 +109,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "7f5cecdf-649a-4a8b-ad64-d2fc3f37166d", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found the following DATA_SOURCE values in the data: ['CUSTOMERS', 'REFERENCE', 'WATCHLIST']\n" + ] + } + ], "source": [ "datasources = []\n", "\n", @@ -142,15 +150,35 @@ "id": "7df1865e-38e5-416a-835b-b326b4eaf7a5", "metadata": {}, "source": [ - "Create Senzing objects." + "Create an abstract factory for accessing Senzing via gRPC." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "3272f76c-dc95-4ff8-b573-8bddd55fb779", "metadata": {}, "outputs": [], + "source": [ + "sz_abstract_factory = SzAbstractFactory(\n", + " grpc_channel=grpc.insecure_channel(\"localhost:8261\")\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "60c3824c-e3ac-4445-ac71-338361890405", + "metadata": {}, + "source": [ + "Create Senzing objects." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "301ce7eb-9069-4c8d-a1c4-ebe8f78d1bf6", + "metadata": {}, + "outputs": [], "source": [ "sz_abstract_factory = SzAbstractFactory(\n", " grpc_channel=grpc.insecure_channel(\"localhost:8261\")\n", @@ -171,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "fbf17cc3-3273-4097-90a2-f0b9a21674a1", "metadata": {}, "outputs": [], @@ -191,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "97854ac2-ad01-4663-9f6c-4afd816230f9", "metadata": {}, "outputs": [], @@ -213,7 +241,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "32217742-9e09-4778-b7fe-1e23817251ec", "metadata": {}, "outputs": [], @@ -235,7 +263,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "df805089-7a9a-4e4e-b959-c320819e855b", "metadata": {}, "outputs": [], @@ -265,7 +293,15 @@ "execution_count": null, "id": "cb8318ec-cd73-4e43-8349-586c8dd0dbfb", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{\"DATA_SOURCE\":\"CUSTOMERS\",\"RECORD_ID\":\"1001\",\"AFFECTED_ENTITIES\":[],\"INTERESTING_ENTITIES\":{\"ENTITIES\":[]}}\n" + ] + } + ], "source": [ "for filename in truth_set_filenames:\n", " filepath = home_path + filename\n", diff --git a/src/senzing_quickstart/hello_world.py b/src/senzing_quickstart/hello_world.py index 9723ed3..2cf944e 100755 --- a/src/senzing_quickstart/hello_world.py +++ b/src/senzing_quickstart/hello_world.py @@ -2,9 +2,11 @@ # coding: utf-8 # # Senzing Hello World -# +# # The following is a quick test of connectivity to Senzing using Python over gRPC. -# +# + +# Import python packages. # In[ ]: @@ -14,8 +16,29 @@ import grpc from senzing_grpc import SzAbstractFactory + +# Create an abstract factory for accessing Senzing via gRPC. + +# In[ ]: + + sz_abstract_factory = SzAbstractFactory( grpc_channel=grpc.insecure_channel("localhost:8261") ) + + +# Create a Senzing object. + +# In[ ]: + + sz_product = sz_abstract_factory.create_sz_product() + + +# Use Senzing object. + +# In[ ]: + + print(json.dumps(json.loads(sz_product.get_version()), indent=2)) + diff --git a/src/senzing_quickstart/load_truthsets.py b/src/senzing_quickstart/load_truthsets.py index e79dbef..b1994a1 100755 --- a/src/senzing_quickstart/load_truthsets.py +++ b/src/senzing_quickstart/load_truthsets.py @@ -2,9 +2,9 @@ # coding: utf-8 # # Load Senzing truth-sets -# +# # These instructions load the [Senzing truth-sets] into the Senzing engine. -# +# # [Senzing truth-sets]: https://github.com/Senzing/truth-sets # ## Prepare Python enviroment @@ -21,6 +21,7 @@ import requests from senzing_grpc import SzAbstractFactory, SzEngineFlags, SzError + # Set environment specific variables. # In[ ]: @@ -68,10 +69,21 @@ datasources.append(datasource) print(f"Found the following DATA_SOURCE values in the data: {datasources}") + # ## Update Senzing configuration +# Create an abstract factory for accessing Senzing via gRPC. + +# In[ ]: + + +sz_abstract_factory = SzAbstractFactory( + grpc_channel=grpc.insecure_channel("localhost:8261") +) + + # Create Senzing objects. # In[ ]: @@ -93,7 +105,7 @@ old_config_id = sz_configmanager.get_default_config_id() old_json_config = sz_configmanager.get_config(old_config_id) -config_handle = sz_config.import_config(old_json_config) +config_handle = sz_config.import_config(old_json_config) # Add DataSources to Senzing configuration. @@ -114,8 +126,10 @@ new_json_config = sz_config.export_config(config_handle) -new_config_id = sz_configmanager.add_config(new_json_config, "Add TruthSet datasources") -sz_configmanager.replace_default_config_id(old_config_id, new_config_id) +new_config_id = sz_configmanager.add_config( + new_json_config, "Add TruthSet datasources" +) +sz_configmanager.replace_default_config_id(old_config_id, new_config_id) # With the change in Senzing configuration, Senzing objects need to be updated. @@ -138,7 +152,7 @@ filepath = home_path + filename with open(filepath, "r") as file: for line in file: - try: + try: line_as_dict = json.loads(line) info = sz_engine.add_record( line_as_dict.get("DATA_SOURCE"), @@ -148,7 +162,7 @@ ) print(info) except SzError as err: - print(err) + print(err) # ## View results @@ -173,3 +187,4 @@ } search_result = sz_engine.search_by_attributes(json.dumps(search_query)) print(json.dumps(json.loads(search_result), indent=2)) + diff --git a/src/senzing_quickstart/method_help.py b/src/senzing_quickstart/method_help.py index c9bdbb6..49a7e69 100755 --- a/src/senzing_quickstart/method_help.py +++ b/src/senzing_quickstart/method_help.py @@ -9,9 +9,11 @@ import grpc + from senzing_grpc import SzAbstractFactory -# Create Senzing object. + +# Create an abstract factory for accessing Senzing via gRPC. # In[ ]: @@ -19,6 +21,13 @@ sz_abstract_factory = SzAbstractFactory( grpc_channel=grpc.insecure_channel("localhost:8261") ) + + +# Create Senzing object. + +# In[ ]: + + sz_engine = sz_abstract_factory.create_sz_engine() @@ -36,3 +45,4 @@ print(sz_engine.help("get_entity_by_record_id")) +