How to use cld - 7 common examples

To help you get started, we’ve selected a few cld 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 patrickkettner / manifestation / lib / scrapers / lang.js View on Github external
}

  // if they declare the lang attr, we assume they know what they are talking about
  if (declaredLang) {
    callback(null, declaredLang);
  }
  else {
    let lang;

    const options = {
      isHTML: true,
      tldHint: obj.url && TldExtract(obj.url).tld
    };

    // otherwise, we load the page, and use Google's cld to try to detect it
    Cld.detect(html, options, (err, result) => {

      if (!err && result.reliable) {
        lang = result.languages[0].code;
      }
      else if (err) {
        console.warn(err);
      }

      // if we were unable to identify the language, or the results are not
      // considered reliable, re return undefined
      // don't return the actual error as we don't want to stop parsing as a result

      callback(null, lang);
    });
  }
};
github sallar / top-tweets / source / app / controllers / validator.js View on Github external
return new Promise(function(resolve) {
            // Only run the detection if it’s enabled.
            if(config.secondaryCheck === true) {
                cld.detect(status.text, options, function(err, result) {
                    if(
                        !err &&
                        result.languages[0].code === language &&
                        result.languages[0].score >= config.langThreshold &&
                        result.reliable === true
                    ) {
                        resolve(status);
                    } else {
                        resolve(null);
                    }
                });
            } else {
                resolve(status);
            }
        });
    }
github GLAMpipe / GLAMpipe / app / node_runners / field-detect-language.js View on Github external
async.eachSeries(input, function iterator(value, nextvalue) {
		
		cld.detect(value, function(err, result) {
			console.log("detection result");
			console.log(result);
			sandbox.context.data.push(result);
			nextvalue();
		});
		
	}, function done() {
		sandbox.run.runInContext(sandbox);
github AlduinApp / alduin / main.js View on Github external
return await new Promise((resolve, reject) => {
    cld.detect(content, {
      isHTML: true,
      tldHint: tldExtract(url).tld
    }, (err, result) => {
      resolve(rtlDetect.isRtlLang(result.languages[0].code))
    })
  })
})
github ava-ia / core / src / processor / language.js View on Github external
return new Promise((resolve) => {
    cld.detect(state.rawSentence, (error, value) => {
      if (!error) {
        state.language = value.languages[0].code;
      }
      state.sentence = state.rawSentence;

      resolve(state);
    });
  });
}
github electron-userland / electron-spellchecker / src / cld2.js View on Github external
return new Promise((res,rej) => {
      cld.detect(text, (err, result) => {
        if (err) { rej(new Error(err.message)); return; }
        if (!result.reliable || result.languages[0].percent < 85) {
          rej(new Error('Not enough reliable text'));
          return;
        }

        res(result.languages[0].code);
      });
    });
  }
github jupitex / sisyphe / src / worker / nb / index.js View on Github external
async.eachSeries(abstracts, function(item, callback) {
      cld.detect(item, {
        "isHTML": false,
        "encodingHint": "UTF8",
      }, function(err, result) {
        if (err) return callback(err);
        if (!result) return callback();
        if (result.reliable && result.languages.length) {
          if (result.languages[0].percent >= worker.resources.parameters.cld.percent && result.languages[0].code === worker.resources.parameters.cld.code) abstract = item;
        }
        callback();
      });
    }, function(err) {
      if (err) {

cld

Language detection for Javascript. Based on the CLD2 (Compact Language Detector) library from Google. Highly optimized for space and speed. Runs about 10x faster than other libraries. Detects over 160 languages. Full test coverage. Runs on Linux, OS X, an

Apache-2.0
Latest version published 4 months ago

Package Health Score

69 / 100
Full package analysis

Popular cld functions