G2Config Reference

Prepare environment

In [1]:
import os
import sys
import json

# For RenderJSON

import uuid
from IPython.display import display_javascript, display_html, display

Helper class for JSON rendering

A class for pretty-printing JSON. Not required by Senzing, but helps visualize JSON.

In [2]:
class RenderJSON(object):
    def __init__(self, json_data):
        if isinstance(json_data, dict):
            self.json_str = json.dumps(json_data)
        elif isinstance(json_data, bytearray):
            self.json_str = json_data.decode()
        else:
            self.json_str = json_data
        self.uuid = str(uuid.uuid4())

    def _ipython_display_(self):
        display_html('<div id="{}" style="height:100%; width:100%; background-color: LightCyan"></div>'.format(self.uuid), raw=True)
        display_javascript("""
        require(["https://rawgit.com/caldwell/renderjson/master/renderjson.js"], function() {
        document.getElementById('%s').appendChild(renderjson(%s))
        });
        """ % (self.uuid, self.json_str), raw=True)

Initialize variables

Create variables used for G2Config.

In [3]:
%run senzing-init-config.ipynb
Stored 'senzing_config_json' (str)
Default config already set
Stored 'config_id_bytearray' (bytearray)
In [4]:
%store -r senzing_config_json
In [5]:
RenderJSON(senzing_config_json)
In [6]:
python_path = "{0}/python".format(
    os.environ.get("SENZING_G2_DIR", "/opt/senzing/g2"))
sys.path.append(python_path)

G2Config

The G2Config API...

In [7]:
from G2Config import G2Config
import G2Exception

Initialize G2Config

In [8]:
g2_config = G2Config()
try:
    g2_config.initV2(module_name, senzing_config_json, verbose_logging)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Create configuration handle

In [9]:
try:
    config_handle = g2_config.create()
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

save

In [10]:
try:
    response_bytearray = bytearray()
    g2_config.save(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray)

load

