In my previous article, I briefly introduced GIG and its architecture. As explained there, GIG is written in Golang with a focus on optimizing the performance of the core system. To make things much easier for the developers, we have also developed a python library that enables Python developers to integrate GIG API into their code seamlessly.

You can use the following oneliner to install the gig-python package to your python project.

Installation

pip install gig-python

Prerequisites

The Python package is only a wrapper to the GIG Server which is originally built using Golang. You require a running GIG server to interface with the Python library. Check https://github.com/LDFLK/GIG for more information on how to initiate a GIG server locally. Also having some data populated using the crawlers might come in handy when testing the functions we are explaining below.

Initialization

Once you have the GIG server up and running use the following code snippet to import and initiate the server connection. Change the server URL accordingly.

API Functions

Next will see how we can use the functionality of our Python package. The library provides a rich set of functions to interface with the GIG server easily.

Let's say you need to get all the details available regarding an entity from the server. The following code snippet shows how to retrieve an entity using the library. Please note the entity name must be an exact match.

As said above the entity name to get the details should be an exact match. To find the existing entities from the server, you can use the search function to retrieve matching entity results using the code sample given below. The search keyword doesn’t have to be an exact match. our search algorithm is capable of finding the most relevant results from the database.

Also, if you decide to write your own crawlers to populate the GIG server database, you can tap into the normalization service to get the proper entity names if they exist. GIG API always rechecks for normalized title names before saving them into the server. Therefore it is optional for you to check before sending an entity to be saved in the server.

Similarly, we have a separate endpoint to Normalize location names.

Having all the details from an entity might not be enough. Let's say Person A is connected to Organization B. So Organization B will be linked to Person A. To get any entities linked to Person A, you can use the following code snippet. This will return a list of entities linked to the given entity.

Similarly, you can get the reverse of the links using the following function. To get a list of other entities which refer to a given entity, use the following code.

You can use add and add_all functions to add new entities to the server. This function will look if an entity with the same name already exists and modify the entity with new data. Otherwise, it creates a new entity.

Use the following code snippet to notify the system that a certain entity ceases to exist from a specific data. The source date is considered the end date of the entity.

References

  1. https://github.com/LDFLK/gig-python
  2. https://pypi.org/project/gig-python/

Tech Enthusiast, Critical Thinker