npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

customer-service

v1.0.0

Published

Question & Answer'Ai * <a href="#chinese">Introduction</a> * <a href="#english">english</a>

Downloads

3

Readme

CustomerService

Question & Answer'Ai

  • 中文文档
  • english
  • API

中文文档

  • 介绍
  • 要求
  • 安装
  • 使用

介绍


CustomerService是一个可以从句子里面拆出词汇,并且可以实现问题和回答的相似度匹配的AI系统. 理论上只要词库(中文已有部分)和问答库(未导入)足够的大,就可以实现非常完美的问答.Power By NodeJs.

要求


由于使用了async和await,所以nodejs版本要在7.7.1以上.或使用babel.

安装


npm install customer-service

使用


初始化工具

const CustomerService = require("customer-service");
var customerService = new CustomerService('mylang',2,13);
var sw = customerService.getSplitWord();
var ie = customerService.getImportExport();
var qa = customerService.getQuestionAnswer();

拆词

sw.collisionWord(sw.sentenceToList('我在洗澡,你在干嘛'))
.then((res)=>{
console.log(res);
/* will print
[ { key: 'word:b7669c4218782c0035b6383623e19b29',
    word: '我在',
    questionList: {} },
  { key: 'word:5ac500cfcc1fe66f7243cad4039281d1',
    word: '洗澡',
    questionList: {} },
  { key: 'word:9d63b7094c5a502e66fccc79e5fe1f69',
    word: '你在',
    questionList: {} },
  { key: 'word:c44a42f209fa03606e607994c2321ebd',
    word: '干嘛',
    questionList: {} } ]
*/
});

库的导入和打印

