<jupyter_start><jupyter_text>G2Engine Guide - Export configurationThe `exportConfig()` method creates a string with information about the Senzing engine's configuration.More information:* [G2Engine Reference](senzing-G2Engine-reference.ipynb)  Prepare Environment<jupyter_code>import com.senzing.g2.engine.G2Engine;
import com.senzing.g2.engine.G2JNI;
import com.senzing.g2.engine.Result;<jupyter_output><empty_output><jupyter_text>Helper class for Json Rendering<jupyter_code>%%loadFromPOM
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
</dependency>
import javax.json.*;
import static java.util.Collections.*;
import static javax.json.stream.JsonGenerator.PRETTY_PRINTING;
public class JsonUtil {
    private static final JsonWriterFactory PRETTY_FACTORY
        = Json.createWriterFactory(singletonMap(PRETTY_PRINTING, true));
        
    private static final JsonWriterFactory UGLY_FACTORY
        = Json.createWriterFactory(emptyMap());
    
    public static String toJsonText(JsonValue val) {
        return toJsonText(val, true);
    }

    public static String toJsonText(JsonValue val, boolean prettyPrint) {
        JsonWriterFactory factory = (prettyPrint) ? PRETTY_FACTORY : UGLY_FACTORY;
        StringWriter sw = new StringWriter();
        JsonWriter writer = factory.createWriter(sw);
        writer.write(val);
        sw.flush();
        return sw.toString();
    }
    
    public static JsonObject parseJsonObject(String jsonText) {
        if (jsonText == null) return null;
        StringReader sr = new StringReader(jsonText);
        JsonReader jsonReader = Json.createReader(sr);
        return jsonReader.readObject();
  }

    public static JsonArray parseJsonArray(String jsonText) {
        if (jsonText == null) return null;
        StringReader sr = new StringReader(jsonText);
        JsonReader jsonReader = Json.createReader(sr);
        return jsonReader.readArray();
  }
    
    
}
import java.util.UUID;
public static void RenderJSON(String str){
    JsonObject json = JsonUtil.parseJsonObject(str);
    String Config = JsonUtil.toJsonText(json, false);
    UUID id = UUID.randomUUID();
    String uuid = id.toString();
    String div = "<div id=\""+ uuid +"\" style=\"height:100%; width:100%; background-color: LightCyan\"></div>";
    display(div, "text/html");
    String jav = "require([\"https://rawgit.com/caldwell/renderjson/master/renderjson.js\"], function() {document.getElementById(\'"+ uuid +"\').appendChild(renderjson("+json+"))});";
    display(jav, "application/javascript");
}<jupyter_output><empty_output><jupyter_text>Initialize Senzing configurationUsing environment variables and default values, create `senzingConfigJson`.This value is used when instantiating Senzing objects.<jupyter_code>// Get variables used in constructing Senzing Engine configuration.
String senzingConfigJson=System.getenv("SENZING_ENGINE_CONFIGURATION_JSON");

String configPath = System.getenv("SENZING_ETC_DIR");
if (configPath == null) {
    configPath = "/etc/opt/senzing";
}

String supportPath = System.getenv("SENZING_DATA_VERSION_DIR");
if (supportPath == null) {
    supportPath = "/opt/senzing/data";
}

String g2Path = System.getenv("SENZING_G2_DIR");
if (g2Path == null) {
    g2Path = "/opt/senzing/g2";
}

String resourcePath = g2Path + "/resources";

String sqlConnection = System.getenv("SENZING_SQL_CONNECTION");
if (sqlConnection == null) {
    sqlConnection = "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db";
}

    // Construct the JSON string used for Senzing Engine configuration.
if(senzingConfigJson==null)
    senzingConfigJson = "{"
       + "\"PIPELINE\": {"
       +     "\"CONFIGPATH\": \"" + configPath + "\","
       +     "\"SUPPORTPATH\": \"" + supportPath + "\","
       +     "\"RESOURCEPATH\": \"" + resourcePath + "\""
       + "},"
       + "\"SQL\": {"
       +     "\"CONNECTION\": \"" + sqlConnection + "\""
       + "}}";

RenderJSON(senzingConfigJson);<jupyter_output><empty_output><jupyter_text>G2Engine  G2Engine initializationTo start using Senzing G2Engine, create and initialize an instance.This should be done once per process.The `initV2()` method accepts the following parameters:- **moduleName:** A short name given to this instance of the G2Engine  object.- **senzingConfigJson:** A JSON string containing configuration parameters.- **verboseLogging:** A boolean which enables diagnostic logging.- **configID:** (optional) The identifier value for the engine configuration  can be returned here.Calling this function will return "0" upon success.<jupyter_code>G2Engine g2engine = new G2JNI();

String moduleName = "ExampleG2Engine";
boolean verboseLogging = true;
int return_code = g2engine.initV2(moduleName, senzingConfigJson, verboseLogging);
System.out.print(return_code);<jupyter_output><empty_output><jupyter_text>exportConfigCall `exportConfig()` to retrieve your Senzing engine's configuration.The call will assign a JSON document to a user-designated buffer,containing all relevant configuration information-- the function itself will return "0" upon success.The exportConfig function accepts the following parameters as input:- **response:** The memory buffer to retrieve the JSON  configuration document- **configID:** The identifier value for the engine configuration  can be returned here.<jupyter_code>StringBuffer response = new StringBuffer();
Result<Long> configID = new Result<Long>();

g2engine.exportConfig(response, configID);
System.out.println("Config ID: "+configID.getValue());
System.out.println(response);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12017777777777777, 'fraction_numerical': 0.006933333333333333, 'mean_word_length': 4.5813492063492065, 'pattern_counts': {'":': 6, '<': 33, '<?xml version=': 0, '>': 33, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '407877', 'license': 'Apache-2.0', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1618, 'n_words': 409, 'path': 'notebooks/senzing-examples/java/senzing-G2Engine-exportConfig.ipynb', 'repo_name': 'Senzing/docker-jupyter', 'size': '5625'}