Skip to content

Commit

Permalink
#43 Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
docktermj committed Apr 26, 2024
1 parent d35ef15 commit 0457924
Show file tree
Hide file tree
Showing 29 changed files with 556 additions and 5 deletions.
21 changes: 21 additions & 0 deletions examples/szengine/add_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env python3

from typing import Any, Dict

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
data_source_code = "TEST"
record_id = "1"
record_definition: Dict[Any, Any] = {}
flags = SzEngineFlags.SZ_WITH_INFO

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.add_record(data_source_code, record_id, record_definition, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
15 changes: 15 additions & 0 deletions examples/szengine/count_redo_records.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzError, szengine_grpc

GRPC_URL = "localhost:8261"

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.count_redo_records()
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
18 changes: 18 additions & 0 deletions examples/szengine/delete_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
data_source_code = "TEST"
record_id = "1"
flags = SzEngineFlags.SZ_WITH_INFO

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.delete_record(data_source_code, record_id, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
24 changes: 24 additions & 0 deletions examples/szengine/export_csv_fetch_close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
csv_column_list = "RESOLVED_ENTITY_ID,RESOLVED_ENTITY_NAME,RELATED_ENTITY_ID,MATCH_LEVEL,MATCH_KEY,IS_DISCLOSED,IS_AMBIGUOUS,DATA_SOURCE,RECORD_ID,JSON_DATA"
flags = SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
export_handle = sz_engine.export_csv_entity_report(csv_column_list, flags)
RESULT = ""
while True:
fragment = sz_engine.fetch_next(export_handle)
if len(fragment) == 0:
break
RESULT += fragment
sz_engine.close_export(export_handle)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
23 changes: 23 additions & 0 deletions examples/szengine/export_json_fetch_close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
flags = SzEngineFlags.SZ_EXPORT_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
export_handle = sz_engine.export_json_entity_report(flags)
RESULT = ""
while True:
fragment = sz_engine.fetch_next(export_handle)
if len(fragment) == 0:
break
RESULT += fragment
sz_engine.close_export(export_handle)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
27 changes: 27 additions & 0 deletions examples/szengine/find_network_by_entity_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
entity_list = {
"ENTITIES": [
{"ENTITY_ID": 1},
{"ENTITY_ID": 2},
]
}
max_degrees = 2
build_out_degree = 1
max_entities = 10
flags = SzEngineFlags.SZ_FIND_NETWORK_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.find_network_by_entity_id(
entity_list, max_degrees, build_out_degree, max_entities, flags
)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
27 changes: 27 additions & 0 deletions examples/szengine/find_network_by_record_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
record_list = {
"RECORDS": [
{"DATA_SOURCE": "CUSTOMERS", "RECORD_ID": "1001"},
{"DATA_SOURCE": "CUSTOMERS", "RECORD_ID": "1002"},
]
}
max_degrees = 2
build_out_degree = 1
max_entities = 10
flags = SzEngineFlags.SZ_FIND_NETWORK_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.find_network_by_record_id(
record_list, max_degrees, build_out_degree, max_entities, flags
)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
28 changes: 28 additions & 0 deletions examples/szengine/find_path_by_entity_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
start_entity_id = 1
end_entity_id = 2
max_degrees = 2
exclusions = {}
required_data_sources = {}
flags = SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.find_path_by_entity_id(
start_entity_id,
end_entity_id,
max_degrees,
exclusions,
required_data_sources,
flags,
)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
32 changes: 32 additions & 0 deletions examples/szengine/find_path_by_record_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
start_data_source_code = "CUSTOMERS"
start_record_id = "1001"
end_data_source_code = "CUSTOMERS"
end_record_id = "1002"
max_degrees = 2
exclusions = {}
required_data_sources = {}
flags = SzEngineFlags.SZ_FIND_PATH_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.find_path_by_record_id(
start_data_source_code,
start_record_id,
end_data_source_code,
end_record_id,
max_degrees,
exclusions,
required_data_sources,
flags,
)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
15 changes: 15 additions & 0 deletions examples/szengine/get_active_config_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzError, szengine_grpc

GRPC_URL = "localhost:8261"

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_active_config_id()
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
17 changes: 17 additions & 0 deletions examples/szengine/get_entity_by_entity_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
entity_id = 1
flags = SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_entity_by_entity_id(entity_id, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
18 changes: 18 additions & 0 deletions examples/szengine/get_entity_by_record_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
data_source_code = "CUSTOMERS"
record_id = "1001"
flags = SzEngineFlags.SZ_ENTITY_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_entity_by_record_id(data_source_code, record_id, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
18 changes: 18 additions & 0 deletions examples/szengine/get_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
data_source_code = "CUSTOMERS"
record_id = "1001"
flags = SzEngineFlags.SZ_RECORD_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_record(data_source_code, record_id, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
15 changes: 15 additions & 0 deletions examples/szengine/get_redo_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzError, szengine_grpc

GRPC_URL = "localhost:8261"

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_redo_record()
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
15 changes: 15 additions & 0 deletions examples/szengine/get_repository_last_modified_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzError, szengine_grpc

GRPC_URL = "localhost:8261"

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_repository_last_modified_time()
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
15 changes: 15 additions & 0 deletions examples/szengine/get_stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzError, szengine_grpc

GRPC_URL = "localhost:8261"

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_stats()
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
22 changes: 22 additions & 0 deletions examples/szengine/get_virtual_entity_by_record_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
record_list = {
"RECORDS": [
{"DATA_SOURCE": "CUSTOMERS", "RECORD_ID": "1001"},
{"DATA_SOURCE": "CUSTOMERS", "RECORD_ID": "1002"},
]
}
flags = SzEngineFlags.SZ_VIRTUAL_ENTITY_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.get_virtual_entity_by_record_id(record_list, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
17 changes: 17 additions & 0 deletions examples/szengine/how_entity_by_entity_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env python3

import grpc

from senzing_grpc import SzEngineFlags, SzError, szengine_grpc

GRPC_URL = "localhost:8261"
entity_id = 1
flags = SzEngineFlags.SZ_HOW_ENTITY_DEFAULT_FLAGS

try:
grpc_channel = grpc.insecure_channel(GRPC_URL)
sz_engine = szengine_grpc.SzEngineGrpc(grpc_channel=grpc_channel)
RESULT = sz_engine.how_entity_by_entity_id(entity_id, flags)
print(RESULT)
except SzError as err:
print(f"\nError:\n{err}\n")
Loading

0 comments on commit 0457924

Please sign in to comment.