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 instance 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)
(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 (str) – The name of the group.

Return type:

Tree

Returns:

The generated group tree.

>>> from architxt.schema import Group
>>> group = Group(name='Fruits', entities={'Apple', 'Banana', 'Cherry'})
>>> schema = Schema.from_description(groups={group})
>>> group_tree = gen_group(schema, 'Fruits')
>>> print(group_tree)
(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 instance 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 (str) – The name of the relationship.

Return type:

Tree

Returns:

The generated relation tree.

>>> from architxt.schema import Group, Relation
>>> schema = Schema.from_description(
...     groups={
...         Group(name='Fruits', entities={'Apple', 'Banana'}),
...         Group(name='Colors', entities={'Red', 'Blue'}),
...     },
...     relations={Relation(name='Preference', left='Fruits', right='Colors')}
... )
>>> relation_tree = gen_relation(schema, 'Preference')
>>> print(relation_tree)
(REL::Preference (GROUP::Fruits (ENT::Apple data) (ENT::Banana data)) (GROUP::Colors (ENT::Blue data) (ENT::Red data)))