G2Command is a command line shell for interacting with, exploring and familiarizing yourself with the G2 APIs, without having to write any code.
Although shipped with Senzing, G2Command is not supported for production use. We provide it to expedite API and G2 familiarity and support it on an ad hoc basis. Ad hoc meaning we enhance G2Command (and welcome suggestions) yet it might be slightly trailing the core C API features and functions and isn't guaranteed to always be fully up to date.
Launching G2Command
- cd /opt/senzing/g2/python
- python G2Command.py
Helping Hand
Once initialized type help to get a brief overview of available commands and help topics.
Each command further expands with help <command> and/or <command> -h
To display the help topics use help <topic_item>
Tab completion is available for all of the commands. Don't type searchByAttributes, type se then hit TAB to autocomplete it.
Simple operating system shell access is available from within G2Command by prefixing an OS shell command with ! from within G2Command. For example, using ls to show the contents of /opt/senzing/g2/python/demo/sample.
Purging the Entity Repository
If you have data you'd like to keep and are using the default and embedded SQLite database see Backup & Restore SQLite Repository. If you're using another RDBMS follow the vendors backup and restore procedures. You could also temporarily point your G2 deployment to the default SQLite database to use it as a sandbox.
To purge the current entity repository use purgeRepository
Adding a Record
To add a single record use addRecord. Lets use the first record from the sample_person.json file using ! <linux shell command> to first display the record.
Now using copy and paste you can use this record in the addRecord API call. Note, this first call may appear a little slow as the engine and database resources are initialised, subsequent calls will be much faster.
You've loaded 1 single data source record into Senzing and created a single entity.
Retrieving the Loaded Record
To retrieve the previously - or other loaded records - is accomplished with the getRecord call specifying the data source code and it's RECORD_ID.
getRecord returns a JSON response message detailing the attributes sent and loaded for the associated record. getRecord only returns information pertaining to a single record.
Retrieving the Entity For a Record
To retrieve the entity the record created or merged with using the RECORD_ID is accomplished with the getEntityByRecordID call. The following output has been truncated for brevity.
The getEntityByRecordID returns a JSON response message detailing everything about the entity the record loaded with RECORD_ID = 1001 belongs to. In this example only this single record has been loaded and there is only one entity in the system currently representing this single record.
Note the first key value pair in the response message is "ENTITY_ID":1. This is the unique identifier assigned to the entity the RECORD_ID = 1001 created and belongs to.
Retrieving an Entity by ENTITY_ID
There will be situations where you are working with entity data and you know the ENTITY_ID of the entity of interest and you'd like to retrieve everything about that entity. In this case use getEntityByEntityID.
Just as when using the getEntityByRecordID call, a response message is returned detailing the ENTITY_ID = 1, which the RECORD_ID = 1001 belongs to.
Searching Entities by Attributes
A frequent operation against the entity repository is search - you are interested in locating any entities that match some criteria, even when not exact. To search the entity repository for matching entities searchByAttributes is used.
The search parameters are specified in the same fashion as attributes are mapped for ingestion. An article detailing searching and attribute use in searches will be coming in the near future.
Deleting a Record
To delete a single previously loaded record use deleteRecord. This only deletes the single identified record. If the record was a member of an entity with multiple sources records resolved to it the other records and entity remain.
Replacing a Record
When a record changes in one your source systems replaceRecord is used to replace the existing record, if the record does not exist it is added.
After deleting the previous record, it can be added again with replaceRecord...
...and after being added replaced with data changes/updates.
In addition to tinkering with and exploring G2Command yourself, check out the following resources:
- docs.senzing.com
- docs.senzing.com/python_file.html
- /opt/senzing/g2/sdk/ directory in your deployment
- Interpreting Entity API Response Messages
Comments
0 comments
Please sign in to leave a comment.