Skip to content

Commit

Permalink
#149 Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Dec 13, 2024
1 parent 4ee1d6b commit e2a7a78
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 81 deletions.
2 changes: 1 addition & 1 deletion rootfs/examples/notebooks/go/senzing_hello_world.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
" return \"\", err\n",
" }\n",
" return prettyJSON.String(), nil\n",
"}\n"
"}"
]
},
{
Expand Down
143 changes: 63 additions & 80 deletions rootfs/examples/notebooks/go/senzing_load_truth_sets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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."
]
},
{
Expand All @@ -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)"
]
},
{
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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)"
"}"
]
},
{
Expand All @@ -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",
Expand All @@ -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": []
}
],
Expand Down

0 comments on commit e2a7a78

Please sign in to comment.