Senzing v3 G2Engine Reporting

Reporting

The Senzing engine allows the exporting of entity data in either JSON or CSV format.

exportCSVEntityReport() and exportCSVEntityReport() are not recommended for large systems as it does not scale. It is recommended larger systems implement real-time replication to a data warehouse.

exportCSVEntityReport

exportCSVEntityReport() exports the entire repository content in CSV format.

exportCSVEntityReport() is not recommended for large systems as it does not scale. It is recommended larger systems implement real-time replication to a data warehouse.
g2_engine.exportCSVEntityReport(g2_engine_flags)
Parameters
  • g2_engine_flags: (int [optional]) One or more flags used to determine response document content. Applicable flags are listed here exportCSVEntityReport flags )
Click to expand exportCSVEntityReport() example
Example
#! /usr/bin/env python3

from senzing import G2Engine, G2Exception
import json

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_engine = G2Engine()

fetch_next_response = bytearray()
csv_headers='RESOLVED_ENTITY_ID,RESOLVED_ENTITY_NAME,RELATED_ENTITY_ID,MATCH_LEVEL,MATCH_KEY,IS_DISCLOSED,IS_AMBIGUOUS,DATA_SOURCE,RECORD_ID,JSON_DATA,LAST_SEEN_DT,NAME_DATA,ATTRIBUTE_DATA,IDENTIFIER_DATA,ADDRESS_DATA,PHONE_DATA,RELATIONSHIP_DATA,ENTITY_DATA,OTHER_DATA'

try:
    g2_engine.init("G2Engine", senzing_engine_configuration_json)

    export_handle = g2_engine.exportCSVEntityReport(csv_headers)

    with open('exportCSVEntityReport.csv', 'wb') as export_out:
        while True:
            export_record = g2_engine.fetchNext(export_handle, fetch_next_response)
            if not export_record:
                break
            export_out.write(export_record)

    g2_engine.closeExport(export_handle)
    g2_engine.destroy()

    print('CSV export report complete')

except G2Exception as err:
    print(err)
CSV export report complete

exportJSONEntityReport

exportJSONEntityReport() exports the entire repository content as a JSON document.

exportJSONEntityReport() is not recommended for large systems as it does not scale. It is recommended larger systems implement real-time replication to a data warehouse.
g2_engine.exportJSONEntityReport(g2_engine_flags)

NOTE: This method is not recommended for large systems as it does not scale. It is recommended larger systems implement real-time replication to a data warehouse.

Parameters
  • g2_engine_flags: (int [optional]) One or more flags used to determine response document content. Applicable flags are listed here exportJSONEntityReport flags )
Click to expand exportJSONEntityReport() example
Example
#! /usr/bin/env python3

from senzing import G2Engine, G2Exception
import json

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_engine = G2Engine()

fetch_next_response = bytearray()

try:
    g2_engine.init("G2Engine", senzing_engine_configuration_json)

    export_handle = g2_engine.exportJSONEntityReport()

    with open('exportJSONEntityReport.json', 'wb') as export_out:
        while True:
            export_record = g2_engine.fetchNext(export_handle, fetch_next_response)
            if not export_record:
                break
            export_out.write(export_record)

    g2_engine.closeExport(export_handle)
    g2_engine.destroy()

    print('JSON export report complete')

except G2Exception as err:
    print(err)
JSON export report complete

fetchNext

fetchNext() reads the exportHandle generated by exportCSVEntityReport() or exportJSONEntityReport() to export a row of output containing the entity data for a single entity. Successive calls of fetchNext() will export successive rows of entity data until there is no more.

Parameters
  • export_handle: (int) A long integer from which resolved entity data is read from and exported.
  • response_bytearray: (bytearray) Object to store the output of the method.
Click to expand fetchNext() example
Example
#! /usr/bin/env python3

from senzing import G2Engine, G2Exception
import json

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_engine = G2Engine()

fetch_next_response = bytearray()

try:
    g2_engine.init("G2Engine", senzing_engine_configuration_json)

    export_handle = g2_engine.exportJSONEntityReport()

    g2_engine.fetchNext(export_handle, fetch_next_response)

    g2_engine.closeExport(export_handle)
    g2_engine.destroy()

    print(fetch_next_response.decode())

