Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
listen(function(text) {
if (text.length) {
// const words = tokenizer(text);
const words = nodejieba.cut(text);
const testVec = words2Vec(vocabList, words);
console.log(response(classify(testVec, weights, pAbusive)));
} else {
console.log('Any help?');
}
})
"page": function(page){
// console.log(page);
// 建立页面内容索引
pageIndex[pageId] = {
path : page.path.replace(/readme\.md$/i,'index.html').replace(/\.md$/,'.html'),
title : page.progress.current.title,
level : page.progress.current.level
}
// 分词
var words = _.uniq( nodejieba.cut(page.content) );
// 去重
_(words).forEach(function(word) {
// 不索引1个字的词
//if(word.length > 1){
// 转为大写
word = word.toUpperCase();
// 如果没有这个词的索引空间
if(!searchIndexMap[word]) {
searchIndexMap[word] = [];
}
// 搜索词容器推入
patterns.forEach(function(pattern) {
// const words = tokenizer(pattern);
const words = nodejieba.cut(pattern);
document.push(words);
classes.push(tag);
});
responses[tag] = intent.responses;
listen(function(text) {
if (text.length) {
console.log(classifier.classify(nodejieba.cut(text)));
} else {
console.log('Any help?');
}
});
});
splitToTerms(content){
let self = this;
let terms = [];
let ps = Array.isArray(content)?content:self.splitToParagraphs(content);
for(let x of ps){
let sens = self.splitToSentences(x);
let parag = [];
for(let y of sens){
let sentens = [];
for(let z of nodejieba.cut(y.trim()))sentens.push(z);
if(sentens.length>0){
if(sentens[sentens.length-1]!='。')sentens.push('。');
parag.push(sentens);
}
}
if(parag.length>0)terms.push(parag);
}
return terms;
}
async function isSimilar({ word, guessWord, simiList }, text) {
return jieba.cut(text).every(w => {
return word.indexOf(w) > 0 || guessWord.indexOf(w) > 0 || simiList.every(
({ summary, summaryOrig }) => {
return summary.indexOf(w) > 0 || summaryOrig.indexOf(w) > 0;
}
);
});
}
Classifier.prototype.predict = function(text) {
const words = nodejieba.cut(text);
const features = this.textToFeatures(words);
const results = this.classifier.predict([features]);
const result = results[0];
let max = 0;
let index = 0;
for(let key in result) {
const value = result[key];
if (value > max) {
max = value;
index = key;
}
}
return this.classes[index];
};
exports.cut = function(str) {
return jieba.cut(str || '')
.map(function(item) {
return item.trim();
})
.filter(function(item) {
return !!item;
});
};
patterns.forEach((pattern) => {
const words = nodejieba.cut(pattern);
docs.push({
tag,
words
});
for (let i = 0; i < words.length; i++) {
let token = words[i];
this.features[token] = (this.features[token] || 0) + 1;
}
if (this.classes.indexOf(tag) === -1) {
this.classes.push(tag);
}
});
});
const segment = input => {
const words = jieba.cut(trans.sify(input));
const results = [];
words.forEach(w => {
results.push(trans.tify(w));
})
return results;
}
module.exports = segment;