Skip to content

Commit

Permalink
Merge pull request #100 from prnam/feature/indian-languages
Browse files Browse the repository at this point in the history
Add Sanskrit, Kannada & Telugu language
  • Loading branch information
MihaiValentin authored May 3, 2023
2 parents 080be27 + 029514c commit ee59fc5
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Lunr Languages is a [Lunr](http://lunrjs.com/) addon that helps you search in do
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IQ.png) Arabic
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/CN.png) Chinese
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/VN.png) Vietnamese
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Sankrit
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Kannada
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Telugu
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Hindi
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/IN.png) Tamil
* ![](https://raw.githubusercontent.com/madebybowtie/FlagKit/master/Assets/PNG/KR.png) Korean
Expand Down
8 changes: 7 additions & 1 deletion build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ var list = [
}, {
locale: 'jp'
}, {
locale: 'kn'
},{
locale: 'no',
file: 'NorwegianStemmer.js',
stopwords: stopwordsCustomFolder + 'no.csv',
Expand All @@ -115,13 +117,17 @@ var list = [
stopwords: stopwordsRepoFolder + 'es.csv',
wordCharacters: wordCharacters('Latin')
}, {
locale: 'sa'
},{
locale: 'sv',
file: 'SwedishStemmer.js',
stopwords: stopwordsCustomFolder + 'sv.csv',
wordCharacters: wordCharacters('Latin')
}, {
locale: 'ta',
}, {
},{
locale: 'te'
},{
locale: 'tr',
file: 'TurkishStemmer.js',
stopwords: stopwordsCustomFolder + 'tr.csv',
Expand Down
110 changes: 110 additions & 0 deletions lunr.kn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*!
* Lunr languages, `Kannada` language
* https://github.com/MiKr13/lunr-languages
*
* Copyright 2023, India
* http://www.mozilla.org/MPL/
*/
/*!
* based on
* Snowball JavaScript Library v0.3
* http://code.google.com/p/urim/
* http://snowball.tartarus.org/
*
* Copyright 2010, Oleg Mazko
* http://www.mozilla.org/MPL/
*/

/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
*/
;
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory)
} else if (typeof exports === 'object') {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like environments that support module.exports,
* like Node.
*/
module.exports = factory()
} else {
// Browser globals (root is window)
factory()(root.lunr);
}
}(this, function() {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
* can return a function as the exported value.
*/
return function(lunr) {
/* throw error if lunr is not yet included */
if ('undefined' === typeof lunr) {
throw new Error('Lunr is not present. Please include / require Lunr before this script.');
}

/* throw error if lunr stemmer support is not yet included */
if ('undefined' === typeof lunr.stemmerSupport) {
throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
}

/* register specific locale function */
lunr.kn = function() {
this.pipeline.reset();
this.pipeline.add(
lunr.kn.trimmer,
lunr.kn.stopWordFilter,
lunr.kn.stemmer
);

if (this.searchPipeline) {
this.searchPipeline.reset();
this.searchPipeline.add(lunr.kn.stemmer)
}
};

/* lunr trimmer function */
lunr.kn.wordCharacters = "\u0C80-\u0C84\u0C85-\u0C94\u0C95-\u0CB9\u0CBE-\u0CCC\u0CBC-\u0CBD\u0CD5-\u0CD6\u0CDD-\u0CDE\u0CE0-\u0CE1\u0CE2-\u0CE3\u0CE4\u0CE5\u0CE6-\u0CEF\u0CF1-\u0CF3";
lunr.kn.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.kn.wordCharacters);

lunr.Pipeline.registerFunction(lunr.kn.trimmer, 'trimmer-kn');
/* lunr stop word filter */
lunr.kn.stopWordFilter = lunr.generateStopWordFilter(
'ಮತ್ತು ಈ ಒಂದು ರಲ್ಲಿ ಹಾಗೂ ಎಂದು ಅಥವಾ ಇದು ರ ಅವರು ಎಂಬ ಮೇಲೆ ಅವರ ತನ್ನ ಆದರೆ ತಮ್ಮ ನಂತರ ಮೂಲಕ ಹೆಚ್ಚು ನ ಆ ಕೆಲವು ಅನೇಕ ಎರಡು ಹಾಗು ಪ್ರಮುಖ ಇದನ್ನು ಇದರ ಸುಮಾರು ಅದರ ಅದು ಮೊದಲ ಬಗ್ಗೆ ನಲ್ಲಿ ರಂದು ಇತರ ಅತ್ಯಂತ ಹೆಚ್ಚಿನ ಸಹ ಸಾಮಾನ್ಯವಾಗಿ ನೇ ಹಲವಾರು ಹೊಸ ದಿ ಕಡಿಮೆ ಯಾವುದೇ ಹೊಂದಿದೆ ದೊಡ್ಡ ಅನ್ನು ಇವರು ಪ್ರಕಾರ ಇದೆ ಮಾತ್ರ ಕೂಡ ಇಲ್ಲಿ ಎಲ್ಲಾ ವಿವಿಧ ಅದನ್ನು ಹಲವು ರಿಂದ ಕೇವಲ ದ ದಕ್ಷಿಣ ಗೆ ಅವನ ಅತಿ ನೆಯ ಬಹಳ ಕೆಲಸ ಎಲ್ಲ ಪ್ರತಿ ಇತ್ಯಾದಿ ಇವು ಬೇರೆ ಹೀಗೆ ನಡುವೆ ಇದಕ್ಕೆ ಎಸ್ ಇವರ ಮೊದಲು ಶ್ರೀ ಮಾಡುವ ಇದರಲ್ಲಿ ರೀತಿಯ ಮಾಡಿದ ಕಾಲ ಅಲ್ಲಿ ಮಾಡಲು ಅದೇ ಈಗ ಅವು ಗಳು ಎ ಎಂಬುದು ಅವನು ಅಂದರೆ ಅವರಿಗೆ ಇರುವ ವಿಶೇಷ ಮುಂದೆ ಅವುಗಳ ಮುಂತಾದ ಮೂಲ ಬಿ ಮೀ ಒಂದೇ ಇನ್ನೂ ಹೆಚ್ಚಾಗಿ ಮಾಡಿ ಅವರನ್ನು ಇದೇ ಯ ರೀತಿಯಲ್ಲಿ ಜೊತೆ ಅದರಲ್ಲಿ ಮಾಡಿದರು ನಡೆದ ಆಗ ಮತ್ತೆ ಪೂರ್ವ ಆತ ಬಂದ ಯಾವ ಒಟ್ಟು ಇತರೆ ಹಿಂದೆ ಪ್ರಮಾಣದ ಗಳನ್ನು ಕುರಿತು ಯು ಆದ್ದರಿಂದ ಅಲ್ಲದೆ ನಗರದ ಮೇಲಿನ ಏಕೆಂದರೆ ರಷ್ಟು ಎಂಬುದನ್ನು ಬಾರಿ ಎಂದರೆ ಹಿಂದಿನ ಆದರೂ ಆದ ಸಂಬಂಧಿಸಿದ ಮತ್ತೊಂದು ಸಿ ಆತನ '.split(' '));
/* lunr stemmer function */
lunr.kn.stemmer = (function() {

return function(word) {
// for lunr version 2
if (typeof word.update === "function") {
return word.update(function(word) {
return word;
})
} else { // for lunr version <= 1
return word;
}

}
})();

var segmenter = lunr.wordcut;
segmenter.init();
lunr.kn.tokenizer = function(obj) {
if (!arguments.length || obj == null || obj == undefined) return []
if (Array.isArray(obj)) return obj.map(function(t) {
return isLunr2 ? new lunr.Token(t.toLowerCase()) : t.toLowerCase()
});

var str = obj.toString().toLowerCase().replace(/^\s+/, '');
return segmenter.cut(str).split('|');
}

lunr.Pipeline.registerFunction(lunr.kn.stemmer, 'stemmer-kn');
lunr.Pipeline.registerFunction(lunr.kn.stopWordFilter, 'stopWordFilter-kn');

};
}))
110 changes: 110 additions & 0 deletions lunr.sa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*!
* Lunr languages, `Sanskrit` language
* https://github.com/MiKr13/lunr-languages
*
* Copyright 2023, India
* http://www.mozilla.org/MPL/
*/
/*!
* based on
* Snowball JavaScript Library v0.3
* http://code.google.com/p/urim/
* http://snowball.tartarus.org/
*
* Copyright 2010, Oleg Mazko
* http://www.mozilla.org/MPL/
*/

