AXON datamodel bases on composition of several data construction patterns. It reflects both JSON and XML datamodels.
AXON datamodel has two rules of composition that reflects JSON datamodel:
In addition AXON datamodel has a rule of composition for construction of tuples — fixed sequence of values:
AXON datamodel also has three rules of composition that reflects XML infoset datamodel:
First rule allows to construct structures (named sequences) similar to XML element without attributes. Second rule allows to construct structures (named mappings) similar to XML element without of subelements. Third rule allows to construct structures (named elements) similar XML element both with attributes and subelements. Unlike XML, in AXON attribute's value can be an arbitrary value.
AXON datamodel has yet another rule of composition that reflects concept of named tuple, which contain fixed number of values and may contain also optional values specified by their attribute name: res, which are composed by several rules:
Last rule is for symmetry; it useful for representation of data rows with fixed fields and optional fields specified by their names.
AXON named complex values can be mapped to objects by their names. pyaxon module supports protocol for loading and dumping.
AXON lists, dicts and tuples are mapped to python's list, dicts and tuples.
For named complex values one can define a class with base class GenericBuilder, which has four methods:
sequence(name, list);mapping(name, dict);element(name, dict, list);instance(name, list, dict).During loading these methods are called according to next rules that corresponds to last four above rules of composition:
sequence( $\text{N}$, $[D_1,\dots,D_n]$ );mapping( $\text{N}$, $\{a_1\colon D_1,\dots,a_n\colon D_n\}$ );element( $\text{N}$, $\{a_1\colon D_1,\dots,a_n\colon D_n\}, [E_1,\dots,E_m]$ );instance( $\text{N}$, $[E_1,\dots,E_m]$, $\{a_1\colon D_1,\dots,a_n\colon D_n\}$ ).There is a protocol for dumping python objects. In order to dump the class C instances one have to do the following:
o of the class C and returns instance of Empty, Sequence, Mapping, Element or Instance;reduce function.Empty
In [1]:
from __future__ import print_function, unicode_literals
from axon.api import loads, dumps
# pretty printing of python objects
from pprint import pprint
# ipython tools for pretty of images and html
from IPython.display import HTML, display