Presentation Language
By default, entities and tags returned from analysis or recommendation are provided in the language of the input document or photo.
However, you can request that they be returned in a different language,
by using the presentationLanguage parameter.
Currently supported values include the ISO codes for:
- Czech (
cs) - Dutch (
nl) - English (
en) - French (
fr) - German (
de) - Polish (
pl) - Portuguese (
pt) - Slovak (
sk) - Spanish (
ex)
Basic code common to all guide pages
Basic Code
To use the API, you'll need a valid API key with the appropriate permissions. If you don't have one, please contact us here.
In the code below, replace <YOUR_API_KEY> with your actual API key.
Note: We do not currently provide dedicated SDKs for this API, 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 of the Media API.
# Geneea NLP client SDK; see https://help.geneea.com/sdk/index.html
# Use `pip install geneea-nlp-client`
from geneeanlpclient import g3
BASE_URL = 'https://media-api.geneea.com/v2/'
API_KEY = '<YOUR_API_KEY>'
Presentation Language in Article Content Analysis
The following example demonstrates how to request entities and tags in French, regardless of the input language.
This example is the same as the one in the Quickstart, with the addition
of 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}')
This produces the following result: (See the Analysis reference
for a detailed explanation of each field. The relations field is omitted here for brevity.)
- 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
In cases where you need the output in multiple presentation languages, you have two options:
- Repeat the analysis/recommendation with a different
presentationLanguagevalue each time. - Translate entities or tags after the initial analysis using the Knowledge Base API, which is generally more efficient.
Example: Translating tags to Polish
Let's assume you've already received tags (e.g., from Photo Recommendation), and you want their names in Polish.
Use the Knowledge Base stdforms endpoint to get the translated standard forms:
- 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)
Example output
- 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'}
}