def _process(t): """Encode tree *t* and return the string.""" # tree transformations if normalize_options['make_variables']: t.reset_variables(normalize_options['make_variables']) if normalize_options['canonicalize_roles']: t = transform.canonicalize_roles(t, model) if normalize_options['rearrange'] == 'canonical': layout.rearrange(t, key=model.canonical_order) elif normalize_options['rearrange'] == 'random': layout.rearrange(t, key=model.random_order) g = layout.interpret(t, model) # graph transformations if normalize_options['reify_edges']: g = transform.reify_edges(g, model) if normalize_options['dereify_edges']: g = transform.dereify_edges(g, model) if normalize_options['reify_attributes']: g = transform.reify_attributes(g) if normalize_options['indicate_branches']: g = transform.indicate_branches(g, model) if triples: return codec.format_triples(g.triples, indent=bool( format_options.get('indent', True))) else: return codec.encode(g, **format_options)
def _process_out(g, model, normalize_options): if normalize_options['reconfigure']: key, kwargs = normalize_options['reconfigure'] t = layout.reconfigure(g, key=key, **kwargs) g = layout.interpret(t, model) else: t = layout.configure(g, model=model) if normalize_options['rearrange']: key, kwargs = normalize_options['rearrange'] layout.rearrange(t, key=key, **kwargs) if normalize_options['make_variables']: t.reset_variables(normalize_options['make_variables']) return t
def test_rearrange(): t = codec.parse(''' (a / alpha :ARG0 (b / beta :ARG0 (g / gamma) :ARG1 (d / delta)) :ARG0-of d :ARG1 (e / epsilon))''') rearrange(t, model.original_order) assert codec.format(t) == ( '(a / alpha\n' ' :ARG0 (b / beta\n' ' :ARG0 (g / gamma)\n' ' :ARG1 (d / delta))\n' ' :ARG0-of d\n' ' :ARG1 (e / epsilon))') rearrange(t, model.random_order) assert codec.format(t) == ( '(a / alpha\n' ' :ARG0-of d\n' ' :ARG1 (e / epsilon)\n' ' :ARG0 (b / beta\n' ' :ARG0 (g / gamma)\n' ' :ARG1 (d / delta)))') rearrange(t, model.canonical_order) assert codec.format(t) == ( '(a / alpha\n' ' :ARG0 (b / beta\n' ' :ARG0 (g / gamma)\n' ' :ARG1 (d / delta))\n' ' :ARG1 (e / epsilon)\n' ' :ARG0-of d)')