def process_cf_match(self, cf_match, indent, report): if cf_match == None or len(cf_match) == 0: return report parser = None production = None [gname, pname] = cf_match[0].split(":") parser = self.get_parser(gname) production = parser.getGrammarForUnit(pname) new_result_forest_0 = [] new_result_forest_1 = [] text_tree_0 = report["result_forest_0"][0] params0 = {"pos": 1, "pos2type": [], "pos2ref": [], "stack": [], "refKey": parser.refKey} for parse_tree, s, e in production.scanString(text_tree_0): t0 = parser.normalizeParseTree(parse_tree.asList()) [t0, params0] = TD.postorder_traverse(t0, params0, self.set_position_as_id) [t0, params0] = TD.postorder_traverse(t0, params0, self.compute_type_list) [t0, params0] = TD.preorder_traverse(t0, params0, self.compute_references) [t0, params0] = TD.postorder_traverse(t0, params0, self.compute_reference_list) report["result_parse_tree_0"].append(t0) report["pos2types0"].append(params0["pos2type"]) report["pos2refs0"].append(params0["pos2ref"]) text_tree_1 = report["result_forest_1"][0] params1 = {"pos": 1, "pos2type": [], "pos2ref": [], "stack": [], "refKey": parser.refKey} for parse_tree, s, e in production.scanString(text_tree_1): t1 = parser.normalizeParseTree(parse_tree.asList()) [t1, params1] = TD.postorder_traverse(t1, params1, self.set_position_as_id) [t1, params1] = TD.postorder_traverse(t1, params1, self.compute_type_list) [t1, params1] = TD.preorder_traverse(t1, params1, self.compute_references) [t1, params1] = TD.postorder_traverse(t1, params1, self.compute_reference_list) report["result_parse_tree_1"].append(t1) report["pos2types1"].append(params1["pos2type"]) report["pos2refs1"].append(params1["pos2ref"]) return report
def process_cf_match(self, cf_match, indent, report): if cf_match == None or len(cf_match) == 0: return report parser = None production = None [gname, pname] = cf_match[0].split(':') parser = self.get_parser(gname) production = parser.getGrammarForUnit(pname) text_tree_0 = report['result_forest_0'][0] params0 = {'pos': 1, 'pos2type': [], 'pos2ref': [], 'stack': [], 'refKey': parser.refKey} for parse_tree, s, e in production.scanString(text_tree_0): t0 = parser.normalizeParseTree(parse_tree.asList()) [t0, params0] = TD.postorder_traverse(t0, params0, self.set_position_as_id) [t0, params0] = TD.postorder_traverse(t0, params0, self.compute_type_list) [t0, params0] = TD.preorder_traverse(t0, params0, self.compute_references) [t0, params0] = TD.postorder_traverse(t0, params0, self.compute_reference_list) report['result_parse_tree_0'].append(t0) report['pos2types0'].append(params0['pos2type']) report['pos2refs0'].append(params0['pos2ref']) text_tree_1 = report['result_forest_1'][0] params1 = {'pos': 1, 'pos2type': [], 'pos2ref': [], 'stack': [], 'refKey': parser.refKey} for parse_tree, s, e in production.scanString(text_tree_1): t1 = parser.normalizeParseTree(parse_tree.asList()) [t1, params1] = TD.postorder_traverse(t1, params1, self.set_position_as_id) [t1, params1] = TD.postorder_traverse(t1, params1, self.compute_type_list) [t1, params1] = TD.preorder_traverse(t1, params1, self.compute_references) [t1, params1] = TD.postorder_traverse(t1, params1, self.compute_reference_list) report['result_parse_tree_1'].append(t1) report['pos2types1'].append(params1['pos2type']) report['pos2refs1'].append(params1['pos2ref']) return report
def xudiff(self, xPath, report, init_params): result = [] parser = parsers.XPathParser() parses = parser.xPath.scanString(xPath) for p, s, e in parses: result.append(p) empty_report = {'id': None, 'type': None, 'children': [], 'label': None} report = self.process_xpath(result[0].path, "", report) if (type(report['result_parse_tree_0']) == list and len(report['result_parse_tree_0']) > 0): t0 = report['result_parse_tree_0'][0] else: t0 = empty_report if (type(report['result_parse_tree_1']) == list and len(report['result_parse_tree_1']) > 0): t1 = report['result_parse_tree_1'][0] else: t1 = empty_report params = TD.compute_tree_dist(t0, t1, init_params) report['l0'] = params['l1'] report['l1'] = params['l2'] report['labels0'] = params['labels1'] report['labels1'] = params['labels2'] report['tree_dist'] = params['tree_dist'] report['edit_ops'] = params['edit_ops'] report['update_edit_cost'] = params['update_edit_cost'] report['insert_edit_cost'] = params['insert_edit_cost'] report['delete_edit_cost'] = params['delete_edit_cost'] report['forest_dist'] = params['forest_dist'] return report
def xudiff(self, xPath, report, init_params): result = [] parser = parsers.XPathParser() parses = parser.xPath.scanString(xPath) for p, s, e in parses: result.append(p) report = self.process_xpath(result[0].path, "", report) t0 = report["result_parse_tree_0"][0] t1 = report["result_parse_tree_1"][0] params = TD.compute_tree_dist(t0, t1, init_params) report["l0"] = params["l1"] report["l1"] = params["l2"] report["labels0"] = params["labels1"] report["labels1"] = params["labels2"] report["tree_dist"] = params["tree_dist"] report["edit_ops"] = params["edit_ops"] report["update_edit_cost"] = params["update_edit_cost"] report["insert_edit_cost"] = params["insert_edit_cost"] report["delete_edit_cost"] = params["delete_edit_cost"] report["forest_dist"] = params["forest_dist"] return report