<commit_before>#!/usr/bin/python

# Arguments:
# <sample_mbox.csv> <filter_out.csv> <phrases.csv> <file_to_write_occurances_of_phrases.csv>(by default "phrase_occurances.csv")


import pandas as pd
import sys
import re
from collections import defaultdict

def search_for_phrases_in(questions, phrases):
	phrases_count = defaultdict(lambda: 0)
	for client_email, client_questions in questions.iteritems():
		for question, amount in client_questions.items():
			for phrase in phrases:
				for m in re.finditer(phrase, question):
					phrases_count[phrase] += amount
	return phrases_count 

def search_for_questions(data, filter_out_emails, start_questions = ["How ", "Why ", "What ", "Where "]):
	questions = defaultdict(lambda: dict())
	for index in range(data.shape[0]):
		body = str(data.iloc[index].values[-1])
		for email in filter_out_emails:
			email = str(email).strip()
			if len(email) > len(body):
				break
			for m in re.finditer("<" + email + ">", body):
				body = body[:m.start()]
				break
		message_from = data.iloc[index].values[1]
		for m in re.finditer("<.+@.+>", message_from):
			message_sender = message_from[m.start() + 1: m.end() - 1]
			break

		for start_question in start_questions:
			for m in re.finditer(start_question + ".+\?", str(body)):
				questions[message_sender][body[m.start():m.end()]] = 1
		
	return questions

def write_questions(questions):
	with open("FAQ.csv", "wb") as write_questions:
		for client_mail, client_questions in questions.iteritems():
			[write_questions.write(question + "\r\n") for question in client_questions.keys()]
	return None
<commit_msg>Add wildcard fix<commit_after>#!/usr/bin/python

# Arguments:
# <sample_mbox.csv> <filter_out.csv> <phrases.csv> <file_to_write_occurances_of_phrases.csv>(by default "phrase_occurances.csv")


import pandas as pd
import sys
import re
from collections import defaultdict

def search_for_phrases_in(questions, phrases):
	phrases_count = defaultdict(lambda: 0)
	for client_email, client_questions in questions.iteritems():
		for question, amount in client_questions.items():
			for phrase in phrases:
				for m in re.finditer(phrase, question):
					phrases_count[phrase] += amount
	return phrases_count 

def search_for_questions(data, filter_out_emails, start_questions = ["How ", "Why ", "What ", "Where "]):
	questions = defaultdict(lambda: dict())
	for index in range(data.shape[0]):
		body = str(data.iloc[index].values[-1])
		for email in filter_out_emails:
			email = str(email).strip()
			if email[0:2] == "*@":
				email = email[1:]
			if len(email) > len(body):
				break
			for m in re.finditer(email, body):
				body = body[:m.start()]
				break
		message_from = data.iloc[index].values[1]
		for m in re.finditer("<.+@.+>", message_from):
			message_sender = message_from[m.start() + 1: m.end() - 1]
			break

		for start_question in start_questions:
			for m in re.finditer(start_question + ".+\?", str(body)):
				questions[message_sender][body[m.start():m.end()]] = 1
		
	return questions

def write_questions(questions):
	with open("FAQ.csv", "wb") as write_questions:
		for client_mail, client_questions in questions.iteritems():
			[write_questions.write(question + "\r\n") for question in client_questions.keys()]
	return None

{'fraction_non_alphanumeric': 0.13850415512465375, 'fraction_numerical': 0.0052323791935980305, 'mean_word_length': 4.772646536412078, 'pattern_counts': {'":': 1, '<': 14, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1256521', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1078, 'n_words': 267}