<commit_before>'use strict';

var fs = require('fs')
	,	path = require('path')
	,	Q = require('q')
	,	unicodeHack = require('../lib/unicode_hack')
	,	langMap = require('./lang-mapping.json')
	,	Spellcheck = require('spellcheck');

function Pasquale () {}

Pasquale.prototype.setLanguage = function(lang) {
	var langPaths = langMap[lang]
		,	dictPath = ''
		, affPath = ''
		, dicPath = '';

	if (!langPaths) throw new Error('No path defined for this language');

	dictPath = path.resolve(__dirname, '../bower_components/Dictionaries');
	affPath = path.join(dictPath, langPaths.aff);
	dicPath = path.join(dictPath, langPaths.dic);

	if (!(affPath.match(/\.aff$/) || dicPath.match(/\.aff$/)))
		throw new Error('.aff and a .dic files must be specified');

	if (!(fs.existsSync(affPath) || fs.existsSync(dicPath)))
		throw new Error('Both of the specified files must exist');

	this.sp = new Spellcheck(affPath, dicPath);
};

Pasquale.prototype.checkTextSpell = function (text) {
	var regex = unicodeHack(/\p{L}+/g)
		,	words = []
		,	scope = this
		,	promises = []
		,	dfd = Q.defer();

	words = text.match(regex);
	if (!words) dfd.resolve([]);

	words.forEach(function (word) {
		if (isNaN(+word)) {
			promises.push(scope.checkWordSpell(word));
		}
	});

	Q.all(promises)
		.then(function (results) {<commit_msg>uses /gi so that we are able to iterate over the matches<commit_after>'use strict';

var fs = require('fs')
	,	path = require('path')
	,	Q = require('q')
	,	unicodeHack = require('../lib/unicode_hack')
	,	langMap = require('./lang-mapping.json')
	,	Spellcheck = require('spellcheck');

function Pasquale () {}

Pasquale.prototype.setLanguage = function(lang) {
	var langPaths = langMap[lang]
		,	dictPath = ''
		, affPath = ''
		, dicPath = '';

	if (!langPaths) throw new Error('No path defined for this language');

	dictPath = path.resolve(__dirname, '../bower_components/Dictionaries');
	affPath = path.join(dictPath, langPaths.aff);
	dicPath = path.join(dictPath, langPaths.dic);

	if (!(affPath.match(/\.aff$/) || dicPath.match(/\.aff$/)))
		throw new Error('.aff and a .dic files must be specified');

	if (!(fs.existsSync(affPath) || fs.existsSync(dicPath)))
		throw new Error('Both of the specified files must exist');

	this.sp = new Spellcheck(affPath, dicPath);
};

Pasquale.prototype.checkTextSpell = function (text) {
	var regex = unicodeHack(/\p{L}+/gi)
		,	scope = this
		,	promises = []
		,	dfd = Q.defer()
		,	match;

	while (match = regex.exec(text), match)
		promises.push(scope.checkWordSpell(match[0]))

	Q.all(promises)
		.then(function (results) {
{'fraction_non_alphanumeric': 0.17770034843205576, 'fraction_numerical': 0.00038714672861014324, 'mean_word_length': 4.199195171026157, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1486376', 'n_tokens_mistral': 963, 'n_tokens_neox': 912, 'n_words': 202}