Python

The examples below show how to call the General API from Python 3. Calling other API functions is similar - all you need to do is change the URL. Expected inputs and outputs are described in G3 API Reference. However, you might consider using our Python SDK.

Basic Calls

Executing this code:

import requests

def callGeneea(input):
    url = 'https://api.geneea.com/v3/analysis'
    headers = {
        'content-type': 'application/json',
        'Authorization': 'user_key <your user key>'
    }
    return requests.post(url, json=input, headers=headers).json()

print(callGeneea({'text': 'The pizza in London was great!'}))

produces the following results (see the Response reference page for explanation):

{
    'language': {'detected': 'en'},
    'entities': [{'id': 'E0', 'gkbId': 'hash_dc386592', 'stdForm': 'London', 'type': 'location'}],
    'tags': [
        {'id': 'T0', 'stdForm': 'London', 'type': 'ENTITIES', 'relevance': 1.0},
        {'id': 'T1', 'stdForm': 'pizza', 'type': 'KEYWORDS', 'relevance': 0.462},
        {'id': 'T2', 'stdForm': 'great', 'type': 'KEYWORDS', 'relevance': 0.284}
    ],
    'relations': [
        {
            'id': 'R0',
            'name': 'great',
            'textRepr': 'great(pizza)',
            'type': 'ATTR',
            'args': [{'type': 'SUBJECT', 'name': 'pizza'}],
            'feats': {'negated': 'false', 'modality': ''}
        }
    ],
    'docSentiment': {'mean': 0.6, 'label': 'positive', 'positive': 0.6, 'negative': 0.0},
    'usedChars': 100
}

You can restrict the type of analyses. For example, requesting only entities (see Request for a list of all possible analyses values) will produce the following simpler result:

print(callGeneea({'text': 'The pizza in London was great!', 'analyses': ['entities']}))
{'language': {'detected': 'en'}, 'entities': [{'id': 'E0', 'gkbId': 'hash_dc386592', 'stdForm': 'London', 'type': 'location'}], 'usedChars': 100}

Linking to the Geneea Knowledge Base

We can also use the media domain to have entities linked to Geneea Knowledge Base (at this moment, only media domains link locations):

print(callGeneea({'text': 'The pizza in London was great!', 'analyses': ['entities'], 'domain': 'media'}))
{'language': {'detected': 'en'}, 'entities': [{'id': 'E0', 'gkbId': 'G84', 'stdForm': 'London', 'type': 'location'}], 'usedChars': 100}

We can use the media endpoint to query the Geneea Knowledge Base (note that in addition to your user key, you will also need to provide a X-Customer-ID to do this):

import requests

def callGkb(id):
    url = f'https://api.geneea.com/media/items/{id}'
    headers = {
        'Accept': 'application/json',
        'X-Customer-ID': '<your customer id>',
        'Authorization': 'user_key <your key>'
    }
    return requests.get(url, headers=headers).json()

print(callGkb('G84'))
{
    'id': 'G84',
    'hrid': 'London (G84)',
    'descriptions': [
        {'text': 'capital of England and the United Kingdom', 'language': 'en'},
        {'text': 'hlavní město Anglie a Spojeného království', 'language': 'cs'}],
    ...
}