之前有介绍过图形化生成的过程,但是需求变了,需要把数据预处理的现成东西写成一个完整的模块,我使用python方法调用java程序,来使用stanford parse。
这个是使用命令来执行:(就是官方打包好的一个例子)
然后就开始看我们的正儿八经的代码吧:
在数据预处理 中,使用cmd调用stanford parse的代码
def dependency_parse(filepath, cp='', tokenize=True):
print('\nDependency parsing ' + filepath)
dirpath = os.path.dirname(filepath)#得到文件的绝对路径
filepre = os.path.splitext(os.path.basename(filepath))[0]#得到路径中最后的文件名和后缀
tokpath = os.path.join(dirpath, filepre + '.toks')
parentpath = os.path.join(dirpath, filepre + '.parents')
relpath = os.path.join(dirpath, filepre + '.rels')
tokenize_flag = '-tokenize - ' if tokenize else ''
cmd = ('