def generate_project_kernel(project, cluster_json=None): """ run graph kernel computation """ out_dir = dot.dot_dirs(project)[0] print("Generating kernel for {0} with dot files in {1}.".format(project, out_dir)) kernel_file_path = dot.get_kernel_path(project, out_dir) if cluster_json: print("Using clustering output for node relabeling:") graph_kernel_cmd = ['python', common.get_simprog('precompute_kernel.py'), os.path.join(dot.dot_dir(project), out_dir), kernel_file_path, cluster_json ] common.run_cmd(graph_kernel_cmd, True) else: graph_kernel_cmd = ['python', common.get_simprog('precompute_kernel.py'), os.path.join(dot.dot_dir(project), out_dir), kernel_file_path ] common.run_cmd(graph_kernel_cmd, True) print("Generated kernel file for {0} in {1}.".format(project, kernel_file_path))
def generate_project_kernel(project, cluster_json=None): """ run graph kernel computation """ project_dir = common.get_project_dir(project) dot_dirs = dot.dot_dirs(project) if not dot_dirs: print("No graphs generated for {}".format(project)) return out_dir = dot_dirs[0] kernel_file_path = dot.get_kernel_path(project, out_dir) if cluster_json: graph_kernel_cmd = [ 'python', common.get_simprog('precompute_kernel.py'), project_dir, kernel_file_path, cluster_json ] common.run_cmd(graph_kernel_cmd, 'graphkernel') else: graph_kernel_cmd = [ 'python', common.get_simprog('precompute_kernel.py'), project_dir, kernel_file_path ] common.run_cmd(graph_kernel_cmd, 'graphkernel')
def get_method_map(project_list, include_all=True): dot_to_method_map = {} for project in project_list: project_dot_dirs = [] if include_all: project_dot_dirs = dot.dot_dirs(project) else: project_dot_dirs = [dot.dot_dirs(project)[0]] for output_dir in project_dot_dirs: method_file = dot.get_method_path(project, output_dir) if not os.path.isfile(method_file): print("Cannot find method file for project {0} at {1}".format(project, method_file)) sys.exit(0) with open(method_file, "r") as mf: content = mf.readlines() for line in content: line = line.rstrip() items = line.split('\t') method_name = items[0] method_dot = items[1] method_dot_path = dot.get_dot_path(project, output_dir, method_dot) dot_to_method_map[method_dot_path] = method_name return dot_to_method_map
def get_dot_method_map(proj_lst): dot_method_map = {} for proj in proj_lst: output_dir_lst = dot.dot_dirs(proj) for output_dir in output_dir_lst: method_file = dot.get_method_path(proj, output_dir) with open(method_file, "r") as mf: for line in mf: line = line.rstrip() items = line.split("\t") method_name = items[0] method_dot = items[1] method_dot_path = dot.get_dot_path(proj, output_dir, method_dot) dot_method_map[method_dot_path] = method_name return dot_method_map
def gather_kernels(projects, corpus_kernel_file): print("Gathering kernels from projects {0}".format(" and ".join(projects))) with open(corpus_kernel_file, "w") as corpus_kernel_file_handle: for project in projects: project_dir = common.get_project_dir(project) out_dir = dot.dot_dirs(project)[0] # only consider the first one project_kernel_file_path = dot.get_kernel_path(project, out_dir) if os.path.isfile(project_kernel_file_path): with open(project_kernel_file_path, "r") as fi: corpus_kernel_file_handle.write(fi.read()) else: print ("No kernel file find for project {0}.\n {1} is not a file.".format( project, project_kernel_file_path ))