CNode

写了一个用nodejs来拆词和问答的模块,跪求github点星,感谢好心人

分享
Zzy445566发布于9 年前最后回复9 年前15 回复4782 浏览0 收藏

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

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
nametyperequiredefaultDescription
namespacestringoption'mylang'选择的命名空间
minContinuenumberoption1拆词的最小长度
maxContinuenumberoption13拆词的最大长度

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
nametyperequiredefaultDescription
sentencestringmustempty要拆的句子

FunctionName collisionWord

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

FunctionName sentenceToUnsigned

  • Return sentence
  • Description 将句子去除所有符号
  • Param
nametyperequiredefaultDescription
sentencestringmustempty要去除符号的句子

ImportExport


FunctionName getData

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

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
nametyperequiredefaultDescription
libPathstringoptionempty文件地址
typestringoption'word'词使用'word',提问回答使用'qa'

FunctionName stringToLevel

  • Return true
  • Description 将字符串导入数据库
  • Param
nametyperequiredefaultDescription
chunkstringmustempty要导入的字符串
typestringoption'word'词使用'word',提问回答使用'qa'

QuestionAnswer


FunctionName getQuestionList

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

FunctionName getAnswer

  • Return beQuestion
  • Description 通过问句获取最大可能的问题和回答
  • Param
nametyperequiredefaultDescription
questionQuerystringmustempty提问的语句
查看回复

回复 (15)

I
i5ting#1·9 年前

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

Z
zy445566#2·9 年前

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

Z
zy445566#3·9 年前

自顶了

H
hxh1246996371#4·9 年前

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

M
MiYogurt#6·9 年前

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

Y
yuu2lee4#7·9 年前
M
MiYogurt#8·9 年前

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

Z
zhanzhenzhen#9·9 年前

@zy445566

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

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

Z
zy445566#10·9 年前
Z
zy445566#11·9 年前
引用 MiYogurt一般这种AI原理有没有好点的课程推荐。

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

Z
zy445566#14·9 年前
引用 zhanzhenzhen@zy445566 为星是有苦衷的,所以目前一颗星都没有 然而目前已经有29颗星了,好嫉妒~

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

M
MiYogurt#15·9 年前

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

参与回复
登录后即可参与回复。登录