Relations
We distinguish three types of relations:
- Attribute relations – e.g., good in a good pizza or the pizza is good expressis an attribute of pizza.
- Verbal relations – e.g., eat in John ate a pizza represents a relation between John and pizza.
- Parent relations – e.g., beer is an alcoholic drink, which is a type of drink. (Note: This type of relation is available only to some accounts and generally requires access to the Geneea Knowledge Base.)
See the Relation object reference for more information.
Sample Call
You can easily try it yourself:
- cURL
- Python SDK
- plain Python
curl -X POST https://api.geneea.com/v3/analysis \
-H 'Authorization: user_key <YOUR USER KEY>' \
-H 'Content-Type: application/json' \
-d '{
"id": "1",
"text": "The trip to London was amazing. But I would not recommend the food. Especially the pizza was terrible.",
"analyses": ["relations"],
"domain": "voc-hospitality"
}'
## On Windows, use \" instead of " and " instead of '
from geneeanlpclient import g3
from typing import Optional
requestBuilder = g3.Request.Builder(
analyses=[g3.AnalysisType.ENTITIES, g3.AnalysisType.RELATIONS],
domain='voc-hospitality',
)
def argStr(arg: Optional[g3.Relation.Argument]) -> Optional[str]:
""" Print relation subject/object including entity reference, if any """
if arg:
if arg.entity:
return f'{arg.name} ({arg.entity.gkbId} {arg.entity.stdForm})'
else:
return f'{arg.name}'
with g3.Client.create(userKey=GENEEA_API_KEY) as analyzer:
result = analyzer.analyze(requestBuilder.build(
id=str(1),
text='The trip to London was amazing. But I would not recommend the food. Especially the pizza was terrible.'
))
for r in result.relations:
if r.type == g3.Relation.TYPE_ATTR.upper():
print(f'{r.type} {argStr(r.subject())}: {r.name}')
else:
print(f'{r.type} name={r.name} ')
print(f' {r.textRepr}')
print(f' subj={argStr(r.subject())}')
print(f' obj={argStr(r.object())}')
print(f' negated={r.isNegated} modality={r.modality}')
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()
responseObj = callGeneea({
'id': '1',
'text': 'The trip to London was amazing. But I would not recommend the food. Especially the pizza was terrible.',
'analyses': ['relations'],
'domain': 'voc-hospitality'
})
print(responseObj)
You should get the following response:
- cURL
- Python SDK
- plain Python
{
"version": "3.2.1",
"id": "1",
"language": {"detected": "en"},
"entities": [
{"id": "e0", "gkbId": "HSP-10210", "stdForm": "food", "type": "food"},
{"id": "e1", "gkbId": "HSP-1091", "stdForm": "pizza", "type": "food"}
],
"relations": [
{
"id": "r0", "name": "amazing", "textRepr": "amazing(trip)", "type": "ATTR",
"args": [{"type": "SUBJECT", "name": "trip"}],
"feats": {"negated": "false", "modality": ""}
},
{
"id": "r1", "name": "recommend", "textRepr": "would recommend-not(i,food)", "type": "VERB",
"args": [{"type": "SUBJECT", "name": "i"}, {"type": "OBJECT", "name": "food", "entityId": "e0"}],
"feats": {"negated": "true", "modality": "would"}
},
{
"id": "r2", "name": "terrible", "textRepr": "terrible(pizza)", "type": "ATTR",
"args": [{"type": "SUBJECT", "name": "pizza", "entityId": "e1"}],
"feats": {"negated": "false", "modality": ""}
}
],
"usedChars": 102
}
ATTR trip: amazing
negated=False modality=
VERB name=recommend
would recommend-not(i,food)
subj=i
obj=food (HSP-10210 food)
negated=True modality=would
ATTR pizza (HSP-1091 pizza): terrible
negated=False modality=
{
"version": "3.2.1",
"id": "1",
"language": {"detected": "en"},
"entities": [
{"id": "e0", "gkbId": "HSP-10210", "stdForm": "food", "type": "food"},
{"id": "e1", "gkbId": "HSP-1091", "stdForm": "pizza", "type": "food"}
],
"relations": [
{
"id": "r0", "name": "amazing", "textRepr": "amazing(trip)", "type": "ATTR",
"args": [{"type": "SUBJECT", "name": "trip"}],
"feats": {"negated": "false", "modality": ""}
},
{
"id": "r1", "name": "recommend", "textRepr": "would recommend-not(i,food)", "type": "VERB",
"args": [{"type": "SUBJECT", "name": "i"}, {"type": "OBJECT", "name": "food", "entityId": "e0"}],
"feats": {"negated": "true", "modality": "would"}
},
{
"id": "r2", "name": "terrible", "textRepr": "terrible(pizza)", "type": "ATTR",
"args": [{"type": "SUBJECT", "name": "pizza", "entityId": "e1"}],
"feats": {"negated": "false", "modality": ""}
}
],
"usedChars": 102
}
Since relations may reference entities, all relevant entities are automatically included in the response.