In [11]:
try:
    # example using the saved config from the `save()` method
    g2_config.load(response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Datasources

listDataSourcesV2

Call G2Config's listDataSourcesV2() method and pretty-printsresults.

In [12]:
try:
    response_bytearray = bytearray()

    g2_config.listDataSourcesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

RenderJSON(response_bytearray)

addDataSourceV2

Call G2Config's addDataSourceV2() method and pretty-prints results.

In [13]:
try:
    datasource_json = "{\"DSRC_CODE\": \"CUSTOMER\"}" 

    response_bytearray = bytearray()

    g2_config.addDataSourceV2(config_handle, datasource_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

RenderJSON(response_bytearray)

addDataSourceWithID

In [14]:
try:
    datasource_json = "{\"DSRC_CODE\": \"CUSTOMER\"}" 

    response_bytearray = bytearray()
    
    id = 0
    
    g2_config.addDataSourceWithID(config_handle, datasource_json, id)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

listDataSources again

Call G2Config's listDataSourcesV2() method and pretty-prints results. Notice that the list now contains the newly added datasource_code of "CUSTOMER".

In [15]:
try:
    response_bytearray = bytearray()

    g2_config.listDataSourcesV2(config_handle, response_bytearray)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Entities

listEntityClassesV2

Calls G2Config's listEntityClassesV2() method and pretty-prints results.

In [16]:
try:
    response_bytearray = bytearray()

    g2_config.listEntityClassesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listEntityTypesV2

Calls G2Config's listEntityTypesV2() method and pretty-prints results.

In [17]:
try:
    response_bytearray = bytearray()

    g2_config.listEntityTypesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listEntityClasses again

In [18]:
try:
    response_bytearray = bytearray()

    g2_config.listEntityClassesV2(config_handle, response_bytearray)

    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

addEntityTypeV2

In [19]:
try:
    entitytype_json = "{\"ETYPE_CODE\": \"PROFESSIONAL\", \"ECLASS_CODE\": \"ACTOR\"}" 
    response_bytearray = bytearray()

    g2_config.addEntityTypeV2(config_handle, entitytype_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listEntityTypes again

In [20]:
try:
    response_bytearray = bytearray()

    g2_config.listEntityTypesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteEntityTypesV2

In [21]:
try:
    entitytype_json = "{\"ETYPE_CODE\": \"PROFESSIONAL\", \"ECLASS_CODE\": \"ACTOR\"}" 

    g2_config.deleteEntityTypeV2(config_handle, entitytype_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Feature

listFeatureElementsV2

In [22]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureElementsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureElementV2

In [23]:
try:
    response_bytearray = bytearray()
    featureElm_json="{\"FELEM_CODE\":\"GIVEN_NAME\"}"

    g2_config.getFeatureElementV2(config_handle, featureElm_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureElementV2

In [24]:
try:
    response_bytearray = bytearray()
    featureElm_json = "{\"FELEM_CODE\":\"myNewFelem\",\"FELEM_ID\":789,\"TOKENIZE\":1,\"DATA_TYPE\":\"string\"}"

    g2_config.addFeatureElementV2(config_handle, featureElm_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteFeatureElementV2

In [25]:
try:
    featureElm_json = "{\"FELEM_CODE\":\"myNewFelem\"}"
    g2_config.deleteFeatureElementV2(config_handle, featureElm_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

listFeatureClassesV2

In [26]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureClassesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listFeaturesV2

In [27]:
try:
    response_bytearray = bytearray()

    g2_config.listFeaturesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureV2

In [28]:
try:
    response_bytearray = bytearray()
    feature_json =  "{\"FTYPE_CODE\":\"name\"}"
    g2_config.getFeatureV2(config_handle, feature_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureV2

In [29]:
try:
    response_bytearray = bytearray()
    feature_json = "{\"FTYPE_CODE\":\"myNewFtype\",\"FTYPE_ID\":789,\"FCLASS_CODE\":\"ELECTED_ID\",\"FTYPE_FREQ\":\"FF\", \"FEATURE_ELEMENTS\":[{\"FELEM_CODE\":\"expression\"}]}"

    g2_config.addFeatureV2(config_handle, feature_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteFeatureV2

In [30]:
try:
    feature_json = "{\"FTYPE_CODE\":\"NAME\"}"
    g2_config.deleteFeatureV2(config_handle, feature_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

addElementToFeatureV2

In [31]:
try:
    elmnt_json =  "{\"FTYPE_CODE\":\"myNewFtype\", \"FELEM_CODE\":\"expression\",\"EXEC_ORDER\":4}"
    g2_config.addElementToFeatureV2(config_handle, elmnt_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

deleteElementFromFeatureV2

In [32]:
try:
    elmnt_json = "{\"FTYPE_CODE\":\"myNewFtype\", \"FELEM_CODE\":\"expression\"}"
    
    g2_config.deleteElementFromFeatureV2(config_handle, elmnt_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Standardization

listFeatureStandardizationFunctionsV2

In [33]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureStandardizationFunctionsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listFeaturesStandardizationFunctionCallsV2

In [34]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureStandardizationFunctionCallsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureStandardizationFunctionCallV2

In [35]:
try:
    response_bytearray = bytearray()
    featureStandard_json = "{\"SFCALL_ID\":4}"
    g2_config.getFeatureStandardizationFunctionCallV2(config_handle, featureStandard_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureStandardizationFunctionCallV2

In [36]:
try:
    response_bytearray = bytearray()
    featureStandard_json = "{\"FTYPE_CODE\":\"veh_vin\",\"SFCALL_ID\":789,\"SFUNC_CODE\":\"PARSE_ID\",\"EXEC_ORDER\":15}"
    g2_config.addFeatureStandardizationFunctionCallV2(config_handle, featureStandard_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteFeatureStandardizationFunctionCallV2

In [37]:
#Get the json from the previous function
try:
    featureStandard_json = "{\"SFCALL_ID\":789}"
    g2_config.deleteFeatureStandardizationFunctionCallV2(config_handle, featureStandard_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Expression

listFeatureExpressionFunctionsV2

In [38]:
try:
    response_bytearray = bytearray()
    g2_config.listFeatureExpressionFunctionsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listFeatureExpressionFunctionCallsV2

In [39]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureExpressionFunctionCallsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureExpressionFunctionCallV2

In [40]:
try:
    response_bytearray = bytearray()
    featureExpress_json = "{\"EFCALL_ID\":1}"
    g2_config.getFeatureExpressionFunctionCallV2(config_handle, featureExpress_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureExpressionFunctionCallV2

In [41]:
try:
    response_bytearray = bytearray()
    featureExpress_json = "{\"FTYPE_CODE\":\"veh_vin\",\"EFCALL_ID\":789,\"EFUNC_CODE\":\"EXPRESS_ID\",\"EXEC_ORDER\":15, \"BOM_ELEMENTS\":[{\"FTYPE_CODE\":\"veh_vin\",\"FELEM_CODE\":\"id_num\",\"REQUIRED\":\"Yes\"}]}"
    g2_config.addFeatureExpressionFunctionCallV2(config_handle, featureExpress_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureExpressionFunctionCallElementV2

In [42]:
try:
    featureExpressElm_json = "{\"EFCALL_ID\":789, \"FTYPE_CODE\":\"address\",\"FELEM_CODE\":\"addr5\",\"REQUIRED\":\"Yes\"}"
    g2_config.addFeatureExpressionFunctionCallElementV2(config_handle, featureExpressElm_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

deleteFeatureExpressionFunctionCallElementV2

In [43]:
try:
    featureExpressElm_json = "{\"EFCALL_ID\":789, \"FTYPE_CODE\":\"ADDRESS\",\"FELEM_CODE\":\"ADDR5\"}"
    g2_config.deleteFeatureExpressionFunctionCallElementV2(config_handle, featureExpressElm_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

deleteFeatureExpressionFunctionCallV2

In [44]:
#Get the json from the previous function
try:
    featureExpress_json = "{\"EFCALL_ID\":789}"
    g2_config.deleteFeatureExpressionFunctionCallV2(config_handle, featureExpress_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Comparison

listFeatureComparisonFunctionsV2

In [45]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureComparisonFunctionsV2(config_handle, response_bytearray)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listFeatureComparisonFunctionCallsV2

In [46]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureComparisonFunctionCallsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureComparisonFunctionCallV2

In [47]:
try:
    response_bytearray = bytearray()
    featureCompFunc_json = "{\"CFCALL_ID\":2}"
    g2_config.getFeatureComparisonFunctionCallV2(config_handle, featureCompFunc_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureComparisonFunctionCallV2

In [48]:
try:
    response_bytearray = bytearray()
    featureCompFunc_json = "{\"FTYPE_CODE\":\"name_key\",\"CFCALL_ID\":789,\"CFUNC_CODE\":\"ID_COMP\",\"EXEC_ORDER\":15, \"BOM_ELEMENTS\":[{\"FELEM_CODE\":\"expression\"}]}"
    g2_config.addFeatureComparisonFunctionCallV2(config_handle, featureCompFunc_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteFeatureComparisonFunctionCallV2

In [49]:
#Get input_json from previous function
try:
    featureComp_json = "{\"CFCALL_ID\":789}"
    g2_config.deleteFeatureComparisonFunctionCallV2(config_handle, featureComp_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

addFeatureComparsionFunctionCallElementV2

In [50]:
try:
    featureCompElm_json =  "{\"CFCALL_ID\":5, \"FELEM_CODE\":\"addr6\"}"
    g2_config.addFeatureComparisonFunctionCallElementV2(config_handle, featureCompElm_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

deleteFeatureComparsionFunctionCallElementV2

In [51]:
try:
    featureCompElm_json =  "{\"CFCALL_ID\":5, \"FELEM_CODE\":\"ADDR4\"}"
    g2_config.deleteFeatureComparisonFunctionCallElementV2(config_handle, featureCompElm_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Distinct

listFeatureDistinctFunctionsV2

In [52]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureDistinctFunctionsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listFeatureDistinctFunctionCallsV2

In [53]:
try:
    response_bytearray = bytearray()

    g2_config.listFeatureDistinctFunctionCallsV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getFeatureDistinctFunctionCallV2

In [54]:
try:
    response_bytearray = bytearray()
    featureFunc_json =  "{\"DFCALL_ID\":2}"
    g2_config.getFeatureDistinctFunctionCallV2(config_handle, featureFunc_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addFeatureDistinctFunctionCallV2

In [55]:
try:
    response_bytearray = bytearray()
    featureFunc_json = "{\"FTYPE_CODE\":\"name_key\",\"DFCALL_ID\":789,\"DFUNC_CODE\":\"FELEM_STRICT_SUBSET\",\"EXEC_ORDER\":15, \"BOM_ELEMENTS\":[{\"FELEM_CODE\":\"expression\"}]}"
    g2_config.addFeatureDistinctFunctionCallV2(config_handle, featureFunc_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteFeatureDistinctFunctionCallV2

In [56]:
try:
    featureFunc_json = "{\"DFCALL_ID\":1002}"
    g2_config.deleteFeatureDistinctFunctionCallV2(config_handle, featureFunc_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

addFeatureDistinctFunctionCallElementV2

In [57]:
try:
    featureElmt_json = "{\"DFCALL_ID\":5, \"FELEM_CODE\":\"addr6\"}"
    g2_config.addFeatureDistinctFunctionCallElementV2(config_handle, featureElmt_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

deleteFeatureDistinctFunctionCallElementV2

In [58]:
try:
    featureElmt_json = "{\"DFCALL_ID\":5, \"FELEM_CODE\":\"ADDR4\"}"
    g2_config.deleteFeatureDistinctFunctionCallElementV2(config_handle, featureElmt_json)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Attributes

listAttributeClassesV2

In [59]:
try:
    response_bytearray = bytearray()

    g2_config.listAttributeClassesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

listAttributesV2

In [60]:
try:
    response_bytearray = bytearray()

    g2_config.listAttributesV2(config_handle, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

getAttributeV2

In [61]:
try:
    response_bytearray = bytearray()
    input_json = "{\"ATTR_CODE\":\"DATA_SOURCE\"}"
    g2_config.getAttributeV2(config_handle, input_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

addAttributeV2

In [62]:
try:
    response_bytearray = bytearray()
    attr_json = "{\"ATTR_CODE\":\"myNewAttr\",\"ATTR_ID\":789,\"ATTR_CLASS\":\"attribute\",\"FTYPE_CODE\":\"name_key\",\"FELEM_CODE\":\"latitude\",\"FELEM_REQ\":\"myReqValue\",\"DEFAULT_VALUE\":\"myDefault\",\"ADVANCED\":\"Y\",\"INTERNAL\":1}"
    g2_config.addAttributeV2(config_handle, attr_json, response_bytearray)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())
    
RenderJSON(response_bytearray.decode())

deleteAttributeV2

In [63]:
try:
    input_json = "{\"ATTR_CODE\":\"NAME_FIRST\"}"
    g2_config.deleteAttributeV2(config_handle, input_json)
    
except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

Cleanup

getLastException

In [64]:
print(g2_config.getLastException())

clearLastException

In [65]:
try:
    g2_config.clearLastException()

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

close

In [66]:
try:
    g2_config.close(config_handle)

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())

destroy

In [67]:
try:
    g2_config.destroy()

except G2Exception.G2ModuleGenericException as err:
    print(g2_config.getLastException())