architxt.generator#

Generator of instances.

Functions

gen_collection(name, elements)

Generate a collection tree.

gen_group(schema, name)

Generate a group tree structure with the given name and elements.

gen_instance(schema, *[, size, ...])

Generate a database instances as a tree based on the given groups and relations schema.

gen_relation(schema, name)

Generate a relation tree structure based on the given parameters.

architxt.generator.gen_collection(name, elements)[source]#

Generate a collection tree.

Parameters:
  • name (str) – The name of the collection.

  • elements (Iterable[Tree]) – The list of trees that make up the collection.

Return type:

Tree

Returns:

A tree representing the collection.

>>> from architxt.tree import Tree
>>> elems = [Tree('Element1', []), Tree('Element2', [])]
>>> collection_tree = gen_collection('Collection', elems)
>>> print(collection_tree.pformat(margin=255))
(COLL::Collection (Element1 ) (Element2 ))
architxt.generator.gen_group(schema, name)[source]#

Generate a group tree structure with the given name and elements.

Parameters:
  • schema (Schema) – A schema to guide the tree structure.

  • name (NodeLabel) – The name of the group.

Return type:

Tree

Returns:

The generated group tree.

>>> schema = Schema.from_description(groups={'Fruits': {'Apple', 'Banana', 'Cherry'}})
>>> group_tree = gen_group(schema, NodeLabel(NodeType.GROUP, 'Fruits'))
>>> print(group_tree.pformat(margin=255))
(GROUP::Fruits (ENT::Apple data) (ENT::Banana data) (ENT::Cherry data))
architxt.generator.gen_instance(schema, *, size=200, generate_collections=True)[source]#

Generate a database instances as a tree based on the given groups and relations schema.

Parameters:
  • schema (Schema) – A schema to guide the tree structure.

  • size (int) – An integer specifying the size of the generated trees.

  • generate_collections (bool) – A boolean indicating whether to generate collections or not.

Return type:

Generator[Tree, None, None]

Returns:

A tree representing the generated instance.

architxt.generator.gen_relation(schema, name)[source]#

Generate a relation tree structure based on the given parameters.

Parameters:
  • schema (Schema) – A schema to guide the tree structure.

  • name (NodeLabel) – The name of the relationship.

Return type:

Tree

Returns:

The generated relation tree.

>>> schema = Schema.from_description(
...     groups={'Fruits': {'Apple', 'Banana'}, 'Colors': {'Red', 'Blue'}},
...     rels={'Preference': ('Fruits', 'Colors')}
... )
>>> relation_tree = gen_relation(schema, NodeLabel(NodeType.REL, 'Preference'))
>>> print(relation_tree.pformat(margin=255))
(REL::Preference (GROUP::Colors (ENT::Blue data) (ENT::Red data)) (GROUP::Fruits (ENT::Apple data) (ENT::Banana data)))