<jupyter_start><jupyter_text>Add DataSourceThe `addDataSource()` method adds a datasource to the list of accepted datasources.  Prepare environment  Initialize python environment<jupyter_code>import os
import sys
import json

# For RenderJSON

import uuid
from IPython.display import display_javascript, display_html, display<jupyter_output><empty_output><jupyter_text>Helper class for JSON renderingA class for pretty-printing JSON.Not required by Senzing, but helps visualize JSON.<jupyter_code>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)<jupyter_output><empty_output><jupyter_text>System pathUpdate system path.<jupyter_code>python_path = "{0}/python".format(
    os.environ.get("SENZING_G2_DIR", "/opt/senzing/g2"))
sys.path.append(python_path)<jupyter_output><empty_output><jupyter_text>Initialize variablesCreate variables used for G2Engine.<jupyter_code>%run senzing-init-config.ipynb
%store -r senzing_config_json
%store -r config_id_bytearray
config_id=config_id_bytearray.decode()
RenderJSON(senzing_config_json)<jupyter_output><empty_output><jupyter_text>G2ConfigThe G2Config API...<jupyter_code>from senzing import G2Config, G2Exception<jupyter_output><empty_output><jupyter_text>InitializationTo start using Senzing G2Engine, create and initialize an instance.This should be done once per process.The `init()` method accepts the following parameters:- **module_name:** A short name given to this instance of the G2 engine (i.e. your G2Module object)- **g2module_ini_pathname:** A fully qualified path to the G2 engine INI file (often /opt/senzing/g2/python/G2Module.ini)- **verbose_logging:** A boolean which enables diagnostic logging - this will print a massive amount of information to stdout (default = False)Calling this function will return "0" upon success.<jupyter_code>try:
    g2_config = G2Config()
    g2_config.init(module_name, senzing_config_json, verbose_logging)

except G2Exception as err:
    print(g2_config.getLastException())<jupyter_output><empty_output><jupyter_text>Create configuration handle<jupyter_code>config_handle = g2_config.create()<jupyter_output><empty_output><jupyter_text>listDataSources()Call G2Config's `listDataSources()` method and pretty-print results.<jupyter_code>response_bytearray = bytearray()

try:
    g2_config.listDataSources(config_handle, response_bytearray)

except G2Exception as err:
    print(g2_config.getLastException())
RenderJSON(response_bytearray)<jupyter_output><empty_output><jupyter_text>addDataSource()Call G2Config's `addDataSource()` method and pretty-print results.<jupyter_code>try:
    datasource = {
        "DSRC_CODE": "CUSTOMER"
    }
    datasource_json = json.dumps(datasource)
    response_bytearray = bytearray()

    g2_config.addDataSource(config_handle, datasource_json, response_bytearray)

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

RenderJSON(response_bytearray)<jupyter_output><empty_output><jupyter_text>listDataSources() againCall G2Config's `listDataSources()` method and pretty-print results.Notice that the list now contains the newly added datasource_code of "CUSTOMER".<jupyter_code>response_bytearray = bytearray()

try:
    g2_config.listDataSources(config_handle, response_bytearray)

except G2Exception as err:
    print(g2_config.getLastException())
RenderJSON(response_bytearray)<jupyter_output><empty_output><jupyter_text>Close configuration handle<jupyter_code>g2_config.close(config_handle)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10155688622754491, 'fraction_numerical': 0.010059880239520959, 'mean_word_length': 6.326315789473684, 'pattern_counts': {'":': 1, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '569040', 'license': 'Apache-2.0', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1302, 'n_words': 267, 'path': 'notebooks/senzing-addDataSource.ipynb', 'repo_name': 'Senzing/poc-notebook', 'size': '4175'}