Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function cleanDomainFromTitle(splitTitle, url) {
// Search the ends of the title, looking for bits that fuzzy match
// the URL too closely. If one is found, discard it and return the
// rest.
//
// Strip out the big TLDs - it just makes the matching a bit more
// accurate. Not the end of the world if it doesn't strip right.
const { host } = URL.parse(url);
const nakedDomain = host.replace(DOMAIN_ENDINGS_RE, '');
const startSlug = splitTitle[0].toLowerCase().replace(' ', '');
const startSlugRatio = wuzzy.levenshtein(startSlug, nakedDomain);
if (startSlugRatio > 0.4 && startSlug.length > 5) {
return splitTitle.slice(2).join('');
}
const endSlug = splitTitle
.slice(-1)[0]
.toLowerCase()
.replace(' ', '');
const endSlugRatio = wuzzy.levenshtein(endSlug, nakedDomain);
if (endSlugRatio > 0.4 && endSlug.length >= 5) {
return splitTitle.slice(0, -2).join('');
}
return null;
// accurate. Not the end of the world if it doesn't strip right.
const { host } = URL.parse(url);
const nakedDomain = host.replace(DOMAIN_ENDINGS_RE, '');
const startSlug = splitTitle[0].toLowerCase().replace(' ', '');
const startSlugRatio = wuzzy.levenshtein(startSlug, nakedDomain);
if (startSlugRatio > 0.4 && startSlug.length > 5) {
return splitTitle.slice(2).join('');
}
const endSlug = splitTitle
.slice(-1)[0]
.toLowerCase()
.replace(' ', '');
const endSlugRatio = wuzzy.levenshtein(endSlug, nakedDomain);
if (endSlugRatio > 0.4 && endSlug.length >= 5) {
return splitTitle.slice(0, -2).join('');
}
return null;
}
function constructMatrix(sentences, threshold) {
var matrix = [];
for (var i = 0; i < sentences.length; i++) {
matrix[i] = [];
var sentenceA = sentences[i];
for (var j = 0; j < sentences.length; j++) {
var sentenceB = sentences[j];
var value = wuzzy.tanimoto(sentenceB, sentenceA);
if(!!threshold && value < threshold) {
value = 0;
}
matrix[i][j] = value;
}
matrix[i] = normalize(matrix[i]);
}
return matrix;
}