Presentation Language
By default, entities and tags of analysis or recommendation are reported in the language of the document or photo.
However, we can request them in other languages as well
(currently, Czech, Dutch, English, French, German, Polish, Portuguese, Slovak, and Spanish are supported)
using the parameter presentationLanguage
with the ISO code of the desired language.
Basic code common for all the guide pages
Basic code
To use the API, you need a valid API key with appropriate authorizations.
Please get in touch with us if you do not have it here.
In the code below, replace <YOUR_API_KEY>
with the API key.
Note that we do not provide SDKs for the API yet, but our G3 SDKs can be used to perform NLP analysis.
- cURL
- cURL (Windows)
- JavaScript
- Python
- Python SDK
No special setup necessary
No special setup necessary
// HTTP client; see https://github.com/axios/axios
const axios = require('axios');
const config = {
baseURL: 'https://media-api.geneea.com/v2/',
headers: {
'X-API-KEY': '<YOUR_API_KEY>'
}
};
// A simple function to report the returned json objects
const report = (output) => console.dir(output, { depth: null });
// In production environment, the API should always be called from the backend,
// otherwise you run into CORS problems
# http client; see https://docs.python-requests.org/en/latest/
import requests
BASE_URL = 'https://media-api.geneea.com/v2/'
HEADERS = {
'content-type': 'application/json',
'X-API-Key': '<YOUR_API_KEY>'
}
## We do not provide a dedicated SDK for the Media API yet.
## However, the SDK for General API can be used for the content analysis (i.e. NLP) part
## Geneea NLP client SDK; see https://help.geneea.com/sdk/index.html
from geneeanlpclient import g3
BASE_URL = 'https://media-api.geneea.com/v2/'
API_KEY = '<YOUR_API_KEY>'
Presentation Language in Article Content Analysis
Below, is an example reporting entities and tags in French.
The code is the same as in this example
except the presentationLanguage
parameter.
- JavaScript
- Python
- Python SDK
const analyze = async (config, input) => {
const response = await axios.post('nlp/analyze', input, config);
return response.data;
};
const input = {
id: '1234',
title: 'Emmanuel Macron in Germany.',
text: 'Mr. Macron visited a trade show in Munich.'
presentationLanguage: 'fr'
}
analyze(config, input).then(report);
def analyze(input):
return requests.post(f'{BASE_URL}nlp/analyze', json=input, headers=HEADERS).json()
input = {
'id': '1234',
'title': 'Emmanuel Macron in Germany.',
'text': 'Mr. Macron visited a trade show in Munich.',
'presentationLanguage': 'fr'
}
analyze(input)
from geneeanlpclient import g3
requestBuilder = g3.Request.Builder(customConfig={'presentationLanguage': 'fr'})
with g3.Client.create(url=f'{BASE_URL}nlp/analyze") as analyzer:
analyzer.session.headers.update({'X-API-Key': API_KEY})
request = requestBuilder.build(id=str('1234'), title='Emmanuel Macron in Germany.', text='Mr. Macron visited a trade show in Munich.')
result = analyzer.analyze(request)
print("Entities:")
for e in result.entities:
print(f' {e.type}: {e.stdForm} ({e.gkbId})')
print("Tags:")
for t in result.tags:
print(f' {t.type}: {t.stdForm} ({t.gkbId}) relevance: {t.relevance}')
produces the following result (see the Analysis reference page for explanation. Note that we have omitted the relations field for simplicity).
- JavaScript
- Python
- Python SDK
{
version: '3.2.1',
id: '1234',
language: { detected: 'en' },
entities: [
{ id: 'e0', gkbId: 'G57305', stdForm: 'salon', type: 'general' },
{ id: 'e1', gkbId: 'G183', stdForm: 'Allemagne', type: 'location' },
{ id: 'e2', gkbId: 'G1726', stdForm: 'Munich', type: 'location' },
{ id: 'e3', gkbId: 'G3052772', stdForm: 'Emmanuel Macron', type: 'person' },
{ id: 'e4', gkbId: 'G183', stdForm: 'Allemagne', type: 'country', feats: {derivedBy: 'gkb2:[gkbp:adminCountry]'} },
{ id: 'e5', gkbId: 'G980', stdForm: 'Bavière', type: 'region', feats: { derivedBy: 'gkb2:[gkbp:region]' } }
],
tags: [
{ id: 't0', gkbId: 'G3052772', stdForm: 'Emmanuel Macron', type: 'media', relevance: 22.605, feats: { wikidataId: 'Q3052772' } },
{ id: 't1', gkbId: 'G183', stdForm: 'Allemagne', type: 'media', relevance: 18.365, feats: { wikidataId: 'Q183' } },
{ id: 't2', gkbId: 'G1726', stdForm: 'Munich', type: 'media', relevance: 7.57, feats: { wikidataId: 'Q1726' } }
],
relations: [..],
docSentiment: { mean: 0.0, label: 'neutral', positive: 0.0, negative: 0.0 },
usedChars: 100
}
{
'version': '3.2.1',
'id': '1234',
'language': { 'detected': 'en' },
'entities': [
{ 'id': 'e0', 'gkbId': 'G57305', 'stdForm': 'salon', 'type': 'general' },
{ 'id': 'e1', 'gkbId': 'G183', 'stdForm': 'Allemagne', 'type': 'location' },
{ 'id': 'e2', 'gkbId': 'G1726', 'stdForm': 'Munich', 'type': 'location' },
{ 'id': 'e3', 'gkbId': 'G3052772', 'stdForm': 'Emmanuel Macron', 'type': 'person' },
{ 'id': 'e4', 'gkbId': 'G183', 'stdForm': 'Allemagne', 'type': 'country', 'feats': {'derivedBy': 'gkb2:[gkbp:adminCountry]'} },
{ 'id': 'e5', 'gkbId': 'G980', 'stdForm': 'Bavière', 'type': 'region', 'feats': { 'derivedBy': 'gkb2:[gkbp:region]' } }
],
'tags': [
{ 'id': 't0', 'gkbId': 'G3052772', 'stdForm': 'Emmanuel Macron', 'type': 'media', 'relevance': 22.605, 'feats': { 'wikidataId': 'Q3052772' } },
{ 'id': 't1', 'gkbId': 'G183', 'stdForm': 'Allemagne', 'type': 'media', 'relevance': 18.365, 'feats': { 'wikidataId': 'Q183' } },
{ 'id': 't2', 'gkbId': 'G1726', 'stdForm': 'Munich', 'type': 'media', 'relevance': 7.57, 'feats': { 'wikidataId': 'Q1726' } }
],
'relations': [..],
'docSentiment': { 'mean': 0.0, 'label': 'neutral', 'positive': 0.0, 'negative': 0.0 },
'usedChars': 100
}
Entities:
general: salon (G57305)
location: Allemagne (G183)
location: Munich (G1726)
person: Emmanuel Macron (G3052772)
country: Allemagne (G183)
region: Bavière (G980)
Tags:
media: Emmanuel Macron (G3052772) relevance: 22.605
media: Allemagne (G183) relevance: 18.365
media: Munich (G1726) relevance: 7.57
Presentation Language in Photo Recommendation
Documentation coming soon.
Multiple Presentation Languages
Sometimes more than one presentation language is needed. Obviously, we could perform repeated analyses or recommendations, each with one of the desired presentation language. However, it is typically faster to perform one analysis/recommendation and then ask the knowledgebase for translation of entities and tags to other languages.
For example, the following code, translates two tags (e.g., from a
Photo Recommendations
) to Polish:
- JavaScript
- Python
const kbStdForms = async (input, config) => {
const response = await axios.post("knowledgebase/stdforms", input, config);
return response.data;
};
input = {
ids: ["G458", "G567"],
language: "pl",
};
kbStdForms(input, config).then(report);
def kbStdForms(input: Mapping[str, Any]):
return requests.post(f'{BASE_URL}knowledgebase/stdforms', json=input, headers=HEADERS).json()
input = {
'ids': ['G458', 'G567'],
'language': 'pl',
};
kbStdForms(input)
kbStdForms(input, config).then(report);
- JavaScript
- Python
{
G458: { value: 'Unia Europejska', language: 'pl' },
G567: { value: 'Angela Merkel', language: 'pl' }
}
{
'G458': {'value': 'Unia Europejska', 'language': 'pl'},
'G567': {'value': 'Angela Merkel', 'language': 'pl'}
}