domainlab.compos.pcr package

Submodules

domainlab.compos.pcr.p_chain_handler module

Chain of Responsibility

class domainlab.compos.pcr.p_chain_handler.AbstractChainNodeHandler(success_node=None)[source]

Bases: object

Chain of Responsibility: 1. Make sure the chain can be constructed successfully even one node fails to initialize its designated service/business object so services from other nodes will still be available. 2. To ensure this decoupling, avoid overriding self.__init__() (the initializer/constructor) of the handler by using multiple inheritance. e.g. inherit both AbstractChainNodeHandler and Factory Interface since doing so couples the Factory initializer with the AbstractChainNodeHandler(): if the initializer/constructor of the Factory does not work, it will affect the whole chain. 3. Instead, return service/business object in a member function of AbstractChainNodeHandler self.init_business(), this can result in redundant code but is safest. 4. A sub-optimal but still acceptable solution is to use Multiple Inheritance (inherit AbstractChainNodeHandler and Factory interface) but only override the self.init_business(*kargs, **kwargs) method (with concrete input arguments) of the Chain Handler so the initializer/constructor of the Chain Handler will always work. Factory can be returned by calling ChainNode.init_business(*kargs, **kwargs). This can still be coupling since there might be some interface methods in Factory, once you change the parent class, some concrete factories has not implemented that, which will break the initalization of the chain.

handle(request)[source]

This method invoke self.is_myjob() to check which node in the chain should handle the request :param request: subclass can override request object to be string or function :return: light weight AbstractChainNodeHandler

abstract init_business(*kargs)[source]

init_business: initialize and return the heavy weight business object for doing the real job :param request: subclass can override request object to be string or function :return: the constructed service object

abstract is_myjob(request)[source]

is_myjob. :param request: subclass can override request object to be string or function :return True/False

print_options()[source]
set_parent(parent)[source]
class domainlab.compos.pcr.p_chain_handler.DummyBusiness[source]

Bases: object

message = 'dummy business'
class domainlab.compos.pcr.p_chain_handler.DummyChainNodeHandlerBeaver(success_node=None)[source]

Bases: AbstractChainNodeHandler

Dummy class to show how to inherit from Chain of Responsibility

init_business(*kargs, **kwargs)[source]

init_business: initialize and return the heavy weight business object for doing the real job :param request: subclass can override request object to be string or function :return: the constructed service object

is_myjob(request)[source]

is_myjob. :param request: subclass can override request object to be string or function :return True/False

class domainlab.compos.pcr.p_chain_handler.DummyChainNodeHandlerLazy(success_node=None)[source]

Bases: AbstractChainNodeHandler

Dummy class to show how to inherit from Chain of Responsibility

init_business(*kargs, **kwargs)[source]

init_business: initialize and return the heavy weight business object for doing the real job :param request: subclass can override request object to be string or function :return: the constructed service object

is_myjob(request)[source]

is_myjob. :param request: subclass can override request object to be string or function :return True/False

class domainlab.compos.pcr.p_chain_handler.Request4Chain[source]

Bases: object

define all available fields of request to ensure operation safety

abstract convert(obj)[source]

Convert an heavy weight object into request object with pre-defined behavior

domainlab.compos.pcr.request module

class domainlab.compos.pcr.request.RequestArgs2ExpCmd(args)[source]

Bases: object

Isolate args from Request object of chain of responsibility node for experiment For example, args has field names which will couple with experiment class, this request class also serves as isolation class or adaptation class

class domainlab.compos.pcr.request.RequestTask(args)[source]

Bases: object

Isolate args from Request object of chain of responsibility node for task

class domainlab.compos.pcr.request.RequestVAEBuilderCHW(i_c, i_h, i_w, args)[source]

Bases: object

class domainlab.compos.pcr.request.RequestVAEBuilderNN(net_class_d, net_x, net_class_y, i_c, i_h, i_w)[source]

Bases: object

creates request when input does not come from command-line (args) but from test_exp file

Module contents