ragraph.io
¶
Graph import/export¶
Supports multiple formats via its submodules.
archimate
¶
XML format support using The Open Group ArchiMate® Model Exchange File Format.
Reference
from_archimate
¶
to_archimate
¶
Encode Graph to an Archimate model XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to convert to XML. |
required |
path
|
Optional[Union[str, Path]]
|
Optional file path to write XML to. |
None
|
elem
|
Optional[Element]
|
Optional object to append the Graph to. |
None
|
tostring_args
|
Optional[Dict[str, Any]]
|
Optional argument overrides to
|
None
|
bundle_schemas
|
bool
|
When exporting to a file, bundle the .xsd schemas. |
False
|
Returns:
Type | Description |
---|---|
str
|
XML element. |
Note
For both nodes and edges we use the following:
The annotations.archimate["type"]
determines the type (and therefore layer).
The annotations.archimate["documentation"]
populates the documentation field.
Refer to https://www.opengroup.org/xsd/archimate/ and the XSD scheme for all
possible XML element types.
Source code in ragraph/io/archimate/__init__.py
canopy
¶
Canopy by Ratio CASE format support¶
from_canopy
¶
Get the graph(s) from a Canopy data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
Path of the file to load. |
required |
Returns:
Type | Description |
---|---|
List[Graph]
|
Graph objects contained in Canopy data formats being either a graph, tab, |
List[Graph]
|
session, or workspace export of Canopy. |
Raises:
Type | Description |
---|---|
InconsistencyError
|
if graph is inconsistent. |
Source code in ragraph/io/canopy.py
to_canopy
¶
|
Save graph as a Canopy dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to save. |
required |
path
|
Optional[Union[Path, str]]
|
Path to write to. |
None
|
fmt
|
str
|
One of 'session' or 'graph'. |
'graph'
|
Returns:
Type | Description |
---|---|
Optional[str]
|
JSON encoded string if no path was provided to write to. |
Source code in ragraph/io/canopy.py
csv
¶
CSV format support¶
from_csv
¶
|
Convert CSV files to a graph.
Nodes file (optional) requires at least a name
column. Optional special
property columns are kind
, labels
, parent
, children
and is_bus
.
Edges file requires at least a source
and target
column. Optional special
property columns are kind
and labels
.
Automatically completes one sided parent-child relationships.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes_path
|
Optional[Union[str, Path]]
|
Path of optional nodes CSV file. |
None
|
edges_path
|
Optional[Union[str, Path]]
|
Path of edges CSV file. |
None
|
csv_delimiter
|
str
|
Delimiter of CSV file. |
';'
|
iter_delimiter
|
str
|
Iterable delimiter (i.e. for children names list). |
';'
|
node_weights
|
Optional[List[str]]
|
Columns to interpret as node weights. |
None
|
edge_weights
|
Optional[List[str]]
|
Columns to interpret as edge weights. |
None
|
**graph_kwargs
|
Any
|
Optional |
{}
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Raises:
Type | Description |
---|---|
InconsistencyError
|
if graph is inconsistent. |
Source code in ragraph/io/csv.py
to_csv
¶
|
Save graph to nodes and edges CSV files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to save. |
required |
stem_path
|
Union[str, Path]
|
Stem path for output CSV's. Appended with _nodes.csv and _edges.csv. |
required |
csv_delimiter
|
str
|
CSV delimiter. |
';'
|
iter_delimiter
|
str
|
Iterable delimiter (i.e. for children names list). |
';'
|
use_uuid
|
bool
|
Whether to export UUIDs, too. |
False
|
Source code in ragraph/io/csv.py
esl
¶
Elephant Specification Language format support¶
from_esl
¶
Convert ESL file(s) into a :obj:ragraph.graph.Graph
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths
|
Union[str, Path]
|
Paths to resolve into ESL files. May be any number of files and directories to scan. |
()
|
Returns:
Type | Description |
---|---|
Graph
|
Instantiated graph. |
Source code in ragraph/io/esl.py
grip
¶
GRIP format support¶
add_SI_Functie
¶
Add function reference to super element.
Note: This is a bit of a weird quirk of the GRIP data structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sub
|
Element
|
super element to add function element to |
required |
func
|
Dict[str, Any]
|
function reference. |
required |
fcount
|
int
|
Number of referenced function. |
required |
node
|
Node
|
Node to which the reference is added. |
required |
Source code in ragraph/io/grip.py
from_grip
¶
Decode GRIP XML file, string, or element into a Graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Union[str, Path]
|
GRIP XML file path. |
required |
hierarchy_mode
|
str
|
One of "bottom-up" or "top-down". Defines how the hierarchy relations are stored. |
'top-down'
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Source code in ragraph/io/grip.py
parse_CI_MEEisObjects
¶
Parse CI_MEEisObjects and store within annotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
el
|
Element
|
Systeemeis to be parsed |
required |
annotations
|
Dict
|
Dictionary in which information must be stored |
required |
Source code in ragraph/io/grip.py
parse_CI_MEEisObjecttypen
¶
Parse CI_MEEisObjectypen and store within annotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
el
|
Element
|
Systeemeis to be parsed |
required |
annotations
|
Dict
|
Dictionary in which information must be stored |
required |
Source code in ragraph/io/grip.py
parse_collection
¶
Decode contents of XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph object to add nodes to |
required |
root
|
Element
|
Root of XML file |
required |
collection
|
str
|
Sub-collection to parse (e.g. objecten or Objecttypen) |
required |
item
|
str
|
item kind to parse. |
required |
kind
|
str
|
kind to assign to created nodes. |
required |
Source code in ragraph/io/grip.py
parse_eisteksten
¶
Parse eisteksten and store within annotations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
el
|
Element
|
Systeemeis to be parsed |
required |
annotations
|
Dict
|
Dictionary in which information must be stored |
required |
Source code in ragraph/io/grip.py
parse_element
¶
Parsing element and store relevant information within Node annotations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
el
|
Element
|
Element to parse. |
required |
item
|
str
|
item kind being parsed. |
required |
Returns:
Type | Description |
---|---|
Dict
|
Name string and Annotations dictionary. |
Source code in ragraph/io/grip.py
parse_params
¶
Decode parameter section of GRIP XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph object to add nodes to. |
required |
root
|
Element
|
Root of XML file. |
required |
Source code in ragraph/io/grip.py
to_grip
¶
|
Convert a graph with GRIP content structure to a GRIP XML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to convert. |
required |
path
|
Optional[Union[str, Path]]
|
Optional path to write converted XML text to. |
None
|
Returns:
Type | Description |
---|---|
Optional[str]
|
String contents when no path was given. |
Source code in ragraph/io/grip.py
json
¶
JSON format support¶
from_json
¶
|
Decode JSON file or string into a Graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
JSON file path. |
None
|
enc
|
Optional[str]
|
JSON encoded string. |
None
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Source code in ragraph/io/json.py
graph_from_json_dict
¶
Recreate Graph object from JSON dictionary.
Source code in ragraph/io/json.py
to_json
¶
Encode Graph to JSON file or string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
Optional file path to write JSON to. |
None
|
Returns:
Type | Description |
---|---|
Optional[str]
|
JSON string. |
Source code in ragraph/io/json.py
matrix
¶
Adjacency and mapping matrices support¶
from_matrix
¶
|
Create a graph from an adjacency or mapping matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matrix
|
Union[ndarray, List[List[int]], List[List[float]]]
|
Matrix to convert into a graph. |
required |
rows
|
Optional[Union[List[Node], List[str]]]
|
Nodes or node labels corresponding to the rows of the matrix. |
None
|
cols
|
Optional[Union[List[Node], List[str]]]
|
Nodes or node labels corresponding to the columns of the matrix. If none are provided, the row labels are re-used. |
None
|
weight_label
|
str
|
Weight label to use for matrix values. |
'default'
|
empty
|
Optional[Union[int, float]]
|
Cell value to be considered "empty", e.g. no edge should be created. |
0.0
|
**graph_args
|
Dict[str, Any]
|
Additional arguments to |
{}
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Note
If no row labels are provided, they are generated in a "node#" format. If no column labels are provided, they are assumed to be equal to the rows. For non-square matrices, you should provide node labels!
Source code in ragraph/io/matrix.py
to_matrix
¶
|
Convert graph data into a directed numerical adjacency or mapping matrix.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to fetch data from. |
required |
rows
|
Optional[Union[List[Node], List[str]]]
|
Nodes representing the matrix rows. |
None
|
cols
|
Optional[Union[List[Node], List[str]]]
|
Nodes representing the matrix columns if different from the rows. |
None
|
inherit
|
bool
|
Whether to count weights between children of the given nodes. |
False
|
loops
|
bool
|
Whether to calculate self-loops from a node to itself. |
False
|
only
|
Optional[List[str]]
|
Optional subset of edge weights to consider. See
|
None
|
Returns:
Type | Description |
---|---|
Union[ndarray, List[List[float]]]
|
Adjacency matrix as a 2D numpy array if numpy is present. Otherwise it will return a 2D |
Union[ndarray, List[List[float]]]
|
nested list. |
Note
Note that the matrix is directed! Columns are inputs to rows.
Source code in ragraph/io/matrix.py
xml
¶
XML format support using the XML Metadata Interchange (XMI) standard.
from_xml
¶
Decode XML file, string, or element into a Graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
XML file path. |
None
|
enc
|
Optional[str]
|
XML encoded string. |
None
|
elem
|
Optional[Element]
|
XML Element. |
None
|
validate
|
bool
|
Whether to validate the XML input. |
True
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Note
You should only provide one of path
, enc
, or elem
, which are handled in that order of
precedence.
Source code in ragraph/io/xml/__init__.py
to_xml
¶
Encode Graph to an XML element.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Graph
|
Graph to convert to XML. |
required |
path
|
Optional[Union[str, Path]]
|
Optional file path to write XML to. |
None
|
elem
|
Optional[Element]
|
Optional object to append the Graph to. |
None
|
tostring_args
|
Optional[Dict[str, Any]]
|
Optional argument overrides to
|
None
|
bundle_schemas
|
bool
|
When exporting to a file, bundle the .xsd schemas. |
False
|
Returns:
Type | Description |
---|---|
str
|
XML element. |
Source code in ragraph/io/xml/__init__.py
yaml
¶
YAML format support¶
from_yaml
¶
Decode YAML file or string into a Graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
YAML file path. |
None
|
enc
|
Optional[str]
|
YAML encoded string. |
None
|
Returns:
Type | Description |
---|---|
Graph
|
Graph object. |
Source code in ragraph/io/yaml.py
to_yaml
¶
Encode Graph to YAML file or string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Optional[Union[str, Path]]
|
Optional file path to write YAML to. |
None
|
Returns:
Type | Description |
---|---|
Optional[str]
|
YAML string. |