简体   繁体   English

自动化斯坦福解析器的二进制化器时出错(Python)

[英]Error in automating binarizer of stanford parser (Python)

I am using Stanford Parser to generate trees from the given data in the required annotated format. 我正在使用Stanford Parser以所需的带注释格式从给定数据生成树。 I am able to do it for a single file by running: 我可以通过运行以下命令为单个文件执行此操作:

./lexparser.sh input_file > output_file

from the stanford-parser-full-2018-02-27 folder. stanford-parser-full-2018-02-27文件夹中。 But, I have multiple files so I tried to automate it using python as follows : 但是,我有多个文件,因此我尝试使用python将其自动化,如下所示:

import os
import glob
import subprocess

for movie in glob.glob("../full_movies/annotated/*.txt"):
    tree = subprocess.call(['./lexparser.sh', os.path.basename(movie)])
    with open("../full_movies/trees/" + os.path.basename(movie), "w") as fid:
        fid.write(tree)

But it shows the following error : 但它显示以下错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J:无法加载类“ org.slf4j.impl.StaticLoggerBinder”。 SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. SLF4J:默认为不操作(NOP)记录器实现SLF4J:有关更多详细信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder Exception in thread "main" edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to open "movie_name.txt" as class path, filename or URL at edu.stanford.nlp.io.IOUtils.slurpFileNoExceptions(IOUtils.java:1316) at edu.stanford.nlp.sentiment.BuildBinarizedDataset.main(BuildBinarizedDataset.java:171) Caused by: java.io.IOException: Unable to open "movie_name.txt" as class path, filename or URL at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:480) at edu.stanford.nlp.io.IOUtils.readerFromString(IOUtils.java:637) at edu.stanford.nlp.io.IOUtils.slurpFile(IOUtils.java:1159) at edu.stanford.nlp.io.IOUtils.slurpFile(IOUtils.java:1184) at edu.stanford.nlp.io.IOUtils.slurpFileNoExceptions(IOUtils.java:1314) ... 1 more 线程“主”中的异常edu.stanford.nlp.io.RuntimeIOException:java.io.IOException:无法在edu.stanford.nlp.io.IOUtils.slurpFileNoExceptions(处以类路径,文件名或URL打开“ movie_name.txt” edu.stanford.nlp.sentiment.BuildBinarizedDataset.main(BuildBinarizedDataset.java:171)上的IOUtils.java:1316)原因:java.io.IOException:无法在以下位置将“ movie_name.txt”作为类路径,文件名或URL打开edu.stanford.nlp.io.IOUtils.readerFromString(IOUtils.java:637)的edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:480)edu.stanford.nlp.io.IOUtils.slurpFile( IOUtils.java:1159)位于edu.stanford.nlp.io.IOUtils.slurpFile(IOUtils.java:1184)at edu.stanford.nlp.io.IOUtils.slurpFileNoExceptions(IOUtils.java:1314)...还有1

I am unable to understand this. 我不明白这一点。 Is it a mistake in my python script or something else is wrong here? 这是我的python脚本中的错误还是这里有其他错误? If you want to see the contents of ./lexparser.sh let me know. 如果您想查看./lexparser.sh的内容, ./lexparser.sh告诉我。 Thanks in advance. 提前致谢。

I think your problem is simple you just give Filenames to the lex parser, because you call basename on it. 我认为您的问题很简单,只需将文件名提供给lex解析器,因为您在其上调用了基名。 But since lexparser isn't in the same directory as the files you need to give the full path to the files. 但是由于lexparser与文件不在同一目录中,因此需要提供文件的完整路径。 Just use movie and delete the os.path.basename call. 只需使用movie并删除os.path.basename调用即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM