Graph
graph feature can visualize a dataset stored on disk or in memory.
You can write a Geist template with the graph tag. You can also use CLI or Python API step by step as follows:
graph command can visualize a dataset. Only rdflib
is supported for now.
Usage: geist graph [OPTIONS] COMMAND [ARGS]...
Visualize a dataset
Options:
--help Show this message and exit.
geist graph rdflib [OPTIONS]
Usage: geist graph rdflib [OPTIONS]
Visualize an RDF dataset
Options:
-d, --dataset TEXT Name of RDF dataset to be visualized
(default "kb")
-r, --rankdir [TB|BT|LR|RL] Direction of the graph (default TB): TB or
BT or LR or RL
-m, --mappings TEXT File of the mappings to shorten text (str):
path of a JSON file, where the key is the
original text and the value is the shorter
text.
-on, --on TEXT Column(s) to be mapped.
-sc, --samecolor Use the same color for same edges.
-oroot, --outputroot TEXT Path of the directory to store the graph
(default: current directory). If the given
path (i.e., --outputfile) is a relative
path, it will be ignored.
-ofile, --outputfile TEXT Path of the file without extension to store
the graph (default: res)
-oformat, --outputformat [none|svg|png|gv]
Format of the graph (default: none): none or
svg or png or gv
--help Show this message and exit.
Example: visualize the test
dataset
geist graph rdflib --dataset test --outputformat svg
graph function can visualize a dataset. Only rdflib
is supported for now.
Parameters description for export():
Name | Type | Description | Default |
---|---|---|---|
datastore | string | A backend datastore, i.e., 'rdflib' or 'duckdb' |
REQUIRED |
dataset | string OR GeistGraph object |
Dataset to load an object: (1) A string indicates the name of the dataset stored on disk OR (2) a GeistGraph object for dataset in memory |
REQUIRED |
hasoutput | bool | True to export as a file or print it out |
REQUIRED |
config | dict | A dictionary with configurations for certain backend store | see below |
Description for the config parameter:
datastore: rdflib
Name | Type | Description | Default |
---|---|---|---|
rankdir | string | Direction of the graph: 'TB' or 'BT' or 'LR' or 'RL' |
'TB' |
mappings | string | File of the mappings to shorten text (str): path of a JSON file, where the key is the original text and the value is the shorter text | None |
on | string | Column(s) to be mapped | None |
samecolor | bool | True to use the same color for same edges |
True |
outputroot | string | Path of the directory to store the graph | './' |
outputfile | string | Path of the file without extension to store the graph | 'res' |
outputformats | list | Format of the graph: 'none' or 'svg' or 'png' or 'gv' |
['none'] |
Example: visualize the test
dataset
import geist
# Visualize the test dataset as a graph and save it as the res.svg file
geist.graph(datastore='rdflib', dataset='test', hasoutput=True, config={'outputformats': ['svg']})
graph method of the Connection class exports a dataset. Only rdflib
is supported for now. It is very similar to the graph()
function. The only difference is that the datastore
and the dataset
parameters do not need to be passed as they have already been specified while initialzing the Connection class.
Parameters description for graph method of the Connection class:
Name | Type | Description | Default |
---|---|---|---|
datastore | string | A backend datastore, i.e., 'rdflib' or 'duckdb' |
REQUIRED` |
dataset | string OR GeistGraph object |
Dataset to load an object: (1) A string indicates the name of the dataset stored on disk OR (2) a GeistGraph object for dataset in memory |
REQUIRED |
hasoutput | bool | True to export as a file or print it out |
REQUIRED |
config | dict | A dictionary with configurations for certain backend store. | see below |
Description for the config parameter:
datastore: rdflib
Name | Type | Description | Default |
---|---|---|---|
rankdir | string | Direction of the graph: 'TB' or 'BT' or 'LR' or 'RL' |
'TB' |
mappings | string | File of the mappings to shorten text (str): path of a JSON file, where the key is the original text and the value is the shorter text | None |
on | string | Column(s) to be mapped | None |
samecolor | bool | True to use the same color for same edges |
True |
outputroot | string | Path of the directory to store the graph | './' |
outputfile | string | Path of the file without extension to store the graph | 'res' |
outputformats | list | Format of the graph: 'none' or 'svg' or 'png' or 'gv' |
['none'] |
Example 1: visualize the test
dataset on disk
There exist a file with the path of .geistdata/duckdb/test.duckdb
. The following code visualizes the test dataset as a graph and saves it as the res.svg file.
import geist
# Create a Connection instance
connection = geist.Connection.connect(datastore='duckdb', dataset='test')
# Visualize the test dataset
connection.graph(hasoutput=True, config={'outputformats': ['svg']})
Example 2: visualize the test
dataset in memory
Suppose conn
is a DuckPyConnection
object points to a DuckDB dataset in memory. The following code visualizes the test dataset as a graph and saves it as the res.svg file.
import geist
# Create a Connection instance
connection = geist.Connection(datastore='duckdb', dataset=':memory:', conn=conn)
# Visualize the test dataset
connection.graph(hasoutput=True, config={'outputformats': ['svg']})