def text_results(self, index, searchword=""): path = files.experiment_results_file_path(self) full_results = [] if (searchword == ""): excerpt = subprocess.check_output([ "sed", "-n", str(index + 1) + "," + str(index + 33) + "p", path ]).split("\n") for line in excerpt: line = line.strip() if len(line) > 0: full_results.append(line) full_results.pop() full_results.pop() try: labels, values = zip( *[s.strip().rsplit(None, 1) for s in full_results]) except ValueError: labels = [] values = [] else: values = [ v if v == '***OOV***' else (abs(float(v))) for v in values ] return [labels, {self.lm.name: values}] else: excerpt = subprocess.check_output(["grep", "-n", searchword, path]).split("\n") for line in excerpt: if (len(line) > 0): line = line.strip().split(":") full_results.append(int(line[0])) return full_results
def search_results(self, searchword=""): full_results = [] path = files.experiment_results_file_path(self) excerpt = subprocess.check_output(["grep", "-n", searchword, path]).split("\n") for line in excerpt: if (len(line) > 0): line = line.strip().split(":") full_results.append(int(line[0])) return full_results
def lsvlm_results(self): lsvlm_output = files.tail(files.experiment_results_file_path(self), 2).strip() #lsvlm_output = lsvlm_output.split("\n") split = re.findall(r"([A-Za-z ]+:? ([0-9\.]+( \(\d+.\d+%\))?|-nan))", lsvlm_output) stats = [ s[0].strip().replace(":", "").replace(" (", "(").rsplit(" ", 1) for s in split ] results = {} for [key, value] in stats: results[key] = value return results
def get_contexts(self, results): path = files.experiment_results_file_path(self) contextStart = [] contextEnd = [] for num in results: if (num < 11): num = 11 elif (num > self.totalWords() - 11): num = self.totalWords - 1 excerptStart = subprocess.check_output( ["sed", "-n", str(num - 10) + "," + str(num - 1) + "p", path]).split("\n") excerptEnd = subprocess.check_output( ["sed", "-n", str(num + 1) + "," + str(num + 10) + "p", path]).split("\n") for line in excerptStart: contextStart.append(line.split()[0]) for line in excerptEnd: contextEnd.append(line.split()[0]) return contextStart, contextEnd
def lsvlm_results(self): lsvlm_output = files.tail(files.experiment_results_file_path(self), 2) lsvlm_output = lsvlm_output.split("\n")[0] split = re.findall(r"([A-Za-z ]+:? [0-9\.]+( \(\d+.\d+%\))?)", lsvlm_output) return [s[0].strip().replace(":", "").replace(" (", "(").rsplit(" ", 1) for s in split]
def results_file(self): path = files.experiment_results_file_path(self) return files.file_contents(path)