写了一个用nodejs来拆词和问答的模块,跪求github点星,感谢好心人
发布于 8 个月前 作者 zy445566 1069 次浏览 来自 分享

#写了一个用nodejs来拆词和问答的模块,跪求github点星,感谢好心人 #大哥们,谢谢你们了,跪求点赞,下面是链接 #https://github.com/zy445566/CustomerService #为了支持async和await,我这个也建议直接上node的7.7.1以上版本

CustomerService

Question & Answer’Ai

  • <a href="#chinese">中文文档</a>
  • <a href="#english">english</a>
  • <a href="#api">API</a>

<a name=“chinese”></a> 中文文档

  • <a href="#intro-zh">介绍</a>
  • <a href="#req-zh">要求</a>
  • <a href="#install-zh">安装</a>
  • <a href="#use-zh">使用</a>

<a name=“intro-zh”></a>

介绍


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

<a name=“req-zh”></a>

要求


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

<a name=“install-zh”></a>

安装


npm install customer-service

<a name=“use-zh”></a>

使用


初始化工具

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);
});

<a name=“english”></a> Document

  • <a href="#intro-en">intro</a>
  • <a href="#req-en">req</a>
  • <a href="#install-en">install</a>
  • <a href="#use-en">use</a>

<a name=“intro-en”></a>

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.

<a name=“req-en”></a>

req


nodejs’version>7.7.1 or use babel.

<a name=“install-en”></a>

install


npm install customer-service

<a name=“use-en”></a>

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);
});

<a name=“api”></a> API

  • <a href="#customer-service-api">CustomerService</a>
  • <a href="#split-word-api">SplitWord</a>
  • <a href="#import-export-api">ImportExport</a>
  • <a href="#question-answer-api">QuestionAnswer</a>

<a name=“customer-service-api”></a>

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>splitWord
  • Description 获取分词工具
  • Param empty

FunctionName getImportExport

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

FunctionName getQuestionAnswer

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

<a name=“split-word-api”></a>

SplitWord


FunctionName sentenceToList

  • Return <Object>singleWordList
  • Description 将句子拆成所有可能的词汇
  • Param
name type require default Description
sentence string must empty 要拆的句子

FunctionName collisionWord

  • Return <Array>hitWordList
  • Description 将句子所有可能的词汇去碰撞词库得到正确的词汇
  • Param
name type require default Description
singleWordList Object must empty 句子所有可能的词汇

FunctionName sentenceToUnsigned

  • Return <String>sentence
  • Description 将句子去除所有符号
  • Param
name type require default Description
sentence string must empty 要去除符号的句子

<a name=“import-export-api”></a>

ImportExport


FunctionName getData

  • Return <Promise>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 <Promise>true
  • Description 将文件读入数据库
  • Param
name type require default Description
libPath string option empty 文件地址
type string option ‘word’ 词使用’word’,提问回答使用’qa’

FunctionName stringToLevel

  • Return <Promise>true
  • Description 将字符串导入数据库
  • Param
name type require default Description
chunk string must empty 要导入的字符串
type string option ‘word’ 词使用’word’,提问回答使用’qa’

<a name=“question-answer-api”></a>

QuestionAnswer


FunctionName getQuestionList

  • Return <Promise>questionObject
  • Description 通过问句获取所有被碰撞中的问题和回答
  • Param
name type require default Description
questionQuery string must empty 提问的语句

FunctionName getAnswer

  • Return <Promise>beQuestion
  • Description 通过问句获取最大可能的问题和回答
  • Param
name type require default Description
questionQuery string must empty 提问的语句
15 回复

开发api的时候不建议上那么高的api封装,不具有通用性的

谢谢,提醒。当时主要是为了方便

自顶了

挺反感这种帖子,人家star你的项目是因为确实需要用到你的东西,对你的项目感兴趣

@hxh1246996371 为星是有苦衷的,所以目前一颗星都没有

一般这种AI原理有没有好点的课程推荐。

=。= 汗 说实话,start 真没啥用。并不会因为 start 就提升项目本身的含金量。

@zy445566

为星是有苦衷的,所以目前一颗星都没有

然而目前已经有29颗星了,好嫉妒~

@yuu2lee4 已start你的项目了

@MiYogurt 这个目前真没有吧,如果真要学,要么自己想,要么就看别人写的源码,现在应该有很多这样开源的项目 不过大多ai项目都是java的代码,所以还要有个第二语言

@MiYogurt 公司要求要start求业绩,我也不想

@yuu2lee4 跪谢,已互赞

@zhanzhenzhen 都是自己跪求身边的朋友,一个一个强行让他们赞,在社区就得到2颗

@zy445566 语言不难,我自己学过不少语言,基本语法基本都学过,貌似Udacity优达有这样的课程,就是不知道好不好。

回到顶部