languages.io
v0.9.1
Published
Multi Languages Detection for Text-Mining and Natural Language Processing - True ITK - Open Source
Downloads
3,012
Maintainers
Readme
Node.js languages.io
Multi Languages Detection for Text-Mining and Natural Language Processing
Built With
- franc-all - Detect the language of text.
- langs - This library provides ISO 639-1/2/3 language codes with English and local names.
- node-nlp - "NLP.js" is a general natural language utilities for nodejs.
Installing
$ npm install --save languages.io
Usage
const Languages = require('languages.io')
const language = new Languages()
Recognizes the language of a text
Detects the language of the given string and returns an object with all available ISO 639 language codes along with the accuracy. The accuracy should be as close as possible to "1", which is the best result, an accuracy below 1 should be followed by further testing. The text passed should be as long as possible so that the accuracy is as high as possible.
const language = new Languages()
var source = 'Erkennt die Sprache der übergebenen Zeichenkette und gibt ein Objekt mit allen verfügbaren ISO 639 Sprach Codes zusammen mit der Genauigkeit zurück. Die Genauigkeit sollte möglichst bei "1" liegen, was dem besten Ergebniss entspricht, einer Genauigkeit von unter 1 sollten weiteren Test folgen. Der übergebene Text sollte möglichst lang sein damit die Genauigkeit möglichst hoch ist.'
console.log(language.recognize(source))
/* {
name: 'German',
local: 'Deutsch',
code: 'DE',
accuracy: 1,
ISO639_1: 'de',
ISO639_2: 'deu',
ISO639_3: 'deu',
ISO639_2T: 'deu',
ISO639_2B: 'ger'
} */
A list of all available languages including their speakers. (It should meet all common requirements 😁)
Check ISO 639 language code
Check if the passed string is a language code according to ISO 639
const language = new Languages()
var languageCode = 'en' /* ( "English" | "English" | "en" | "eng" | "eng" | "eng" | "eng" ) */
var isoCode = 1 /* ( "name" | "local" | 1 | 2 | 3 | "2T" | "2B" ) */
console.log(language.isLanguageCode(languageCode, isoCode)) /* => boolean (true / false) check if "en" = ISO 639 Language Code */
if (language.isLanguageCode(languageCode, isoCode)) /* => true */
Returns Object with ISO 639 Codes
Returns an object with all recognized ISO 639 codes based on a single passed ISO code.
const language = new Languages()
var languageCode = 'en' /* ( "English" | "English" | "en" | "eng" | "eng" | "eng" | "eng" ) */
var isoCode = 1 /* ( "name" | "local" | 1 | 2 | 3 | "2T" | "2B" ) */
console.log(language.getLanguageCodes(languageCode, isoCode))
/* {
name: 'English',
local: 'English',
code: 'EN',
ISO639_1: 'en',
ISO639_2: 'eng',
ISO639_3: 'eng',
ISO639_2T: 'eng',
ISO639_2B: 'eng'
} */
Check certain language
Check if a string corresponds to a certain language
const language = new Languages()
var source = 'Returns true or false if the source matches the language.'
console.log(language.isGerman(source)) /* => boolean (true / false) check if source = German */
console.log(language.isEnglish(source)) /* => boolean (true / false) check if source = English */
console.log(language.isFrench(source)) /* => boolean (true / false) check if source = French */
console.log(language.isSpanish(source)) /* => boolean (true / false) check if source = Spanish */
console.log(language.isItalian(source)) /* => boolean (true / false) check if source = Italian */
console.log(language.isDutch(source)) /* => boolean (true / false) check if source = Dutch */
console.log(language.isPolish(source)) /* => boolean (true / false) check if source = Polish */
console.log(language.isFinnish(source)) /* => boolean (true / false) check if source = Finnish */
console.log(language.isFarsi(source)) /* => boolean (true / false) check if source = Farsi */
console.log(language.isRussian(source)) /* => boolean (true / false) check if source = Russian */
console.log(language.isPortugese(source)) /* => boolean (true / false) check if source = Portugese */
console.log(language.isNorwegian(source)) /* => boolean (true / false) check if source = Norwegian */
console.log(language.isSwedish(source)) /* => boolean (true / false) check if source = Swedish */
console.log(language.isVietnamese(source)) /* => boolean (true / false) check if source = Vietnamese */
console.log(language.isJapanese(source)) /* => boolean (true / false) check if source = Japanese */
if (language.isEnglish(source)) /* => true */
if (!language.isGerman(source)) /* => true */
License
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details © John Ollhorn [email protected]