def build_operator(action, schema, args): print("building \t{}".format(action.name)) for i, arg in enumerate(args): schema.elements.add(arg) schema.edges.add(Edge(schema.root, arg, i)) if action.precond is not None: precond_list = [] if action.precond.formula.key == "and": for child in action.precond.formula.children: prec = build_literal(child, schema) if prec is None: continue precond_list.append(prec) schema.edges.add(Edge(schema.root, prec, "precond-of")) else: prec = build_literal(action.precond.formula, schema) schema.edges.add(Edge(schema.root, prec, "precond-of")) if action.effect is not None: effect_list = [] if action.effect.formula.key == "and": for child in action.effect.formula.children: eff = build_literal(child, schema) effect_list.append(eff) schema.edges.add(Edge(schema.root, eff, "effect-of")) else: eff = build_literal(action.effect.formula, schema) schema.edges.add(Edge(schema.root, eff, "effect-of")) return schema
def getSubFormulaGraph(formula, op_graph, parent=None, relationship=None, elements=None, edges=None): if elements is None: elements = set() if edges is None: edges = set() '''make new literal representing subformula''' if formula.key == 'not': formula = next(iter(formula.children)) if formula.key == 'intends': lit, formula = nested_lit(False, parent, formula, elements, edges, 'intends', relationship, 'goal-of') elif formula.key in {'equals', '=', 'equal'}: getNonEquals(formula, op_graph, elements, edges) return elif formula.key == 'bel-char': lit, formula = nested_lit(False, parent, formula, elements, edges, 'bel-char', relationship, 'bel-of') else: lit, formula = makeLit(formula, parent, relationship, elements, edges, False) elif formula.key == 'intends': lit, formula = nested_lit(True, parent, formula, elements, edges, 'intends', relationship, 'goal-of') elif formula.key == 'bel': lit, formula = nested_lit(True, parent, formula, elements, edges, 'belief', relationship, 'bel') elif formula.key == 'obs': lit, formula = nested_lit(True, parent, formula, elements, edges, 'obs', relationship, 'obs') # raise NameError('no intends yet') elif formula.key == 'bel-char': lit, formula = nested_lit(True, parent, formula, elements, edges, 'bel-char', relationship, 'bel-of') elif formula.key == 'for-all' or formula.key == 'forall': raise NameError('no for-all yet') elif formula.type > 0: raise ValueError('not sure why formula.type > 0') else: lit, formula = makeLit(formula, parent, relationship, elements, edges, True) '''for each variable, find existing argument in action parameters and add Edge''' for i, child in enumerate(formula.children): try: arg = next(element for element in elements if child.key.name == element.arg_name) except: print('debug') if relationship == 'actor-of': edges.add(Edge(parent, arg, 'actor-of')) else: edges.add(Edge(lit, arg, i)) return elements, edges
def nested_lit(status, parent, formula, elements, edges, lit_name, relationship, lit_relationship): _lit = Literal(name=lit_name, num_args=2, truth=status) edges.add(Edge(parent, _lit, relationship)) person_name = formula.children[0].key.name arg = next(element for element in elements if person_name == element.arg_name) edges.add(Edge(_lit, arg, GC.ARGLABELS[0])) elements.add(_lit) symb_ = formula.children[1] if symb_.key == 'not': symb_ = next(iter(formula.children)) return makeLit(symb_, _lit, lit_relationship, elements, edges, False) else: return makeLit(symb_, _lit, lit_relationship, elements, edges, True)
def getSubFormulaNoParent(formula, objects): elements = set() edges = set() if formula.key == 'not': formula = next(iter(formula.children)) if formula.key == 'intends': raise NameError('no intends yet') else: lit = Literal(name=formula.key, num_args=len(formula.children), truth=False) elements.add(lit) elif formula.key == 'intends': raise NameError('no intends yet') elif formula.type > 0: raise ValueError('not sure why formula.type > 0') else: lit = Literal(name=formula.key, num_args=len(formula.children), truth=True) elements.add(lit) for i, child in enumerate(formula.children): # children are list arg = next(ob_element for ob_name, ob_element in objects.items() if child.key == ob_name) edges.add(Edge(lit, arg, i)) elements.add(arg) return elements, edges
def stepFromArg(arg, DG): step_elm = whichElm(arg.children[0].key.name, DG) # step type op_type = arg.children[1].key step_elm.name = op_type args = [whichElm(child.key.name, DG) for child in arg.children[1].children] # args = [whichElm(child.key.name, DG) for child in arg.children[0].children] for i, arg in enumerate(args): DG.edges.add(Edge(step_elm, arg, i))
def build_problem_goal(problem, args): goal_op = Operator(name='dummy_goal', stepnumber=1, num_args=0) goal_graph = Action(name='dummy_goal', root_element=goal_op) for i, object in enumerate(args): goal_graph.elements.add(object) goal_graph.edges.add(Edge(goal_op, object, i)) if problem.goal.formula.key != "and": build_literal(problem.goal.formula, goal_graph) else: precond_list = [] for child in problem.goal.formula.children: prec = build_literal(child, goal_graph) if prec is None: continue precond_list.append(prec) goal_graph.edges.add(Edge(goal_op, prec, "precond-of")) return goal_graph
def build_problem_init(problem, args): init_op = Operator(name='dummy_init', stepnumber=0, num_args=0) init_graph = Action(name='dummy_init', root_element=init_op) for i, object in enumerate(args): init_graph.elements.add(object) init_graph.edges.add(Edge(init_op, object, i)) effect_edges = [] for condition in problem.init.predicates: effect = build_literal(condition, init_graph) if effect is None: continue eff_edge = Edge(init_op, effect, 'effect-of') init_graph.edges.add(eff_edge) effect_edges.append(eff_edge) return init_graph, effect_edges
def distinguished_steps(GL, gdo, height): dummy_init = Action(name='begin:' + str(gdo.name) + "-" + str(gdo.root.stepnumber) + str([decompile(arg, gdo) for arg in gdo.Args])) dummy_init.has_cndt = False dummy_init.root.name = dummy_init.name for condition in gdo.Preconditions: if condition.name not in GL.non_static_preds: continue dummy_init.edges.add(Edge(dummy_init.root, condition.root, 'effect-of')) dummy_init.edges.update(condition.edges) dummy_init.elements.update(condition.elements) dummy_init.instantiable = False """ One does not need to add preconditions to the dummy_init - these are marked as completed during initial insertion In other words. when we insert a decompositional step, its preconditions are passed to its dummy_init. """ dummy_goal = Action(name='finish:' + str(gdo.name) + "-" + str(gdo.root.stepnumber) + str([decompile(arg, gdo) for arg in gdo.Args])) dummy_goal.is_cndt = False dummy_goal.root.name = dummy_goal.name for condition in gdo.Effects: dummy_goal.edges.add(Edge(dummy_goal.root, condition.root, "effect-of")) dummy_goal.edges.update(condition.edges) dummy_goal.elements.update(condition.elements) if not GL.check_has_effect(condition, height + 1): # this is a pattern effect. continue dummy_goal.edges.add( Edge(dummy_goal.root, condition.root, 'precond-of')) dummy_goal.instantiable = False gdo.sub_dummy_init = dummy_init gdo.sub_dummy_goal = dummy_goal
def replaceArg(self, original, replacer): incoming = [edge for edge in self.edges if edge.sink == original] for edge in incoming: try: self.edges.remove(edge) except: raise ValueError('edge not in set') self.edges.add(Edge(edge.source, replacer, edge.label)) # edge.sink = replacer if original in self.elements: self.elements.remove(original) self.elements.add(replacer)
def problemToGraphs(problem): """ Returns a dictionary: Keys: 'arg', 'init', 'goal' Values: arg dictionary, (elements, edges), (elements, edges) """ Args = { object.name: Argument(name=object.name, typ=object.typeName) for object in problem.objects if not object.typeName.lower() in {'character', 'actor', 'person', 'agent'} } Args.update({ object.name: Actor(typ=object.typeName.lower(), name=object.name) for object in problem.objects if object.typeName.lower() in {'character', 'actor', 'person', 'agent'} }) goal_elements, goal_edges = getGoalSet(problem.goal.formula, Args) goal_op = Operator(name='dummy_goal', stepnumber=1, num_args=0) goal_graph = Action(name='dummy_goal', root_element=goal_op) goal_graph.elements.update(goal_elements) goal_graph.edges.update(goal_edges) goal_graph.edges.update({ Edge(goal_op, goal_lit, 'precond-of') for goal_lit in goal_elements if type(goal_lit) is Literal }) init_op = Operator(name='dummy_init', stepnumber=0, num_args=0) init_graph = Action(name='dummy_init', root_element=init_op) for condition in problem.init.predicates: lit = Literal(name=condition.name, num_args=len(condition.parameters), truth=True) init_graph.elements.add(lit) init_graph.edges.add(Edge(init_op, lit, 'effect-of')) for i, p in enumerate(condition.parameters): init_graph.edges.add(Edge(lit, Args[p], i)) return Args, init_graph, goal_graph
def getPotentialEffectLinkConditions(self, src, snk): """ Given source and sink steps, return {eff(src) \cap pre(snk)} But, let those conditions be those of the src. """ cndts = [] for eff in self[src.stepnumber].effects: for pre in self[snk.stepnumber].preconditions: if eff.replaced_ID not in self.id_dict[pre.replaced_ID]: continue cndts.append(Edge(src, snk, copy.deepcopy(eff))) return cndts
def addNegativeInitStates(predicates, initAction, objects): init_tups = defaultdict(set) effects = initAction.getNeighbors(initAction.root) for eff in effects: nontup = sorted([(edge.sink, edge.label) for edge in initAction.getIncidentEdges(eff)], key=lambda x: x[1]) init_tups[eff.name].add(tuple(nontup[i][0] for i in range(len(nontup)))) objs_by_type_dict = defaultdict(set) for obj in objects: objs_by_type_dict[obj.typ].add(obj) for p in predicates: param_object_pairs = [[ obj for obj in objs_by_type_dict[param.types[0]] ] for param in p.parameters if not p.parameters[0].types is None] param_tuples = {i for i in itertools.product(*param_object_pairs)} pred = Literal(name=p.name, arg_name='init_effect', num_args=len(p.parameters), truth=False) for pt in param_tuples: if pt in init_tups[p.name]: continue pc = copy.deepcopy(pred) pc.ID = uuid4() for i, arg in enumerate(pt): initAction.edges.add(Edge(pc, arg, i)) if len(pt) > 0: initAction.elements.add(pc) initAction.edges.add(Edge(initAction.root, pc, 'effect-of'))
def litFromArg(arg, DG): neg = True if arg.key == 'not': neg = False arg = arg.children[0] # arg 2 is written out lit_name = arg.key lit_elm = Literal(name=lit_name, arg_name=lit_name + str(uuid4())[19:23], num_args=len(arg.children), truth=neg) for i, ch in enumerate(arg.children): e_i = whichElm(ch.key.name, DG) DG.edges.add(Edge(lit_elm, e_i, i)) return lit_elm
def build_literal(literal, schema): predicate = literal.key # base case - its a var! if type(predicate) is not str: arg = get_arg_from_op(predicate, schema) return arg if len(literal.children) == 0 and predicate != '-': arg = get_arg_from_op_with_string(literal.key, schema) if arg is not None: return arg # return arg if hasattr(schema, "constants"): # pass if predicate in schema.constants.keys(): arg = schema.constants[predicate] return arg # recursive case - it's not a var! term_list = [] for child in literal.children: term = build_literal(child, schema) if term is None: continue term_list.append(term) # check negate and remove link as needed if len(term_list) == 1 and predicate == "not": lit = term_list[0] # special rules for non-equality constraints if lit.name in {'equals', '=', 'equal'}: compile_nonequality(lit, schema) return None lit.truth = False return lit lit = Literal(name=predicate, num_args=len(term_list), truth=True) schema.elements.add(lit) for i, term in enumerate(term_list): schema.edges.add(Edge(lit, term, i)) return lit
def filter_and_add_orderings(planets, RQ): orderings = RQ.OrderingGraph.edges indices = [] for i in range(len(planets)): # filter None Planets, which are scratched possible worlds if planets[i] is None: continue # add orderings if len(orderings) > 0: GtElm = planets[i].getElementById planets[i].OrderingGraph.edges = {Edge(GtElm(ord.source.ID), GtElm(ord.sink.ID), '<') for ord in orderings} indices.append(i) planets[:] = [planets[i] for i in indices]
def build_op_from_arg(condition, decomp_graph): """ e.g. (= ?call (call ?c)) e.g. (= ?n2 (run ?c2 ?p4 ?p3)) e.g. (= ?end-master (virtual-shot scene-master-shot)) """ # the original decomposition step argument step_var = get_arg_from_arg_name(condition.Args[0].arg_name, decomp_graph) # the literal assigning the decomposition step variable step_as_literal = Condition.subgraph(decomp_graph, condition.Args[1]) step_var.name = step_as_literal.name for i, step_arg in enumerate(step_as_literal.Args): decomp_graph.edges.add(Edge(step_var, step_arg, i))
def addEdge(self, source, sink): if self.isPath(source, sink): return self.elements.add(source) self.elements.add(sink) self.edges.add(Edge(source, sink, '<')) if self.isCntgPath(source, sink): return # check cntg_source of sink cntg_of_sink = self.get_source_of_cntg(sink) if cntg_of_sink != sink and cntg_of_sink != source: self.addEdge(source, cntg_of_sink) cntg_of_source = self.get_sink_of_cntg(source) if cntg_of_source != source and cntg_of_source != sink: self.addEdge(cntg_of_source, sink)
def makeLit(formula, parent, relationship, elements, edges, bit=None, noAdd=None): if bit == None: bit = True if noAdd == None: noAdd = False num_children = len(formula.children) lit = Literal(name=formula.key, num_args=num_children, truth=bit) if not noAdd: elements.add(lit) edges.add(Edge(parent, lit, relationship)) return lit, formula
def process_subplan(gsub, new_elms, new_edges, new_ords, new_links, new_decomps): """ Recursively add elements (step-typed elements added to arg_dict) Orderings, and Causal Links""" new_elms.update(gsub.elements) new_edges.update(gsub.edges) new_ords.extend(gsub.OrderingGraph.edges) new_links.extend(gsub.CausalLinkGraph.edges) new_decomps.extend([ Edge(gsub.root, elm, "<") for elm in gsub.elements if type(elm) == Operator ]) for step in gsub.Step_Graphs: if hasattr(step, "ground_subplan"): for elm in step.ground_subplan.elements: if elm not in new_elms and type(elm) == Operator: elm.arg_name = str(uuid4()) + elm.arg_name process_subplan(step.ground_subplan, new_elms, new_edges, new_ords, new_links)
def evalActionParams(params, op_graph): for i, parameter in enumerate(params): # parameters are list if 'character' in parameter.types: arg = Actor(typ='character', arg_name=parameter.name) op_graph.elements.add(arg) elif 'actor' in parameter.types: arg = Actor(typ='actor', arg_name=parameter.name) op_graph.elements.add(arg) elif 'person' in parameter.types: arg = Actor(typ='person', arg_name=parameter.name) op_graph.elements.add(arg) else: arg_type = next(iter(parameter.types)) if arg_type in {'lit', 'literal'}: arg_type = 'Condition' arg = Argument(typ=arg_type, arg_name=parameter.name) op_graph.elements.add(arg) op_graph.edges.add(Edge(op_graph.root, arg, i))
def UnifyActions(self, P, G): # Used by Plannify NG = G.deepcopy(replace_internals=True) for edge in list(NG.edges): if edge.sink.replaced_ID == -1: sink = copy.deepcopy(edge.sink) sink.replaced_ID = edge.sink.ID self.elements.add(sink) else: sink = P.getElmByRID(edge.sink.replaced_ID) if sink is None: sink = copy.deepcopy(edge.sink) self.elements.add(sink) source = P.getElmByRID(edge.source.replaced_ID) if source is None: source = copy.deepcopy(edge.source) self.elements.add(source) self.edges.add(Edge(source, sink, edge.label))
def __init__(self, position, link, GL): """ @param position: in list of links of Planet @param link: ground steps @param Plan: Plan containing link @param GL: ground step library """ self.position = position self.source = link.source self.sink = link.sink self.condition = link.label #LinkLib is a library of potential conditions, just 1 if already specified self._links = [] if not link.label.arg_name is None: #linked-by self._links = [Edge(link.source, link.sink, self.condition)] else: # add new condition for each potential condition # "effect" mentioned in method below to emphasize whose condition becomes dependency self._links = GL.getPotentialEffectLinkConditions(link.source, link.sink)
def Groundify(Planets, GL, has_links): print('...Groundify - Unifying Actions with GL') for i, Planet in enumerate(Planets): print("... Planet {}".format(i)) for Step in Planet.Step_Graphs: print('... Unifying {} with {}'.format(Step, GL[Step.stepnumber])) # Unify Actions (1) swaps step graphs with ground step Planet.UnifyActions(Step, GL[Step.stepnumber]) if not has_links: return Planets print('...Groundify - Creating Causal Links') Discovered_Planets = [] for Plan in Planets: #print(Plan) Libs = [LinkLib(i, link, GL) for i, link in enumerate(Plan.CausalLinkGraph.edges)] #LW = [plan1 [link1.condition, link2.condition,..., link-n.condition], # plan2 [link1.condition, link2.condition, ..., link-m.condition], # plan-k [l1,...,lz]] LW = productByPosition(Libs) for lw in LW: # create new Planet ("discovered planet") for each linkworld. NP = Plan.deepcopy() for _link in list(lw): pre_token = GL.getConsistentPrecondition(Action.subgraph(NP, _link.sink), _link.label) #label = NP.getElementByID(_link.label.ID) if pre_token != _link.label: NP.ReplaceSubgraphs(pre_token, _link.label) NP.CausalLinkGraph.edges.remove(_link) NP.CausalLinkGraph.edges.add(Edge(_link.source, _link.sink, Condition.subgraph(NP, _link.label))) Discovered_Planets.append(NP) return Discovered_Planets
def build_decomp(dformula, dparams, dschema, op_graphs): existing_args = 0 if hasattr(dschema, "Args"): existing_args = len(dschema.Args) for i, arg in enumerate(dparams): dschema.elements.add(arg) dschema.edges.add(Edge(dschema.root, arg, existing_args + i)) if dformula.key != "and": literal = build_literal(dformula, dschema) if literal is None: raise ValueError("literal is None") compile_decomp_literal(literal, dschema, op_graphs) return dschema for child in dformula.children: literal = build_literal(child, dschema) if literal is None: continue compile_decomp_literal(literal, dschema, op_graphs) return dschema
def test_detect_cycle(self): Elms = [ Element(ID=0, name='0'), Element(ID=1, name='1'), Element(ID=2, name='2'), Element(ID=3, name='3') ] edges = { Edge(Elms[0], Elms[1], '<'), Edge(Elms[0], Elms[2], '<'), Edge(Elms[0], Elms[3], '<'), Edge(Elms[2], Elms[1], '<'), Edge(Elms[3], Elms[1], '<') } G = Graph(ID=10, typ='test', Elements=set(Elms), Edges=edges) OG = OrderingGraph(ID=5, Elements=G.elements, Edges=G.edges) assert (not OG.detectCycle()) OG.edges.add(Edge(Elms[1], Elms[0], '<')) assert (OG.detectCycle())
def groundDecompStepList(doperators, GL, stepnum=0, height=0): gsteps = [] print('...Creating Ground Decomp Steps') for op in doperators: #Subplans = Plannify(op.subplan, GL) print('processing operator: {}'.format(op)) try: sub_plans = Plannify(op.subplan, GL, height) except: continue for sp in sub_plans: GDO = copy.deepcopy(op) GDO.is_decomp = True if not rewriteElms(GDO, sp, op): continue GDO.root.is_decomp = True # swap constructor IDs and replaced_IDs GDO._replaceInternals() GDO.replaceInternals() # Now create dummy init step and goal step dummy_init = Action(name='begin:' + str(GDO.name)) dummy_init.has_cndt = False dummy_init.root.stepnumber = stepnum for condition in GDO.Preconditions: dummy_init.edges.add( Edge(dummy_init.root, condition.root, 'effect-of')) dummy_init.edges.update(condition.edges) dummy_init.elements.update(condition.elements) gsteps.append(dummy_init) stepnum += 1 dummy_goal = Action(name='finish:' + str(GDO.name)) dummy_goal.is_cndt = False dummy_goal.root.stepnumber = stepnum for condition in GDO.Effects: dummy_goal.edges.add( Edge(dummy_goal.root, condition.root, 'precond-of')) dummy_goal.edges.update(condition.edges) dummy_goal.elements.update(condition.elements) gsteps.append(dummy_goal) stepnum += 1 GDO.sub_dummy_init = dummy_init GDO.sub_dummy_goal = dummy_goal GDO.ground_subplan = sp GDO.root.stepnumber = stepnum sp.root = GDO.root stepnum += 1 GDO.height = height + 1 GDO.root.height = height + 1 # important to add init and goal steps first gsteps.append(GDO) return gsteps
def addEdge(self, source, sink, condition): self.elements.add(source) self.elements.add(sink) new_link = Edge(source, sink, condition) self.edges.add(new_link) return new_link
def groundDecompStepList(doperators, GL, stepnum=0, height=0): gsteps = [] print('...Creating Ground Decomp Steps') for op in doperators: #Subplans = Plannify(op.subplan, GL) print('processing operator: {}'.format(op)) try: sub_plans = Plannify(op.subplan, GL, height) except: continue for sp in sub_plans: GDO = copy.deepcopy(op) GDO.is_decomp = True # rewrites operator arguments based on groundings of sub-plan, provides alternatives possible_alternatives = rewriteElms(GDO, sp, op, GL.objects, GL.object_types, height + 1) if not possible_alternatives: continue gdos = [] if type(possible_alternatives) == bool: gdos.append(GDO) else: for gdo in possible_alternatives: gdos.append(gdo) for gdo in gdos: gdo.root.is_decomp = True # swap constructor IDs and replaced_IDs gdo._replaceInternals() gdo.replaceInternals() # Now create dummy init step and goal step dummy_init = Action(name='begin:' + str(gdo.name)) dummy_init.has_cndt = False dummy_init.root.stepnumber = stepnum for condition in gdo.Preconditions: dummy_init.edges.add( Edge(dummy_init.root, condition.root, 'effect-of')) dummy_init.edges.update(condition.edges) dummy_init.elements.update(condition.elements) gsteps.append(dummy_init) stepnum += 1 dummy_goal = Action(name='finish:' + str(gdo.name)) dummy_goal.is_cndt = False dummy_goal.root.stepnumber = stepnum for condition in gdo.Effects: dummy_goal.edges.add( Edge(dummy_goal.root, condition.root, 'precond-of')) dummy_goal.edges.update(condition.edges) dummy_goal.elements.update(condition.elements) gsteps.append(dummy_goal) stepnum += 1 gdo.sub_dummy_init = dummy_init gdo.sub_dummy_goal = dummy_goal gdo.ground_subplan = copy.deepcopy(sp) gdo.root.stepnumber = stepnum gdo.ground_subplan.root = gdo.root stepnum += 1 gdo.height = height + 1 gdo.root.height = height + 1 # important to add init and goal steps first gsteps.append(gdo) # print('Creating ground step w/ height {}, h={}'.format(gdo, height)) return gsteps
def addCntg(self, source, sink): self.addEdge(source, sink) self.edges.add(Edge(source, sink, "cntg"))
def decorateElm(child, DG): if child.key == 'name': elm = whichElm(child.children[0].key.name, DG) elm.name = child.children[1].key elif child.key == 'nth-step-arg' or child.key == 'nth-lit-arg': args = child.children label = int(args[0].key) parent_elm = whichElm(args[1].key.name, DG) child_elm = whichElm(args[2].key.name, DG) DG.edges.add(Edge(parent_elm, child_elm, label)) elif child.key == 'includes': arg1, arg2 = child.children DG.edges.add( Edge(whichElm(arg1.key.name, DG), whichElm(arg2.key.name, DG), 'arg-of')) elif child.key == 'truth': lit, value = child.children lit = whichElm(lit.key.name, DG) if value.key in {'t', '1', 'true', 'yes', 'y'}: lit.truth = True else: lit.truth = False elif child.key == 'effect' or child.key == 'precond': label = child.key + '-of' arg1, arg2 = child.children if len(arg2.children) > 0: child_elm = litFromArg(arg2, DG) else: child_elm = whichElm(arg2.key.name, DG) DG.edges.add(Edge(whichElm(arg1.key.name, DG), child_elm, label)) elif child.key == 'linked': arg1, arg2 = child.children dep = Literal(arg_name='link-condition' + str(uuid4())[19:23]) Src = whichElm(arg1.key.name, DG) Snk = whichElm(arg2.key.name, DG) DG.CausalLinkGraph.addEdge(Src, Snk, dep) DG.edges.add(Edge(Snk, dep, 'precond-of')) DG.edges.add(Edge(Src, dep, 'effect-of')) elif child.key == '<': arg1, arg2 = child.children DG.OrderingGraph.addEdge(whichElm(arg1.key.name, DG), whichElm(arg2.key.name, DG)) elif child.key == 'linked-by': src, snk, by = child.children try: dep = whichElm(by.key.name, DG) except: dep = litFromArg(by, DG) Src = whichElm(src.key.name, DG) Snk = whichElm(snk.key.name, DG) DG.CausalLinkGraph.addEdge(Src, Snk, dep) DG.edges.add(Edge(Snk, dep, 'precond-of')) DG.edges.add(Edge(Src, dep, 'effect-of')) elif child.key == 'consents': arg1, arg2, by = child.children DG.edges.add(Edge(whichElm(arg1.key.name, arg2.key.name, 'actor-of'))) elif child.key in {'occurs', '=', 'is', 'equals'}: # then, first argument is step element name and second argument is an operator with children args stepFromArg(child, DG) elif child.key == 'is-state': litFromArg(child, DG) else: raise NameError( 'No definition implemented for decomp predicate {}'.format( child.key))