def predict(utterance):
try:
tagged = []
finallist = []
parsed = nlp(utterance)
for i in range(len(parsed)):
tagged.append((str(parsed[i]),parsed[i].tag_))
finallist.append(tagged)
test = [sent2features(s) for s in finallist]
if(os.path.isfile("crfModel/classifier.pkl")):
crf = joblib.load("crfModel/classifier.pkl")
else:
return {'success':False,'message':'Please Train the model first'}
predicted = crf.predict(test)
entityList = extractEntities(predicted[0],tagged)
return {'success':True,'entitiesPredicted':entityList}
except Exception as ex:
return {'success':False,'message':'Error while pediction - '+str(ex)}
entityRecognition.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录