architxt.database.loader.documents#
Functions
|
Parse a document tree and yields processed subtrees based on collection grouping. |
|
Parse a document database file like XML, JSON, or CSV. |
|
Read the file as a data tree. |
|
Read and parse a document file like XML, JSON, or CSV. |
|
Recursively converts a document nested structure into a tree. |
|
Recursively traverses and transforms a nested tree into a valid metamodel structure. |
- architxt.database.loader.documents.parse_document_tree(tree)[source]#
Parse a document tree and yields processed subtrees based on collection grouping.
If the root node is not a collection, the entire tree is processed and a single result is yielded.
If the root node is a collection, each child subtree is individually processed and yielded.
- TODO: Enhance tree decomposition for nested collections.
If no collection exists at the root level, consider splitting at the closest collection and duplicating the path to the root for each collection element.
- architxt.database.loader.documents.parse_file(file)[source]#
Parse a document database file like XML, JSON, or CSV.
- architxt.database.loader.documents.read_document(file, *, raw_read=False, root_name='ROOT')[source]#
Read the file as a data tree.
XML are parsed according to https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
- Parameters:
- Return type:
- Returns:
A list of trees representing the database.
- architxt.database.loader.documents.read_document_file(file)[source]#
Read and parse a document file like XML, JSON, or CSV.
- Parameters:
file (
Union
[str
,Path
,BytesIO
,BinaryIO
]) – The document database file to read.- Return type:
- Returns:
The parsed contents of the file.
- Raises:
FileNotFoundError – If the file does not exist.
OSError – If the file cannot be read.
ValueError – If the file cannot be read or is empty.
- architxt.database.loader.documents.read_tree(data, *, root_name='ROOT')[source]#
Recursively converts a document nested structure into a tree.
Dictionaries are treated as groups.
Lists are treated as collections.
Leaf elements are treated as entities.
If a list contains only a single collection, the function flattens the output by returning that collection directly instead of nesting it under another collection node.
- architxt.database.loader.documents.traverse_tree(tree)[source]#
Recursively traverses and transforms a nested tree into a valid metamodel structure.
The function extracts entity nodes and groups them under a single group node. It then establishes relations between this group and any nested subgroups.