Closed Vimos closed 4 years ago
"Context managers allow you to allocate and release resources precisely when you want to. "
当前文档使用方法
from pyltp import Segmentor segmentor = Segmentor() # 初始化实例 segmentor.load(cws_model_path) # 加载模型 words = segmentor.segment('元芳你怎么看') # 分词 print '\t'.join(words) segmentor.release() # 释放模型
可否支持Context Manager,可以节省释放模型的过程
Context Manager
from pyltp import Segmentor with Segmentor() as segmentor: # 初始化实例 segmentor.load(cws_model_path) # 加载模型 words = segmentor.segment('元芳你怎么看') # 分词 print('\t'.join(words))
"Context managers allow you to allocate and release resources precisely when you want to. "
当前文档使用方法
可否支持
Context Manager
,可以节省释放模型的过程