/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
*/
;
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory)
} else if (typeof exports === 'object') {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like environments that support module.exports,
* like Node.
*/
module.exports = factory()
} else {
// Browser globals (root is window)
factory()(root.lunr);
}
}(this, function() {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
* can return a function as the exported value.
*/
return function(lunr) {
/* throw error if lunr is not yet included */
if ('undefined' === typeof lunr) {
throw new Error('Lunr is not present. Please include / require Lunr before this script.');
}

/* throw error if lunr stemmer support is not yet included */
if ('undefined' === typeof lunr.stemmerSupport) {
throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
}

/* register specific locale function */
lunr.sa = function() {
this.pipeline.reset();
this.pipeline.add(
lunr.sa.trimmer,
lunr.sa.stopWordFilter,
lunr.sa.stemmer
);

if (this.searchPipeline) {
this.searchPipeline.reset();
this.searchPipeline.add(lunr.sa.stemmer)
}
};

/* lunr trimmer function */
lunr.sa.wordCharacters = "\u0900-\u0903\u0904-\u090f\u0910-\u091f\u0920-\u092f\u0930-\u093f\u0940-\u094f\u0950-\u095f\u0960-\u096f\u0970-\u097f\uA8E0-\uA8F1\uA8F2-\uA8F7\uA8F8-\uA8FB\uA8FC-\uA8FD\uA8FE-\uA8FF\u11B00-\u11B09";
lunr.sa.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.sa.wordCharacters);

lunr.Pipeline.registerFunction(lunr.sa.trimmer, 'trimmer-sa');
/* lunr stop word filter */
lunr.sa.stopWordFilter = lunr.generateStopWordFilter(
'तथा अयम्‌ एकम्‌ इत्यस्मिन्‌ तथा तत्‌ वा अयम्‌ इत्यस्य ते आहूत उपरि तेषाम्‌ किन्तु तेषाम्‌ तदा इत्यनेन अधिकः इत्यस्य तत्‌ केचन बहवः द्वि तथा महत्वपूर्णः अयम्‌ अस्य विषये अयं अस्ति तत्‌ प्रथमः विषये इत्युपरि इत्युपरि इतर अधिकतमः अधिकः अपि सामान्यतया ठ इतरेतर नूतनम्‌ द न्यूनम्‌ कश्चित्‌ वा विशालः द सः अस्ति तदनुसारम् तत्र अस्ति केवलम्‌ अपि अत्र सर्वे विविधाः तत्‌ बहवः यतः इदानीम्‌ द दक्षिण इत्यस्मै तस्य उपरि नथ अतीव कार्यम्‌ सर्वे एकैकम्‌ इत्यादि। एते सन्ति उत इत्थम्‌ मध्ये एतदर्थं . स कस्य प्रथमः श्री. करोति अस्मिन् प्रकारः निर्मिता कालः तत्र कर्तुं समान अधुना ते सन्ति स एकः अस्ति सः अर्थात् तेषां कृते . स्थितम् विशेषः अग्रिम तेषाम्‌ समान स्रोतः ख म समान इदानीमपि अधिकतया करोतु ते समान इत्यस्य वीथी सह यस्मिन् कृतवान्‌ धृतः तदा पुनः पूर्वं सः आगतः किम्‌ कुल इतर पुरा मात्रा स विषये उ अतएव अपि नगरस्य उपरि यतः प्रतिशतं कतरः कालः साधनानि भूत तथापि जात सम्बन्धि अन्यत्‌ ग अतः अस्माकं स्वकीयाः अस्माकं इदानीं अन्तः इत्यादयः भवन्तः इत्यादयः एते एताः तस्य अस्य इदम् एते तेषां तेषां तेषां तान् तेषां तेषां तेषां समानः सः एकः च तादृशाः बहवः अन्ये च वदन्ति यत् कियत् कस्मै कस्मै यस्मै यस्मै यस्मै यस्मै न अतिनीचः किन्तु प्रथमं सम्पूर्णतया ततः चिरकालानन्तरं पुस्तकं सम्पूर्णतया अन्तः किन्तु अत्र वा इह इव श्रद्धाय अवशिष्यते परन्तु अन्ये वर्गाः सन्ति ते सन्ति शक्नुवन्ति सर्वे मिलित्वा सर्वे एकत्र"'.split(' '));
/* lunr stemmer function */
lunr.sa.stemmer = (function() {

return function(word) {
// for lunr version 2
if (typeof word.update === "function") {
return word.update(function(word) {
return word;
})
} else { // for lunr version <= 1
return word;
}

}
})();

var segmenter = lunr.wordcut;
segmenter.init();
lunr.sa.tokenizer = function(obj) {
if (!arguments.length || obj == null || obj == undefined) return []
if (Array.isArray(obj)) return obj.map(function(t) {
return isLunr2 ? new lunr.Token(t.toLowerCase()) : t.toLowerCase()
});

var str = obj.toString().toLowerCase().replace(/^\s+/, '');
return segmenter.cut(str).split('|');
}

lunr.Pipeline.registerFunction(lunr.sa.stemmer, 'stemmer-sa');
lunr.Pipeline.registerFunction(lunr.sa.stopWordFilter, 'stopWordFilter-sa');

};
}))
122 changes: 122 additions & 0 deletions lunr.te.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*!
* Lunr languages, `Hindi` language
* https://github.com/MiKr13/lunr-languages
*
* Copyright 2023, India
* http://www.mozilla.org/MPL/
*/
/*!
* based on
* Snowball JavaScript Library v0.3
* http://code.google.com/p/urim/
* http://snowball.tartarus.org/
*
* Copyright 2010, Oleg Mazko
* http://www.mozilla.org/MPL/
*/

