1/*! 2 * Lunr languages, `Japanese` language 3 * https://github.com/MihaiValentin/lunr-languages 4 * 5 * Copyright 2014, Chad Liu 6 * http://www.mozilla.org/MPL/ 7 */ 8/*! 9 * based on 10 * Snowball JavaScript Library v0.3 11 * http://code.google.com/p/urim/ 12 * http://snowball.tartarus.org/ 13 * 14 * Copyright 2010, Oleg Mazko 15 * http://www.mozilla.org/MPL/ 16 */ 17 18/** 19 * export the module via AMD, CommonJS or as a browser global 20 * Export code from https://github.com/umdjs/umd/blob/master/returnExports.js 21 */ 22; 23(function(root, factory) { 24 if (typeof define === 'function' && define.amd) { 25 // AMD. Register as an anonymous module. 26 define(factory) 27 } else if (typeof exports === 'object') { 28 /** 29 * Node. Does not work with strict CommonJS, but 30 * only CommonJS-like environments that support module.exports, 31 * like Node. 32 */ 33 module.exports = factory() 34 } else { 35 // Browser globals (root is window) 36 factory()(root.lunr); 37 } 38}(this, function() { 39 /** 40 * Just return a value to define the module export. 41 * This example returns an object, but the module 42 * can return a function as the exported value. 43 */ 44 return function(lunr) { 45 /* throw error if lunr is not yet included */ 46 if ('undefined' === typeof lunr) { 47 throw new Error('Lunr is not present. Please include / require Lunr before this script.'); 48 } 49 50 /* throw error if lunr stemmer support is not yet included */ 51 if ('undefined' === typeof lunr.stemmerSupport) { 52 throw new Error('Lunr stemmer support is not present. Please include / require Lunr stemmer support before this script.'); 53 } 54 55 /* register specific locale function */ 56 lunr.jp = function() { 57 this.pipeline.reset(); 58 this.pipeline.add( 59 lunr.jp.stopWordFilter, 60 lunr.jp.stemmer 61 ); 62 // change the tokenizer for japanese one 63 lunr.tokenizer = lunr.jp.tokenizer; 64 }; 65 var segmenter = new TinySegmenter(); // ã¤ã³ã¹ã¿ã³ã¹çæ 66 67 lunr.jp.tokenizer = function (obj) { 68 if (!arguments.length || obj == null || obj == undefined) return [] 69 if (Array.isArray(obj)) return obj.map(function (t) { return t.toLowerCase() }) 70 71 var str = obj.toString().replace(/^\s+/, '') 72 73 for (var i = str.length - 1; i >= 0; i--) { 74 if (/\S/.test(str.charAt(i))) { 75 str = str.substring(0, i + 1) 76 break 77 } 78 } 79 80 81 var segs = segmenter.segment(str); // åèªã®é åãè¿ã 82 return segs.filter(function (token) { 83 return !!token 84 }) 85 .map(function (token) { 86 return token 87 }) 88 } 89 90 /* lunr stemmer function */ 91 lunr.jp.stemmer = (function() { 92 93 /* TODO japanese stemmer */ 94 return function(word) { 95 return word; 96 } 97 })(); 98 99 lunr.Pipeline.registerFunction(lunr.jp.stemmer, 'stemmer-jp'); 100 101 /* stop word filter function */ 102 lunr.jp.stopWordFilter = function(token) { 103 if (lunr.jp.stopWordFilter.stopWords.indexOf(token) === -1) { 104 return token; 105 } 106 }; 107 108 lunr.jp.stopWordFilter.stopWords = new lunr.SortedSet(); 109 lunr.jp.stopWordFilter.stopWords.length = 45; 110 111 // The space at the beginning is crucial: It marks the empty string 112 // as a stop word. lunr.js crashes during search when documents 113 // processed by the pipeline still contain the empty string. 114 // stopword for japanese is from http://www.ranks.nl/stopwords/japanese 115 lunr.jp.stopWordFilter.stopWords.elements = ' ãã ãã ãã ãã® ãã® ãã® ãã ãã ããã ãã¡ã ã©ã ã ã ãªã« ãªã ä½ ç§ è²´æ¹ è²´æ¹æ¹ æã ç§é ãã®äºº ãã®ãã 彼女 å½¼ ã§ã ããã¾ã ããã¾ã ãã¾ã 㯠ã ã® ã« ã ã§ ã ãã ã¾ã§ ãã ã ã©ã® 㨠ã ããã§ ããã'.split(' '); 116 lunr.Pipeline.registerFunction(lunr.jp.stopWordFilter, 'stopWordFilter-jp'); 117 }; 118}))
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.