<commit_before>import Foundation

/**
Partial validation of email

Email addresses are often requested as input to website as user identification for the purpose of data validation.
An email address is generally recognized as having two parts joined with an at-sign (@). However, the technical 
specification detailed in RFC 822 and subsequent RFCs are more extensive, offering complex and strict restrictions.
It is impossible to match these restrictions with a single technique. Using regular expressions results in 
long patterns giving incomplete results.

http://en.wikipedia.org/wiki/Email_address
*/
public class EmailSpecification: CompositeSpecification {
	private let specification: RegularExpressionSpecification
	
	override init() {
		self.specification = RegularExpressionSpecification(pattern: emailRegularExpression)
		super.init()
	}

	public override func isSatisfiedBy(candidate: Any?) -> Bool {
		return specification.isSatisfiedBy(candidate)
	}

	// RFC5322 address specification
	// http://tools.ietf.org/html/rfc5322#section-3.4
	// Taken from http://stackoverflow.com/a/1149894/78336
	private let emailRegularExpression =
		"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}" +
		"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" +
		"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-" +
		"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5" +
		"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" +
		"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" +
		"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"<commit_msg>Added public keyword lots of places<commit_after>import Foundation

/**
Partial validation of email

Email addresses are often requested as input to website as user identification for the purpose of data validation.
An email address is generally recognized as having two parts joined with an at-sign (@). However, the technical 
specification detailed in RFC 822 and subsequent RFCs are more extensive, offering complex and strict restrictions.
It is impossible to match these restrictions with a single technique. Using regular expressions results in 
long patterns giving incomplete results.

http://en.wikipedia.org/wiki/Email_address
*/
public class EmailSpecification: CompositeSpecification {
	private let specification: RegularExpressionSpecification
	
	public override init() {
		self.specification = RegularExpressionSpecification(pattern: emailRegularExpression)
		super.init()
	}

	public override func isSatisfiedBy(candidate: Any?) -> Bool {
		return specification.isSatisfiedBy(candidate)
	}

	// RFC5322 address specification
	// http://tools.ietf.org/html/rfc5322#section-3.4
	// Taken from http://stackoverflow.com/a/1149894/78336
	private let emailRegularExpression =
		"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}" +
		"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\" +
		"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-" +
		"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5" +
		"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-" +
		"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21" +
		"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"
{'fraction_non_alphanumeric': 0.2370982011206134, 'fraction_numerical': 0.07136537894426423, 'mean_word_length': 3.6786206896551725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7566344', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1348, 'n_words': 241}