/**
* export the module via AMD, CommonJS or as a browser global
* Export code from https://github.com/umdjs/umd/blob/master/returnExports.js
*/
;
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(factory)
} else if (typeof exports === 'object') {
/**
* Node. Does not work with strict CommonJS, but
* only CommonJS-like environments that support module.exports,
* like Node.
*/
module.exports = factory()
} else {
// Browser globals (root is window)
factory()(root.lunr);
}
}(this, function() {
/**
* Just return a value to define the module export.
* This example returns an object, but the module
* can return a function as the exported value.
*/
return function(lunr) {
/* throw error if lunr is not yet included */
if ('undefined' === typeof lunr) {
throw new Error('Lunr is not present. Please include / require Lunr before this script.');
}

/* throw error if lunr stemmer support is not yet included */
if ('undefined' === typeof lunr.stemmerSupport) {
throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.');
}

/* register specific locale function */
lunr.te = function() {
this.pipeline.reset();
this.pipeline.add(
lunr.te.trimmer,
lunr.te.stopWordFilter,
lunr.te.stemmer
);

// change the tokenizer for japanese one
// if (isLunr2) { // for lunr version 2.0.0
// this.tokenizer = lunr.hi.tokenizer;
// } else {
// if (lunr.tokenizer) { // for lunr version 0.6.0
// lunr.tokenizer = lunr.hi.tokenizer;
// }
// if (this.tokenizerFn) { // for lunr version 0.7.0 -> 1.0.0
// this.tokenizerFn = lunr.hi.tokenizer;
// }
// }

if (this.searchPipeline) {
this.searchPipeline.reset();
this.searchPipeline.add(lunr.te.stemmer)
}
};

/* lunr trimmer function */
lunr.te.wordCharacters = "\u0C00-\u0C04\u0C05-\u0C14\u0C15-\u0C39\u0C3E-\u0C4C\u0C55-\u0C56\u0C58-\u0C5A\u0C60-\u0C61\u0C62-\u0C63\u0C66-\u0C6F\u0C78-\u0C7F\u0C3C\u0C3D\u0C4D\u0C5D\u0C77\u0C64\u0C65";
lunr.te.trimmer = lunr.trimmerSupport.generateTrimmer(lunr.te.wordCharacters);

lunr.Pipeline.registerFunction(lunr.te.trimmer, 'trimmer-te');
/* lunr stop word filter */
lunr.te.stopWordFilter = lunr.generateStopWordFilter(
'అందరూ అందుబాటులో అడగండి అడగడం అడ్డంగా అనుగుణంగా అనుమతించు అనుమతిస్తుంది అయితే ఇప్పటికే ఉన్నారు ఎక్కడైనా ఎప్పుడు ఎవరైనా ఎవరో ఏ ఏదైనా ఏమైనప్పటికి ఒక ఒకరు కనిపిస్తాయి కాదు కూడా గా గురించి చుట్టూ చేయగలిగింది తగిన తర్వాత దాదాపు దూరంగా నిజంగా పై ప్రకారం ప్రక్కన మధ్య మరియు మరొక మళ్ళీ మాత్రమే మెచ్చుకో వద్ద వెంట వేరుగా వ్యతిరేకంగా సంబంధం'.split(' '));
/* lunr stemmer function */
lunr.te.stemmer = (function() {

return function(word) {
// for lunr version 2
if (typeof word.update === "function") {
return word.update(function(word) {
return word;
})
} else { // for lunr version <= 1
return word;
}

}
})();

var segmenter = lunr.wordcut;
segmenter.init();
lunr.te.tokenizer = function(obj) {
if (!arguments.length || obj == null || obj == undefined) return []
if (Array.isArray(obj)) return obj.map(function(t) {
return isLunr2 ? new lunr.Token(t.toLowerCase()) : t.toLowerCase()
});

var str = obj.toString().toLowerCase().replace(/^\s+/, '');
return segmenter.cut(str).split('|');
}

lunr.Pipeline.registerFunction(lunr.te.stemmer, 'stemmer-te');
lunr.Pipeline.registerFunction(lunr.te.stopWordFilter, 'stopWordFilter-te');

};
}))
Loading

0 comments on commit ee59fc5

Please sign in to comment.