Graph
Starting from version 0.13.3
we introduce a graph submodule.
One main functionality is now supported, that is, converting an ORKG component from RDF statements into pythonic graph representation. We currently support the well known networkx as a representation.
Usage
import orkg
# create the client to the ORKG
client = orkg.ORKG(host="<host-address-is-here>", creds=('email-address', 'password'))
# get the subgraph of 'contribution_id'. The object has the type networkx.DiGraph
subgraph = orkg.subgraph(client=client, thing_id='contribution_id')
# try this and check what properties we provide!
print('### Nodes ###')
for node in subgraph.nodes(data=True):
print(node)
# also try this and validate the result!
print('### Edges ###')
for edge in subgraph.edges(data=True):
print(edge)
API
- orkg.graph.subgraph(client: Any, thing_id: str, blacklist: Union[str, List[str]] = '', max_level: int = -1) DiGraph
Obtains a networkx directed graph representation of any ORKG component given by its thing_id. E.g. of ORKG components: Paper, Contribution, Comparison, Template
It starts from the thing_id resource and traverses the graph until all literals are reached.
- Parameters
client – orkg.ORKG client used to connect with ORKG backend.
thing_id – Any subject, object or predicate ID in the ORKG.
blacklist – Class(es) to be excluded from the subgraph. E.g. ‘ResearchField’ (see orkgc:ResearchField). Note that the first subgraph level will always be included.
max_level – Deepest subgraph’s level to traverse.