How to use franc-min - 2 common examples

To help you get started, we’ve selected a few franc-min examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GetStream / Winds / api / src / parsers / detect-language.js View on Github external
export async function DetectLangFromStream(feedStream) {
	let posts = await ReadFeedStream(feedStream);

	let bestGuessLanguage = 'eng';
	if (!posts || !posts.length) {
		return bestGuessLanguage;
	}

	let meta = posts[0].meta;
	// language = meta.language
	// guess the language using franc
	let languageSums = {};
	for (let post of posts.slice(0, 10)) {
		let languageVector = franc.all(`${post.title} ${post.description}`);
		for (let [language, score] of languageVector) {
			if (!(language in languageSums)) {
				languageSums[language] = 0;
			}
			languageSums[language] += score;
		}
	}

	// see which language has the highest score
	let languages = Object.entries(languageSums).sort((a, b) => b[1] - a[1]);
	if (languages) {
		bestGuessLanguage = languages[0][0];
	}

	return bestGuessLanguage;
}
github GetStream / Winds / api / src / utils / detectPodcastLanguage.js View on Github external
ParsePodcast(podcastUrl, (err, podcastContents) => {
			if (err) {
				// sometimes rss feeds throw a 503 when being added and parsed immediately - in that case, just resolve to english
				return resolve('eng');
			}
			// language in the feed metadata is only sometimes there - calculating via franc should be good enough for now
			let languageSums = {};
			for (let episode of podcastContents.episodes) {
				let languageVector = franc.all(`${episode.title} ${episode.description}`);
				for (let languageGuess of languageVector) {
					if (languageGuess[0] in languageSums) {
						languageSums[languageGuess[0]] += languageGuess[1];
					} else {
						languageSums[languageGuess[0]] = languageGuess[1];
					}
				}
			}
			// get largest languageSum
			let max = 0;
			let bestGuessLanguage = 'eng';
			for (var language in languageSums) {
				if (languageSums.hasOwnProperty(language)) {
					if (languageSums[language] > max) {
						max = languageSums[language];
						bestGuessLanguage = language;

franc-min

Detect the language of text

MIT
Latest version published 11 months ago

Package Health Score

60 / 100
Full package analysis

Popular franc-min functions