From e2a7a785024482dc46ef6d591e74437896ca2eea Mon Sep 17 00:00:00 2001 From: docktermj Date: Fri, 13 Dec 2024 18:03:47 -0500 Subject: [PATCH] #149 Savepoint --- .../notebooks/go/senzing_hello_world.ipynb | 2 +- .../go/senzing_load_truth_sets.ipynb | 143 ++++++++---------- 2 files changed, 64 insertions(+), 81 deletions(-) diff --git a/rootfs/examples/notebooks/go/senzing_hello_world.ipynb b/rootfs/examples/notebooks/go/senzing_hello_world.ipynb index 154b189..da1b94e 100644 --- a/rootfs/examples/notebooks/go/senzing_hello_world.ipynb +++ b/rootfs/examples/notebooks/go/senzing_hello_world.ipynb @@ -135,7 +135,7 @@ " return \"\", err\n", " }\n", " return prettyJSON.String(), nil\n", - "}\n" + "}" ] }, { diff --git a/rootfs/examples/notebooks/go/senzing_load_truth_sets.ipynb b/rootfs/examples/notebooks/go/senzing_load_truth_sets.ipynb index 67da602..468242c 100644 --- a/rootfs/examples/notebooks/go/senzing_load_truth_sets.ipynb +++ b/rootfs/examples/notebooks/go/senzing_load_truth_sets.ipynb @@ -248,6 +248,30 @@ "}" ] }, + { + "cell_type": "markdown", + "id": "dbe8f2d2-4248-40e3-868d-5f2d383d8abc", + "metadata": {}, + "source": [ + "Create a function to pretty print JSON." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e4bbcc6c-7051-4a60-9574-a8214d71cfe7", + "metadata": {}, + "outputs": [], + "source": [ + "func prettyJSON(str string) (string, error) {\n", + " var prettyJSON bytes.Buffer\n", + " if err := json.Indent(&prettyJSON, []byte(str), \"\", \" \"); err != nil {\n", + " return \"\", err\n", + " }\n", + " return prettyJSON.String(), nil\n", + "}" + ] + }, { "cell_type": "markdown", "id": "9ea0deba-8ed6-45e4-85a2-7df083bd724f", @@ -375,8 +399,10 @@ "%%\n", "oldConfigID, err := szConfigManager.GetDefaultConfigID(ctx)\n", "testErr(err)\n", + "\n", "oldJsonConfig, err := szConfigManager.GetConfig(ctx, oldConfigID)\n", "testErr(err)\n", + "\n", "configHandle, err := szConfig.ImportConfig(ctx, oldJsonConfig)\n", "testErr(err)\n", "\n", @@ -393,53 +419,18 @@ "newConfigID, err := szConfigManager.AddConfig(ctx, newJsonConfig, \"Add TruthSet datasources\")\n", "testErr(err)\n", "\n", - "\n", "err = szConfigManager.ReplaceDefaultConfigID(ctx, oldConfigID, newConfigID)\n", "testErr(err)\n", "\n", - "szAbstractFactory.Reinitialize(ctx, newConfigID)\n", - "\n", - "fmt.Printf(\"Old: %d; New: %d\\n\", oldConfigID, newConfigID)\n" + "szAbstractFactory.Reinitialize(ctx, newConfigID)" ] }, - { - "cell_type": "markdown", - "id": "ed24476a-0979-4c6b-9243-d119a7d49f48", - "metadata": {}, - "source": [ - "Add DataSources to Senzing configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "34b8cf1e-ba63-4084-8486-9426cfeecf31", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "3bfd934f-1041-405f-9253-db4096385e39", - "metadata": {}, - "source": [ - "Persist new Senzing configuration." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8beac8c5-3368-4cef-b561-d90b541c3e3a", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "2ffc09e3-dc87-4fc0-9b01-63f3d8885661", "metadata": {}, "source": [ - "With the change in Senzing configuration, Senzing objects need to be updated." + "TODO: Remove after debugging." ] }, { @@ -464,13 +455,7 @@ "dataXX, err := szConfig.GetDataSources(ctx, configHandle)\n", "testErr(err)\n", "\n", - "fmt.Println(dataXX)\n", - "\n", - "\n", - "\n", - "// result, err := szConfig.GetDataSources(ctx, configHandle)\n", - "// testErr(err)\n", - "// fmt.Printf(\">>>> Result: %s\\n\", result)" + "fmt.Println(dataXX)" ] }, { @@ -481,22 +466,6 @@ "## Add records" ] }, - { - "cell_type": "markdown", - "id": "35ed65ef-5607-4807-9c13-3c1c7907bc6a", - "metadata": {}, - "source": [ - "Print help for `sz_engine.add_record()` to see parameters." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "eaa34d6e-0dfe-4af6-b6d7-f0f219ecc7b4", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "3dc91753-7825-4eda-a64b-b1bb2a48f944", @@ -513,7 +482,6 @@ "outputs": [], "source": [ "%%\n", - "\n", "for _, value := range truthSetFileNames {\n", " filepath := fmt.Sprintf(\"%s%s\", homePath, value)\n", " file, err := os.Open(filepath)\n", @@ -525,28 +493,11 @@ " line := scanner.Bytes()\n", " err := json.Unmarshal(line, &jsonRecord) \n", " testErr(err)\n", - " fmt.Printf(\"UID: %s.%s\\n\", jsonRecord.Data_Source, jsonRecord.Record_ID)\n", " result, err := szEngine.AddRecord(ctx, jsonRecord.Data_Source, jsonRecord.Record_ID, string(line), senzing.SzWithInfo)\n", " testErr(err)\n", " fmt.Println(result)\n", " } \n", - "} \n", - "\n", - "// for filename in truth_set_filenames:\n", - "// filepath = home_path + filename\n", - "// with open(filepath, \"r\") as file:\n", - "// for line in file:\n", - "// try:\n", - "// line_as_dict = json.loads(line)\n", - "// info = sz_engine.add_record(\n", - "// line_as_dict.get(\"DATA_SOURCE\"),\n", - "// line_as_dict.get(\"RECORD_ID\"),\n", - "// line,\n", - "// SzEngineFlags.SZ_WITH_INFO,\n", - "// )\n", - "// print(info)\n", - "// except SzError as err:\n", - "// print(err)" + "}" ] }, { @@ -573,7 +524,16 @@ "id": "a1d50a95-6470-4e5f-944d-41e0662f92cf", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "%%\n", + "customer1070Entity, err := szEngine.GetEntityByRecordID(ctx, \"CUSTOMERS\", \"1070\", senzing.SzEntityIncludeRecordSummary)\n", + "testErr(err)\n", + "\n", + "customer1070EntityPretty, err := prettyJSON(customer1070Entity)\n", + "testErr(err)\n", + "\n", + "fmt.Println(customer1070EntityPretty)" + ] }, { "cell_type": "markdown", @@ -589,6 +549,29 @@ "id": "1ff90ba8-7054-42a1-a8b1-133b9dd7f81e", "metadata": {}, "outputs": [], + "source": [ + "%%\n", + "searchProfile := \"\"\n", + "searchQuery := `{\n", + " \"name_full\": \"robert smith\",\n", + " \"date_of_birth\": \"11/12/1978\"\n", + "}`\n", + "\n", + "searchResult, err := szEngine.SearchByAttributes(ctx, searchQuery, searchProfile, senzing.SzSearchByAttributesDefaultFlags)\n", + "testErr(err)\n", + "\n", + "searchResultPretty, err := prettyJSON(searchResult)\n", + "testErr(err)\n", + "\n", + "fmt.Println(searchResultPretty)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f9de192d-6a15-4398-a877-c62868f587cc", + "metadata": {}, + "outputs": [], "source": [] } ],