def add_truth_to_corpus(self): """Add a truth file to the existing fake corpus.""" d = { key: random.choice([HAM_TAG, SPAM_TAG]) for key in self.file_dict.keys() } self.truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) save_classification_to_file(d, self.truth_filepath)
def setUp(self): """Prepare fake corpus with !truth.txt file.""" self.email_dict = create_corpus_dictionary() self.true_class = create_classification_for(self.email_dict.keys()) create_corpus_dir_from_dictionary(self.email_dict) truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) save_classification_to_file(self.true_class, fname=truth_filepath) self.tc = TrainingCorpus(CORPUS_DIR)
def setUp(self): """Prepare fake corpus with !truth.txt file.""" self.email_dict = create_corpus_dictionary() self.true_class = create_classification_for(self.email_dict.keys()) create_corpus_dir_from_dictionary(self.email_dict) truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) save_classification_to_file(self.true_class, fname=truth_filepath) with replaced_open(): self.tc = TrainingCorpus(CORPUS_DIR)
def create_identical_truth_and_prediction_file(): """ Create identical !truth.txt and !prediction.txt files in the corpus directory. Here we assume that the corpus directory already exists. """ # Create an artificial email classification dictionary class_dict = create_classification() # Compile the filepaths truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) pred_filepath = os.path.join(CORPUS_DIR, PREDICTION_FILANAME) # Save the same dictionary as both the !truth.txt and !prediction.txt save_classification_to_file(class_dict, truth_filepath) save_classification_to_file(class_dict, pred_filepath)
def create_inverse_truth_and_prediction_file(): """ Create inverse !truth.txt and !prediction.txt files in the corpus directory. Here we assume that the corpus directory already exists. """ # Create an artificial truth dictionary truth_dict = create_classification() # Create an inverted version of truth_dict pred_dict = invert_classes(truth_dict) # Compile the filepaths truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) pred_filepath = os.path.join(CORPUS_DIR, PREDICTION_FILANAME) # Save the dictionaries in !truth.txt and !prediction.txt, respectively. save_classification_to_file(truth_dict, truth_filepath) save_classification_to_file(pred_dict, pred_filepath)
def create_truth_and_prediction_file(truth_dict, pred_setter): """ Create !truth.txt and !prediction.txt files in the corpus directory. Here we assume that the corpus directory already exists. The pred_setter function must accept the classification dictionary, and must return a dictionary with the same keys and possibly changed values. """ # Create a prediction dictionary pred_dict = pred_setter(truth_dict) # Compile the filepaths truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) pred_filepath = os.path.join(CORPUS_DIR, PREDICTION_FILANAME) # Save the same dictionary as both the !truth.txt and !prediction.txt save_classification_to_file(truth_dict, truth_filepath) save_classification_to_file(pred_dict, pred_filepath)
def create_truth_and_prediction_file(truth_dict, pred_setter): """ Create !truth.txt and !prediction.txt files in the corpus directory. Here we assume that the corpus directory already exists. The pred_setter function must accept the classification dictionary, and must return a dictionary with the same keys and possibly changed values. """ # Create a preiction dictionary pred_dict = pred_setter(truth_dict) # Compile the filepaths truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) pred_filepath = os.path.join(CORPUS_DIR, PREDICTION_FILANAME) # Save the same dictionary as both the !truth.txt and !prediction.txt save_classification_to_file(truth_dict, truth_filepath) save_classification_to_file(pred_dict, pred_filepath)
def add_truth_to_corpus(self): """Add a truth file to the existing fake corpus.""" d = {key: random.choice([HAM_TAG, SPAM_TAG]) for key in self.file_dict.keys()} self.truth_filepath = os.path.join(CORPUS_DIR, TRUTH_FILENAME) save_classification_to_file(d, self.truth_filepath)