def make_graph(self, instr_file): """Creates a graph from the given instruction file""" err_msg = "couldn't read instructions" self.uniquified = False with utils.ringo_open(instr_file, err_msg) as f: # Execute query try: for line in f: tokens = list(utils.get_tokens(line)) { 'SRC': self.set_src, 'DST': self.set_dst, 'EDGE_ATTR': self.set_edge_attr, 'FLAGS': self.set_flags, 'LOAD': self.load, 'START': self.start, 'LABEL': self.label, 'JOIN': self.join, 'SELECT': self.select, 'COUNT': self.count, 'GROUP': self.group, 'ORDER': self.order }[tokens[0]](*tokens[1:]) except KeyError: raise InvalidInstructionException('Incomplete query') self.build_graph() return
def write_instr_file(self): """Creates the instruction file to be passed to the graph engine (.i file)""" err_msg = "couldn't write query" with utils.ringo_open(self.instr_filename, err_msg, "w") as f: self.write_attr(f, "SRC", [self.src_col] + self.src_attr) self.write_attr(f, "DST", [self.dst_col] + self.dst_attr) # TODO: Depends on the flags! There might be some logic to put here self.write_attr(f, "EDGE_ATTR", self.edge_attr) self.write_attr(f, "FLAGS", self.flags) for instr in self.instructions(): f.write(instr.name + " " + " ".join(instr.args) + "\n")
def write_instr_file(self): """Creates the instruction file to be passed to the graph engine (.i file)""" err_msg = "couldn't write query" with utils.ringo_open(self.instr_filename, err_msg, "w") as f: self.write_attr(f, "SRC", [self.src_col] + self.src_attr) self.write_attr( f, "DST", [self.dst_col] + self.dst_attr ) # TODO: Depends on the flags! There might be some logic to put here self.write_attr(f, "EDGE_ATTR", self.edge_attr) self.write_attr(f, "FLAGS", self.flags) for instr in self.instructions(): f.write(instr.name + " " + " ".join(instr.args) + "\n")
def add_table(self, filename, tablename = None): """ Adds a new table for the dataset. filename is the name of the file containing the table data, and tablename is an optional name for the table. If no name is given, the table name is derived from the name of the file (without the extension). The file should be a tab-separated file, and the first line of the file should contain the column names. """ if tablename is None: tablename = utils.get_name_for_table(filename) err_msg = "cannot load table" with utils.ringo_open(filename, err_msg): #if tablename in self.tablefiles: # print "Table with this name already exists. Changing the source file" self.tablefiles[tablename] = filename
def add_table(self, filename, tablename=None): """ Adds a new table for the dataset. filename is the name of the file containing the table data, and tablename is an optional name for the table. If no name is given, the table name is derived from the name of the file (without the extension). The file should be a tab-separated file, and the first line of the file should contain the column names. """ if tablename is None: tablename = utils.get_name_for_table(filename) err_msg = "cannot load table" with utils.ringo_open(filename, err_msg): #if tablename in self.tablefiles: # print "Table with this name already exists. Changing the source file" self.tablefiles[tablename] = filename
def make_graph(self, filename = None, query = None, keep_instructions = False): """Creates a graph from the given query, or from the current working table / working column if no query has been specified. The query may be passed via a file (with the filename argument) or as a string (via the query argument)""" self.engine.reset() if query is None: with utils.ringo_open(filename) as f: query = f.readlines() query_obj = Query(query, self.tablefiles) if not filename is None: query_obj.instr_filename = filename + ".i" query_obj.write_instr_file() self.check_query(query_obj) self.engine.make_graph(query_obj.instr_filename) if not keep_instructions: os.remove(query_obj.instr_filename)
def make_graph(self, filename=None, query=None, keep_instructions=False): """Creates a graph from the given query, or from the current working table / working column if no query has been specified. The query may be passed via a file (with the filename argument) or as a string (via the query argument)""" self.engine.reset() if query is None: with utils.ringo_open(filename) as f: query = f.readlines() query_obj = Query(query, self.tablefiles) if not filename is None: query_obj.instr_filename = filename + ".i" query_obj.write_instr_file() self.check_query(query_obj) self.engine.make_graph(query_obj.instr_filename) if not keep_instructions: os.remove(query_obj.instr_filename)