所以我看到了这个很棒的natural language processing in javascript,我想知道如何进行基本的语境化?
比如说,我想抽出时间。
做这样的事情:
var word = nlp(`What's the time`)
console.log(word.match('time').found)
我得到一个true
布尔值,因为time
字存在。但我想做的是例如
nlp('What's the time')
和nlp('What time is it')
该值为true,但如果nlp('Time is gold')
该值为false,则用户不会询问时间。
这个库有可能吗?任何帮助将不胜感激。
答案 0 :(得分:3)
听起来你想做的是意图识别,这通常被视为分类问题。这个article概述了一种方法;看看训练数据:
training_data.append({"class":"greeting", "sentence":"how are you?"})
training_data.append({"class":"greeting", "sentence":"how is your day?"})
training_data.append({"class":"greeting", "sentence":"good day"})
training_data.append({"class":"greeting", "sentence":"how is it going today?"})
training_data.append({"class":"goodbye", "sentence":"have a nice day"})
training_data.append({"class":"goodbye", "sentence":"see you later"})
training_data.append({"class":"goodbye", "sentence":"have a nice day"})
training_data.append({"class":"goodbye", "sentence":"talk to you soon"})
training_data.append({"class":"sandwich", "sentence":"make me a sandwich"})
training_data.append({"class":"sandwich", "sentence":"can you make a sandwich?"})
training_data.append({"class":"sandwich", "sentence":"having a sandwich today?"})
training_data.append({"class":"sandwich", "sentence":"what's for lunch?"})
妥协没有任何文字分类功能,所以它对你没有帮助。
答案 1 :(得分:1)
但是,如果你知道,(或机器学习的)句子模板提出意图,你可以找到他们与match syntax
妥协//what time is..
if(doc.has('#QuestionWord time #Copula')){
return true
}
//time is fun..
if(doc.has('time #Copula #Adjective')){
return false
}