PollyKG
The PollyKG class provides an interface to interact with the Polly Knowledge Graph (KG) API. It enables users to execute and manage Gremlin and OpenCypher queries, retrieve node and relationship data, and analyze graph structures efficiently. This class simplifies access to the KG engine, allowing seamless querying and data exploration. It is designed for users who need to extract insights from complex graph-based datasets.
Parameters:
-
token
(str
, default:None
) –Authentication token from polly
Usage
from polly.polly_kg import PollyKG
kg = PollyKG(token)
get_engine_status
Retrieve a status of the Polly Knowledge Graph.
Returns:
-
dict
(dict
) –A dictionary containing status information about the engine, such as gremlin, opencypher.
Raises:
-
ResourceNotFoundError
–Raised when the specified graph does not exist.
-
AccessDeniedError
–Raised when the user does not have permission to access the graph status.
-
RequestFailureException
–Raised when the request fails due to an unexpected error.
Examples:
get_graph_summary
Retrieve a summary of the Polly Knowledge Graph.
Returns:
-
dict
(dict
) –A dictionary containing summary information about the graph, such as node counts, edge counts, and other metadata.
Raises:
-
ResourceNotFoundError
–Raised when the specified graph summary does not exist.
-
AccessDeniedError
–Raised when the user does not have permission to access the graph summary.
-
RequestFailureException
–Raised when the request fails due to an unexpected error.
Examples:
run_gremlin_query
Execute a Gremlin query against the Polly KG endpoint.
Parameters:
-
query
(str
) –The Gremlin query to execute.
Returns:
-
dict
(dict
) –The query execution results.
Raises:
-
InvalidParameterException
–Raised when the query is empty or None.
-
RequestFailureException
–Raised when the request fails due to an unexpected error.
-
QueryFailedException
–Raised when the query execution fails due to a timeout.
Examples:
run_opencypher_query
Execute a opencypher query against the Polly KG endpoint.
Parameters:
-
query
(str
) –The opencypher query to execute.
Returns:
-
dict
(dict
) –The query execution results.
Raises:
-
InvalidParameterException
–Raised when the query is empty or None.
-
RequestFailureException
–Raised when the request fails due to an unexpected error.
-
QueryFailedException
–Raised when the query execution fails due to a timeout.
Examples:
Examples
PollyKG class of polly-python can be initialised using the code block below:-
import os
from polly.auth import Polly
from polly.polly_kg import PollyKG
token = os.environ['POLLY_REFRESH_TOKEN']
Polly.auth(token)
kg = PollyKG()
get_graph_summary()
Users can get summary of the Polly Knowledge Graph with example shown below:-
INFO:root:Graph Summary !{
"numNodes": 9999999,
"numEdges": 9999999,
"numNodeLabels": 99,
"numEdgeLabels": 99,
"nodeLabels": [
"disease",
"exposure",
"example",
"example2"
],
"edgeLabels": [
"enzyme",
"side effect",
"example",
"example2"
],
"numNodeProperties": 99,
"numEdgeProperties": 99,
"nodeProperties": [
{
"name": 999999
}
],
"edgeProperties": [
{
"weights": 999999
}
],
"totalNodePropertyValues": 999999,
"totalEdgePropertyValues": 999999
}
get_engine_status()
Users can get status of the Polly Knowledge Graph with example shown below:-
INFO:root:Graph Status !{
"status": "healthy",
"gremlin": {
"version": "version"
},
"opencypher": {
"version": "version"
}
}
run_gremlin_query()
INFO:root:Run Complete !
{
"data": {
"@type": "g:List",
"@value": [
{
"@type": "g:Map",
"@value": [
"id",
"9999",
"properties",
{
"@type": "g:Map",
"@value": [
"name",
{"@type": "g:List", "@value": ["PPPPPP"]},
],
},
],
},
{
"@type": "g:Map",
"@value": [
"id",
"55555",
"properties",
{
"@type": "g:Map",
"@value": [
"name",
{"@type": "g:List", "@value": ["PPPPPP"]},
],
},
],
},
],
},
"meta": {"@type": "g:Map", "@value": []},
}
run_opencypher_query()
INFO:root:Run Complete !
[
{
"node": {
"~id": "9999",
"~entityType": "node",
"~labels": ["gene/property"],
"~properties": {"name": "PPPPPP"},
}
}
]