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

Initialization

from gig-python import Server as GIG_Server
from gig-python import Entity

server = GIG_Server("http://localhost:9000/")

API Functions

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.

entity = server.get("Sri Lanka")

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.

entities = server.search("sri lanka", attributes_list=["title"])

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.

results = server.normalize_name("sri lanka")

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

results = server.normalize_location("colombo")

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.

entities = server.get_links("Person A")

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.

entities = server.get_relations("Sri Lanka")

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.

entity = Entity()
entity.title = "LDF Test Entity"
result = server.add(entity)
entity = Entity()
entity.title = "LDF Batch"
result = server.add_all([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.

entity = Entity()
entity.title = "LDF Test Entity"
entity.source_date = "2021-01-02T15:04:05-07:00"
entity.source = "python-lib"
result = server.terminate(entity)

References

  1. https://pypi.org/project/gig-python/

Tech Enthusiast, Critical Thinker