How to use the franc.all function in franc

To help you get started, we’ve selected a few franc 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 conventional-changelog / commitlint / @commitlint / core / src / library / ensure-language.js View on Github external
export default (input, allowed) => {
	const detected = franc
		.all(input)
		.filter(lang => lang[1] >= 0.45)
		.map(lang => lang[0])
		.slice(0, 5);

	// Library franc spits out ['und'] when unable to
	// guess any languages, let it through in this case
	const matches = detected[0] === 'und' || detected.indexOf(allowed) > -1;

	return {
		matches,
		detected
	};
};
github jddunn / frame / frame / src / components / Notepad / Notepad.jsx View on Github external
entry = traverseEntriesById(entryId, Entries);

    // let Entries = await localforage.getItem("entries");
    let editorType = entry['editorType'];
    // let library = getState("library");
    let library = defaultFLib;
    const Library = openDB(library);
    const m_this = this;
    entry['timestampLastModified'] = timestampNow;
    // if (entry !== null && entry !== undefined) {
      // entry['html'] = getHTMLFromContent(this.state.editorState);
      entry['html'] = this.state.editorHtml;
      const strippedText = HTMLToText(entry['html']);
      entry['strippedText'] = strippedText;
      const combinedText = entry['title'] + ' ' + strippedText;
      const detectedLanguages = franc.all(combinedText).slice(0, 5);
      entry['detectedLanguages'] = detectedLanguages;
      entry['entities'] = {
        terms: parseTextForTerms(strippedText),
        topics: parseTextForTopics(strippedText),
        people: parseTextForPeople(strippedText),
        dates: parseTextForDates(strippedText),
        organizations: parseTextForOrganizations(strippedText),
        places: parseTextForPlaces(strippedText),
        phoneNumbers: parseTextForPhoneNumbers(strippedText),
        urls: parseTextForURLs(strippedText),
        hashtags: parseTextForHashtags(strippedText),
        quotes: parseTextForQuotes(strippedText),
        statements: parseTextForStatements(strippedText),
        questions: parseTextForQuestions(strippedText),
        bigrams: parseTextForBigrams(strippedText),
        trigrams: parseTextForTrigrams(strippedText)
github jddunn / frame / frame / src / components / Notepad / Notepad.jsx View on Github external
} catch (err) {
        editorType = "flow";
        setState("editorType", "flow");
      }

      const showAnalysisOverlay = nextProps.showAnalysisOverlay;
  
      // if (entry['html'] !== null && entry['html'] !== undefined && entry['html'] !== ""
      //   &amp;&amp; entry['html'] !== "undefined" &amp;&amp; entry['html'] !== 'undefined' &amp;&amp; entry['html'] !== '<p></p>'
      // ) {

        if (showAnalysisOverlay) {
          const strippedText = HTMLToText(entry['html']);
          entry['strippedText'] = strippedText;
          const combinedText = entry['title'] + ' ' + strippedText;
          const detectedLanguages = franc.all(combinedText).slice(0, 5);
          entry['detectedLanguages'] = detectedLanguages;
          entry['entities'] = {
            terms: parseTextForTerms(strippedText),
            topics: parseTextForTopics(strippedText),
            people: parseTextForPeople(strippedText),
            dates: parseTextForDates(strippedText),
            organizations: parseTextForOrganizations(strippedText),
            places: parseTextForPlaces(strippedText),
            phoneNumbers: parseTextForPhoneNumbers(strippedText),
            urls: parseTextForURLs(strippedText),
            hashtags: parseTextForHashtags(strippedText),
            quotes: parseTextForQuotes(strippedText),
            statements: parseTextForStatements(strippedText),
            questions: parseTextForQuestions(strippedText),
            bigrams: parseTextForBigrams(strippedText),
            trigrams: parseTextForTrigrams(strippedText)
github wooorm / franc / packages / franc-cli / index.js View on Github external
function detect(value) {
  var options = {
    minLength: flags.minLength,
    only: flags.only,
    ignore: flags.ignore
  }

  if (flags.all) {
    franc.all(value, options).forEach(function(language) {
      console.log(language[0] + ' ' + language[1])
    })
  } else {
    console.log(franc(value, options))
  }
}
github microsoft / Universal-Language-Intelligence-Service / ulis / lib / ulis.js View on Github external
function query(text, cb) {

		if (!cb) return new Error('Please provide a callback to process the returned response');
		if (!text) return cb(new Error('Please provide a text'));

		//confirm language: requires conversion between iso-639-3 (lang3)  and iso-639-1
		var lang3 = langs.where("1", lang)['3'];
		var detectedLang = franc.all(text,{'whitelist' : ['eng',lang3], 'minLength': 3})[0][0];
		console.log(`${detectedLang} detected`);
		if (detectedLang != lang3 ){
			if ( detectedLang != 'eng'){
				return cb(new Error('Sorry we don\'t support that language at the moment.'));
			}
		}

		translate(text, (err, translatedText) => {
			if (err) return cb(err);
			sendToLuis(translatedText, (err, luisResponse) => {
				if (err) return cb(err);
				luisResponse.translatedText = translatedText; 
				return cb(null, luisResponse);
			});
		});
	}
github SC5 / serverless-blog-to-podcast / aggregate / aggregate.js View on Github external
const writeItem = (item) => {
  const Key = `${item.id}.json`;
  const lang = franc.all(item.title, { whitelist: ['eng', 'fin'] })[0];

  if (lang[0] === 'fin') {
    return 0;
  }

  Object.assign(item, { lang: lang[0] });
  const params = {
    Bucket: process.env.BLOG_BUCKET,
    Key,
  };

  return s3.getObject(params).promise()
    .then(() => item)
    .catch(() =>
      s3.putObject(
        Object.assign(params, {
github wooorm / retext-language / index.js View on Github external
function any(node) {
    patch(node, franc.all(nlcstToString(node)));
}
github bendorshai / its-a-date / model / tokens / common / language_detector.js View on Github external
exports.detect = function (dateString) {
    return franc.all(dateString, {
        'whitelist': languageManager.getSupportedLangCodes(),
        'minLength': 3
    });
}

franc

Detect the language of text

MIT
Latest version published 5 months ago

Package Health Score

64 / 100
Full package analysis

Popular franc functions