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
¶
to_archimate(
graph: Graph,
path: Optional[Union[str, Path]] = None,
elem: Optional[Element] = None,
tostring_args: Optional[Dict[str, Any]] = None,
bundle_schemas: bool = False,
) -> str
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 src/ragraph/io/archimate/__init__.py
canopy
¶
Canopy by Ratio CASE format support¶
from_canopy
¶
from_canopy(path: Union[str, Path]) -> List[Graph]
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 src/ragraph/io/canopy.py
to_canopy
¶
to_canopy(
graph: Graph,
path: Optional[Union[Path, str]] = None,
fmt: str = "graph",
) -> Optional[str]
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 src/ragraph/io/canopy.py
csv
¶
CSV format support¶
from_csv
¶
from_csv(
nodes_path: Optional[Union[str, Path]] = None,
edges_path: Optional[Union[str, Path]] = None,
csv_delimiter: str = ";",
iter_delimiter: str = ";",
node_weights: Optional[List[str]] = None,
edge_weights: Optional[List[str]] = None,
**graph_kwargs: Any
) -> Graph
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 src/ragraph/io/csv.py
to_csv
¶
to_csv(
graph: Graph,
stem_path: Union[str, Path],
csv_delimiter: str = ";",
iter_delimiter: str = ";",
use_uuid: bool = False,
)
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 src/ragraph/io/csv.py
esl
¶
Elephant Specification Language format support¶
from_esl
¶
from_esl(*paths: Union[str, Path]) -> Graph
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 src/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 src/ragraph/io/grip.py
add_labels
¶
add_labels(g: Graph)
Add labels to edges based on the description of Raakvlakken.
Source code in src/ragraph/io/grip.py
add_raakvlak_annotations
¶
add_raakvlak_annotations(g: Graph)
Adding Raakvlak ID's as a string to edges annotations.
Source code in src/ragraph/io/grip.py
from_grip
¶
from_grip(
path: Union[str, Path], hierarchy_mode: str = "top-down"
) -> Graph
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 src/ragraph/io/grip.py
parse_CI_MEEisObjects
¶
parse_CI_MEEisObjects(el: Element, annotations: Dict)
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 src/ragraph/io/grip.py
parse_CI_MEEisObjecttypen
¶
parse_CI_MEEisObjecttypen(el: Element, annotations: Dict)
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 src/ragraph/io/grip.py
parse_CI_MEOnderhoudsactiviteitObject
¶
parse_CI_MEOnderhoudsactiviteitObject(
el: Element, annotations: Dict
)
Parse information for Activity object
Source code in src/ragraph/io/grip.py
parse_CI_Toelichting
¶
parse_CI_Toelichting(el: Element, annotations: Dict)
Parse information attached to an CI_Toelichting.
Source code in src/ragraph/io/grip.py
parse_CI_Verificatievoorschrift
¶
parse_CI_Verificatievoorschrift(
el: Element, annotations: Dict
)
Parse information attached to an CI verificationvoorschrift
Source code in src/ragraph/io/grip.py
parse_SI_Eistype
¶
parse_SI_Eistype(el: Element, annotations: Dict)
Parse information attached to an SI_Eistype.
Source code in src/ragraph/io/grip.py
parse_SI_Fase
¶
parse_SI_Fase(el: Element, annotations: Dict)
Parse information attached to an SI_Fase.
Source code in src/ragraph/io/grip.py
parse_SI_Methode
¶
parse_SI_Methode(el: Element, annotations: Dict)
Parse information attached to an SI_Methode.
Source code in src/ragraph/io/grip.py
parse_SI_Periode
¶
parse_SI_Periode(el: Element, annotations: Dict)
Parse information attached to an SI_Periode.
Source code in src/ragraph/io/grip.py
parse_SI_Systeemeisgroepering
¶
parse_SI_Systeemeisgroepering(
el: Element, annotations: Dict
)
Parse information attached to an SI_Systeemeisgroepering.
Source code in src/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 src/ragraph/io/grip.py
parse_eisteksten
¶
parse_eisteksten(el: Element, annotations: Dict)
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 src/ragraph/io/grip.py
parse_element
¶
parse_element(el: Element, item: str) -> Dict
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 src/ragraph/io/grip.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
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 src/ragraph/io/grip.py
parse_verificatie
¶
parse_verificatie(el: Element, annotations: Dict)
Parse information attached to Verificatie.
Source code in src/ragraph/io/grip.py
to_grip
¶
to_grip(
graph: Graph,
path: Optional[Union[str, Path]] = None,
hierarchy_mode: str = "top-down",
) -> Optional[str]
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 src/ragraph/io/grip.py
json
¶
JSON format support¶
from_json
¶
from_json(
path: Optional[Union[str, Path]] = None,
enc: Optional[str] = None,
use_uuid: bool = True,
) -> Graph
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 src/ragraph/io/json.py
graph_from_json_dict
¶
graph_from_json_dict(
graph_dict: Dict[str, Any], use_uuid: bool = True
) -> Graph
Recreate Graph object from JSON dictionary.
Source code in src/ragraph/io/json.py
to_json
¶
to_json(
graph: Graph, path: Optional[Union[str, Path]] = None
) -> Optional[str]
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 src/ragraph/io/json.py
matrix
¶
Adjacency and mapping matrices support¶
from_matrix
¶
from_matrix(
matrix: Union[
ndarray, List[List[int]], List[List[float]]
],
rows: Optional[Union[List[Node], List[str]]] = None,
cols: Optional[Union[List[Node], List[str]]] = None,
weight_label: str = "default",
empty: Optional[Union[int, float]] = 0.0,
convention: Convention = IR_FAD,
**graph_args: Dict[str, Any]
) -> Graph
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 src/ragraph/io/matrix.py
to_matrix
¶
to_matrix(
graph: Graph,
rows: Optional[Union[List[Node], List[str]]] = None,
cols: Optional[Union[List[Node], List[str]]] = None,
inherit: bool = False,
loops: bool = False,
only: Optional[List[str]] = None,
convention: Convention = IR_FAD,
) -> Union[ndarray, List[List[float]]]
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 src/ragraph/io/matrix.py
xml
¶
XML format support using the XML Metadata Interchange (XMI) standard.
from_xml
¶
from_xml(
path: Optional[Union[str, Path]] = None,
enc: Optional[str] = None,
elem: Optional[Element] = None,
validate: bool = True,
) -> Graph
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 src/ragraph/io/xml/__init__.py
to_xml
¶
to_xml(
graph: Graph,
path: Optional[Union[str, Path]] = None,
elem: Optional[Element] = None,
tostring_args: Optional[Dict[str, Any]] = None,
bundle_schemas: bool = False,
) -> str
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 src/ragraph/io/xml/__init__.py
yaml
¶
YAML format support¶
from_yaml
¶
from_yaml(
path: Optional[Union[str, Path]] = None,
enc: Optional[str] = None,
) -> Graph
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 src/ragraph/io/yaml.py
to_yaml
¶
to_yaml(
graph: Graph, path: Optional[Union[str, Path]] = None
) -> Optional[str]
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. |