def getDoer(cls, sModelDir, sModelName, options=None, bCRF=None, bECN=None, bGAT=None, fun_getConfiguredGraphClass=None, sComment=None, cFeatureDefinition=None, dFeatureConfig={}): """ Create the requested doer object """ assert not fun_getConfiguredGraphClass is None, "You must provide a getConfiguredGraphClass method" assert not cFeatureDefinition is None, "You must provide a cFeatureDefinition class" # Graph mode for computing edges assert not (options.bG1 and options.bG2), "Specify graph mode either 1 or 2 not both" iGraphMode = 1 if options.bG1: iGraphMode = 1 if options.bG2: iGraphMode = 2 Graph.setGraphMode(iGraphMode) bCRF = bCRF or (not (options is None) and options.bCRF) bECN = bECN or (not (options is None) and options.bECN) bGAT = bGAT or (not (options is None) and options.bGAT) assert (bCRF or bECN or bGAT), "You must specify one learning method." assert [ bCRF, bECN, bGAT ].count(True) == 1, "You must specify only one learning method." if bECN: c = DU_ECN_Task elif bCRF: c = DU_CRF_Task elif bGAT: c = DU_GAT_Task c.getConfiguredGraphClass = fun_getConfiguredGraphClass doer = c(sModelName, sModelDir, sComment=sComment, cFeatureDefinition=cFeatureDefinition, dFeatureConfig=dFeatureConfig) if options.seed is None: random.seed() traceln("SETUP: Randomizer initialized automatically") else: random.seed(options.seed) traceln("SETUP: Randomizer initialized by your seed (%d)" % options.seed) traceln("SETUP: doer : class=%s version=%s" % (doer.__class__.__qualname__, doer.getVersion())) return doer
def getDoer( cls, sModelDir, sModelName, options=None, fun_getConfiguredGraphClass=None, sComment=None, cFeatureDefinition=None, dFeatureConfig={}, cTask=None # to specify a specific Task class ): """ Create the requested doer object """ assert not fun_getConfiguredGraphClass is None, "You must provide a getConfiguredGraphClass method" assert not cFeatureDefinition is None, "You must provide a cFeatureDefinition class" # Graph mode for computing edges assert not (options.bG1 and options.bG2), "Specify graph mode either 1 or 2 not both" iGraphMode = 1 assert [options.bG1, options.bG2, options.bG1o].count( True ) <= 1, "Specify at most one graph mode (default is mode %d)" % iGraphMode if options.bG1: iGraphMode = 1 if options.bG2: iGraphMode = 2 if options.bG1o: iGraphMode = 4 Graph.setGraphMode(iGraphMode) # bCRF = bCRF or (not(options is None) and options.bCRF) # bECN = bECN or (not(options is None) and options.bECN) # bECNEnsemble = bECNEnsemble or (not(options is None) and options.bECN) # bGAT = bGAT or (not(options is None) and options.bGAT) assert (options.bCRF or options.bECN or options.bECNEnsemble or options.bGAT or bool(cTask)), "You must specify one learning method." assert bool(cTask) or [ options.bCRF, options.bECN, options.bECNEnsemble, options.bGAT ].count(True) == 1, "You must specify only one learning method." if cTask is None: if options.bECN: c = DU_ECN_Task elif options.bECNEnsemble: c = DU_Ensemble_ECN_Task elif options.bCRF: c = DU_CRF_Task elif options.bGAT: c = DU_GAT_Task else: raise Exception("Internal error: no DU_Task class") else: c = cTask c.getConfiguredGraphClass = fun_getConfiguredGraphClass doer = c(sModelName, sModelDir, sComment=sComment, cFeatureDefinition=cFeatureDefinition, dFeatureConfig=dFeatureConfig) if options.sExt: doer.setXmlFilenamePattern(options.sExt) if options.seed is None: random.seed() traceln("SETUP: Randomizer initialized automatically") else: random.seed(options.seed) traceln("SETUP: Randomizer initialized by your seed (%d)" % options.seed) traceln("SETUP: doer : class=%s version=%s" % (doer.__class__.__qualname__, doer.getVersion())) return doer