📘 Resource stores

📘 Resource stores#

Resource stores are a conveninent mean to serialize/deserialize and share resources such as components, characteristics, descriptions and strategies:

from galactic.algebras.concept.core import ItemUniverse
from galactic.algebras.convex.characteristics.core import (
    Characteristic,
    Component,
    Integer,
)
from galactic.algebras.convex.descriptions.core import (
    Description,
    PredicateUniverse,
    Context,
    GaloisConnection,
)
from galactic.algebras.convex.strategies.core import (
    Strategy,
)
from galactic.algebras.convex.strategies.examples.arithmetic.core import (
    MultipleStrategy,
)
from galactic.algebras.convex.descriptions.examples.arithmetic.core import (
    MultipleDescription,
    DivisorDescription,
)
from galactic.helpers.resource import ResourceStore

characteristic = Integer()
descriptions = [
    DivisorDescription(characteristic=characteristic),
    MultipleDescription(characteristic=characteristic),
]
strategy = MultipleStrategy(characteristic=characteristic)
store = ResourceStore(order=[Component, Characteristic, Description, Strategy])
store.insert(characteristic)
store.insert(descriptions[0])
store.insert(descriptions[1])
store.insert(strategy)
store.dump()
{'characteristic.1': {'$type': 'galactic.algebras.convex.characteristics.core.Integer',
  'components': [{'$type': 'galactic.algebras.convex.characteristics.core.Component'}]},
 'description.1': {'$type': 'galactic.algebras.convex.descriptions.examples.arithmetic.core.DivisorDescription',
  'space': [{'$ref': 'characteristic.1'}]},
 'description.2': {'$type': 'galactic.algebras.convex.descriptions.examples.arithmetic.core.MultipleDescription',
  'space': [{'$ref': 'characteristic.1'}]},
 'strategy.1': {'$type': 'galactic.algebras.convex.strategies.examples.arithmetic.core.MultipleStrategy',
  'space': [{'$ref': 'characteristic.1'}]}}