//导入词库字符串
var chunk = "你好\r\n智能";
ie.stringToLevel(chunk,'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//导入问答字符串
var chunk = "你在洗澡吗?===>>>然而并没有.\r\n你是屌丝吗?===>>>不是屌丝写什么代码.";
ie.stringToLevel(chunk,'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//导入问答字符串

const path = require('path');
//导入词库
ie.readWordToLevel(path.join(__dirname,'word.log'),'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});
//导入问答
ie.readWordToLevel(path.join(__dirname,'qa.log'),'qa')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});
//print data
ie.printData({start:'word',limit:10});

获取回答

//获取最佳回答
qa.getAnswer('你是屌丝吗')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

Document

  • intro
  • req
  • install
  • use

intro


CustomerService is a down words from a sentence, and can realize question and answer the similarity matching of AI system. Theoretically as long as the word library (Chinese existing part) and q&a library (import) not enough big, can achieve very perfect answers. The Power By NodeJs.

req


nodejs'version>7.7.1 or use babel.

install


npm install customer-service

use


init

const CustomerService = require("customer-service");
var customerService = new CustomerService('mylang',2,13);
var sw = customerService.getSplitWord();
var ie = customerService.getImportExport();
var qa = customerService.getQuestionAnswer();

split word

sw.collisionWord(sw.sentenceToList('我在洗澡,你在干嘛'))
.then((res)=>{
console.log(res);
/* will print
[ { key: 'word:b7669c4218782c0035b6383623e19b29',
    word: '我在',
    questionList: {} },
  { key: 'word:5ac500cfcc1fe66f7243cad4039281d1',
    word: '洗澡',
    questionList: {} },
  { key: 'word:9d63b7094c5a502e66fccc79e5fe1f69',
    word: '你在',
    questionList: {} },
  { key: 'word:c44a42f209fa03606e607994c2321ebd',
    word: '干嘛',
    questionList: {} } ]
*/
});

lib import or print

//import word by string
var chunk = "你好\r\n智能";
ie.stringToLevel(chunk,'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//import q&a by string
var chunk = "你在洗澡吗?===>>>然而并没有.\r\n你是屌丝吗?===>>>不是屌丝写什么代码.";
ie.stringToLevel(chunk,'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//import word by file

const path = require('path');
//导入词库
ie.readWordToLevel(path.join(__dirname,'word.log'),'word')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//import q&a by string

ie.readWordToLevel(path.join(__dirname,'qa.log'),'qa')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

//print data
ie.printData({start:'word',limit:10});

get answer

//get best answer
qa.getAnswer('你是屌丝吗')
.then((res)=>{
	console.log(res);
})
.catch((err)=>{
	console.log(err);
});

API

  • CustomerService
  • SplitWord
  • ImportExport
  • QuestionAnswer

CustomerService


FunctionName constructor

  • Return void
  • Description 构造函数
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ namespace |string|option |'mylang' |选择的命名空间 minContinue |number|option |1 |拆词的最小长度 maxContinue |number|option |13 |拆词的最大长度


FunctionName getSplitWord

  • Return splitWord
  • Description 获取分词工具
  • Param empty

FunctionName getImportExport

  • Return importExport
  • Description 获取导入导出工具
  • Param empty

FunctionName getQuestionAnswer

  • Return questionAnswer
  • Description 获取提问回答工具
  • Param empty

SplitWord


FunctionName sentenceToList

  • Return singleWordList
  • Description 将句子拆成所有可能的词汇
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ sentence |string|must |empty |要拆的句子

FunctionName collisionWord

  • Return hitWordList
  • Description 将句子所有可能的词汇去碰撞词库得到正确的词汇
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ singleWordList |Object|must |empty |句子所有可能的词汇

FunctionName sentenceToUnsigned

  • Return sentence
  • Description 将句子去除所有符号
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ sentence |string|must |empty |要去除符号的句子


ImportExport


FunctionName getData

  • Return tmpData
  • Description 获取当前数据库数据
  • attend 这个方法可能回导致内存溢出,请务必传option
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ option |Object|option |{} |筛选选项

Additionally, you can supply an options object as the first parameter to createReadStream() with the following options:

  • 'gt' (greater than), 'gte' (greater than or equal) define the lower bound of the range to be streamed. Only records where the key is greater than (or equal to) this option will be included in the range. When reverse=true the order will be reversed, but the records streamed will be the same.

  • 'lt' (less than), 'lte' (less than or equal) define the higher bound of the range to be streamed. Only key/value pairs where the key is less than (or equal to) this option will be included in the range. When reverse=true the order will be reversed, but the records streamed will be the same.

  • 'start', 'end' legacy ranges - instead use 'gte', 'lte'

  • 'reverse' (boolean, default: false): a boolean, set true and the stream output will be reversed. Beware that due to the way LevelDB works, a reverse seek will be slower than a forward seek.

  • 'keys' (boolean, default: true): whether the 'data' event should contain keys. If set to true and 'values' set to false then 'data' events will simply be keys, rather than objects with a 'key' property. Used internally by the createKeyStream() method.

  • 'values' (boolean, default: true): whether the 'data' event should contain values. If set to true and 'keys' set to false then 'data' events will simply be values, rather than objects with a 'value' property. Used internally by the createValueStream() method.

  • 'limit' (number, default: -1): limit the number of results collected by this stream. This number represents a maximum number of results and may not be reached if you get to the end of the data first. A value of -1 means there is no limit. When reverse=true the highest keys will be returned instead of the lowest keys.

  • 'fillCache' (boolean, default: false): whether LevelDB's LRU-cache should be filled with data read.

  • 'keyEncoding' / 'valueEncoding' (string): the encoding applied to each read piece of data.


FunctionName readWordToLevel

  • Return true
  • Description 将文件读入数据库
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ libPath |string|option |empty |文件地址 type |string|option |'word' |词使用'word',提问回答使用'qa'


FunctionName stringToLevel

  • Return true
  • Description 将字符串导入数据库
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ chunk |string|must |empty |要导入的字符串 type |string|option |'word' |词使用'word',提问回答使用'qa'


QuestionAnswer


FunctionName getQuestionList

  • Return questionObject
  • Description 通过问句获取所有被碰撞中的问题和回答
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ questionQuery |string|must |empty |提问的语句


FunctionName getAnswer

  • Return beQuestion
  • Description 通过问句获取最大可能的问题和回答
  • Param

name | type |require |default |Description ------------|------|--------|-----------|------------ questionQuery |string|must |empty |提问的语句