except G2Exception as err:
    print(err)
Output
{
    "RESOLVED_ENTITY":
    {
        "ENTITY_ID": 1,
        "ENTITY_NAME": "Robert Smith",
        "FEATURES":
        {
            "ADDRESS":
            [
                {
                    "FEAT_DESC": "1515 Adela Lane Las Vegas NV 89111",
                    "LIB_FEAT_ID": 34,
                    "USAGE_TYPE": "HOME",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "1515 Adela Lane Las Vegas NV 89111",
                            "LIB_FEAT_ID": 34
                        },
                        {
                            "FEAT_DESC": "1515 Adela Ln Las Vegas NV 89132",
                            "LIB_FEAT_ID": 76
                        }
                    ]
                },
                {
                    "FEAT_DESC": "123 Main Street, Las Vegas NV 89132",
                    "LIB_FEAT_ID": 3,
                    "USAGE_TYPE": "MAILING",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "123 Main Street, Las Vegas NV 89132",
                            "LIB_FEAT_ID": 3
                        }
                    ]
                }
            ],
            "DOB":
            [
                {
                    "FEAT_DESC": "11/12/1979",
                    "LIB_FEAT_ID": 75,
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "11/12/1979",
                            "LIB_FEAT_ID": 75
                        }
                    ]
                },
                {
                    "FEAT_DESC": "12/11/1978",
                    "LIB_FEAT_ID": 2,
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "12/11/1978",
                            "LIB_FEAT_ID": 2
                        },
                        {
                            "FEAT_DESC": "11/12/1978",
                            "LIB_FEAT_ID": 33
                        }
                    ]
                }
            ],
            "EMAIL":
            [
                {
                    "FEAT_DESC": "[email protected]",
                    "LIB_FEAT_ID": 5,
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "[email protected]",
                            "LIB_FEAT_ID": 5
                        }
                    ]
                }
            ],
            "NAME":
            [
                {
                    "FEAT_DESC": "B Smith",
                    "LIB_FEAT_ID": 74,
                    "USAGE_TYPE": "PRIMARY",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "B Smith",
                            "LIB_FEAT_ID": 74
                        }
                    ]
                },
                {
                    "FEAT_DESC": "Robert Smith",
                    "LIB_FEAT_ID": 1,
                    "USAGE_TYPE": "PRIMARY",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "Robert Smith",
                            "LIB_FEAT_ID": 1
                        },
                        {
                            "FEAT_DESC": "Bob J Smith",
                            "LIB_FEAT_ID": 55
                        },
                        {
                            "FEAT_DESC": "Bob Smith",
                            "LIB_FEAT_ID": 32
                        }
                    ]
                }
            ],
            "PHONE":
            [
                {
                    "FEAT_DESC": "702-919-1300",
                    "LIB_FEAT_ID": 4,
                    "USAGE_TYPE": "HOME",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "702-919-1300",
                            "LIB_FEAT_ID": 4
                        }
                    ]
                },
                {
                    "FEAT_DESC": "702-919-1300",
                    "LIB_FEAT_ID": 4,
                    "USAGE_TYPE": "MOBILE",
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "702-919-1300",
                            "LIB_FEAT_ID": 4
                        }
                    ]
                }
            ],
            "RECORD_TYPE":
            [
                {
                    "FEAT_DESC": "PERSON",
                    "LIB_FEAT_ID": 30,
                    "FEAT_DESC_VALUES":
                    [
                        {
                            "FEAT_DESC": "PERSON",
                            "LIB_FEAT_ID": 30
                        }
                    ]
                }
            ]
        },
        "RECORDS":
        [
            {
                "DATA_SOURCE": "CUSTOMERS",
                "RECORD_ID": "1004",
                "ENTITY_TYPE": "GENERIC",
                "INTERNAL_ID": 4,
                "ENTITY_KEY": "27EB831065949BD567D1E92681CA4ACD8C0FF1AA",
                "ENTITY_DESC": "B Smith",
                "MATCH_KEY": "",
                "MATCH_LEVEL": 0,
                "MATCH_LEVEL_CODE": "",
                "ERRULE_CODE": "",
                "LAST_SEEN_DT": "2022-12-17 01:30:15.453"
            },
            {
                "DATA_SOURCE": "CUSTOMERS",
                "RECORD_ID": "1001",
                "ENTITY_TYPE": "GENERIC",
                "INTERNAL_ID": 1,
                "ENTITY_KEY": "53C913F04DF04CA474389042F731333F92DCD3E7",
                "ENTITY_DESC": "Robert Smith",
                "MATCH_KEY": "+NAME+DOB+PHONE+EMAIL",
                "MATCH_LEVEL": 1,
                "MATCH_LEVEL_CODE": "RESOLVED",
                "ERRULE_CODE": "SF1_SNAME_CFF_CSTAB",
                "LAST_SEEN_DT": "2022-12-17 01:30:15.428"
            },
            {
                "DATA_SOURCE": "CUSTOMERS",
                "RECORD_ID": "1002",
                "ENTITY_TYPE": "GENERIC",
                "INTERNAL_ID": 2,
                "ENTITY_KEY": "E417012A90D71444C2E190FAF313DA88C5E663B9",
                "ENTITY_DESC": "Bob Smith",
                "MATCH_KEY": "+NAME+DOB+ADDRESS",
                "MATCH_LEVEL": 1,
                "MATCH_LEVEL_CODE": "RESOLVED",
                "ERRULE_CODE": "CNAME_CFF_CEXCL",
                "LAST_SEEN_DT": "2022-12-17 01:30:15.435"
            },
            {
                "DATA_SOURCE": "CUSTOMERS",
                "RECORD_ID": "1003",
                "ENTITY_TYPE": "GENERIC",
                "INTERNAL_ID": 3,
                "ENTITY_KEY": "B327B02717D7515EC96319C0A0AD680FE532E27E",
                "ENTITY_DESC": "Bob J Smith",
                "MATCH_KEY": "+NAME+DOB+EMAIL",
                "MATCH_LEVEL": 1,
                "MATCH_LEVEL_CODE": "RESOLVED",
                "ERRULE_CODE": "SF1_PNAME_CSTAB",
                "LAST_SEEN_DT": "2022-12-17 01:30:15.446"
            }
        ]
    },
    "RELATED_ENTITIES":
    [
        {
            "ENTITY_ID": 5,
            "MATCH_LEVEL": 2,
            "MATCH_LEVEL_CODE": "POSSIBLY_SAME",
            "MATCH_KEY": "+NAME+ADDRESS-DOB",
            "ERRULE_CODE": "CNAME_CFF_DEXCL",
            "IS_DISCLOSED": 0,
            "IS_AMBIGUOUS": 0
        },
        {
            "ENTITY_ID": 100002,
            "MATCH_LEVEL": 3,
            "MATCH_LEVEL_CODE": "POSSIBLY_RELATED",
            "MATCH_KEY": "+ADDRESS+SURNAME",
            "ERRULE_CODE": "CFF_SURNAME",
            "IS_DISCLOSED": 0,
            "IS_AMBIGUOUS": 0
        }
    ]
}

closeExport

Parameters
  • export_handle: (int) A long integer from which resolved entity data is read from and exported.
Click to expand closeExport() example
Example
#! /usr/bin/env python3

from senzing import G2Engine, G2Exception
import json

# REPLACE /home/user/your_project with the path to your Senzing project
senzing_engine_configuration_json = '{ "PIPELINE": { "CONFIGPATH": "/home/user/your_project/etc", "SUPPORTPATH": "/home/user/your_project/data", "RESOURCEPATH": "/home/user/your_project/resources" }, "SQL": { "CONNECTION": "sqlite3://na:na@/home/user/your_project/var/sqlite/G2C.db" } }'

g2_engine = G2Engine()

try:
    g2_engine.init("G2Engine", senzing_engine_configuration_json)

    export_handle = g2_engine.exportJSONEntityReport()

    g2_engine.closeExport(export_handle)
    g2_engine.destroy()

except G2Exception as err:
    print(err)