print('RAISED U') raised_u = raise_edge(compressed, 'U', ['L', 'H', 'P', 'S', 'A', 'D'], label_dict=labels) labels = update_id_labels(raised_u, labels) irtg_raised_u = edge2irtg(raised_u, labels) print(irtg_raised_u) print('RAISED F') raised_f = raise_edge( raised_u, 'F', ['L', 'H', 'P', 'S', 'A', 'A1', 'A2', 'A3', 'A4', 'A5', 'D'], label_dict=labels) labels = update_id_labels(raised_f, labels) irtg_raised_f = edge2irtg(raised_f, labels) print(irtg_raised_f) print('Raised D') raised_d = raise_edge( raised_f, 'D', ['L', 'H', 'P', 'S', 'A' 'A1', 'A2', 'A3', 'A4', 'A5'], label_dict=labels) labels = update_id_labels(raised_d, labels) irtg_raised_d = edge2irtg(raised_d, labels) print(irtg_raised_d) lowered = lower_edge(raised_d) irtg_lowered = edge2irtg(lowered, labels) print('Lowered') print(irtg_lowered) roots = get_roots(lowered) print('________________________________-')
id = mrp_dict['id'] framework = mrp_dict['framework'] flavor = mrp_dict['flavor'] time = mrp_dict['time'] version = mrp_dict['version'] tops = mrp_dict['tops'] if len(tops) > 0: top = tops[0] else: top = None node_ids = get_id2lex(mrp_dict) edges = get_mrp_edges(mrp_dict) node_ids, edges = update_id_labels(edges, node_ids) lowered = lower_edge(edges) decompressed = decompress_c(lowered, node_ids) revised_top, with_h = add_h(decompressed, node_ids, top) mrp_post_processed['tops'] = [revised_top] mrp_post_processed['id'] = id mrp_post_processed['framework'] = framework mrp_post_processed['flavor'] = flavor mrp_post_processed['time'] = time mrp_post_processed['version'] = version mrp_post_processed['input'] = input node_ids, with_h = update_id_labels(with_h, node_ids) mrp_nodes = get_terminal_nodes(mrp_dict) for node in node_ids.keys(): if node_ids[node] == 'Non-Terminal': mrp_nodes.append({'id': node}) mrp_post_processed['nodes'] = mrp_nodes
import sys import ast import json from get_edges_from_mrp import get_id2lex, get_mrp_edges from move_edges import lower_edge, raise_edge from edge_to_irtg import edge2irtg from convert_irtg_to_mrp import get_edges, get_id2lex, get_input, get_mrp_edges, get_nodes, get_tops, irtg2mrp from process_c import compress_c_edge, decompress_c infile = sys.argv[1] outfile = sys.argv[2] non_deducible = ["id", "flavor", "framework", "version", "time"] with open(infile, 'r') as f: for line in f: mrp_dict = json.loads(line) extras = {} for category in mrp_dict.keys(): if category in non_deducible: extras[category] = mrp_dict[category] edges = get_mrp_edges(mrp_dict) labels = get_id2lex(mrp_dict) compressable, total, compressed_c = compress_c_edge(edges) lowered_d = lower_edge(compressed_c, 'D', ['P', 'S'], mark=True) preprocessed_mrp = irtg2mrp(lowered_d, labels) for key in extras.keys(): preprocessed_mrp[key] = extras[key] with open(outfile, 'a') as out: out.write(json.dumps(preprocessed_mrp) + '\n')