파이썬과 스탠포드 CoreNLP를 사용하여 xml 파일을 구문 분석하는 데 많은 어려움을 겪고 있습니다. 내가하고 싶은 것은 스탠포드 코어 NLP로 nlp.txt를 분석하여 XML 파일로 출력하는 것입니다. 내가 무슨 일이 일어나고 있는지 이해할 수 없다, 내가 파일을 구문 분석 할 수 붙어 있다고 생각하지만오류 : 파이썬과 스탠포드 CoreNLP를 사용하여 xml을 구문 분석하려고 시도했습니다.
Traceback (most recent call last):
File "stanford.py", line 30, in <module>
parse_nlp()
File "stanford.py", line 25, in parse_nlp
check=True # error check
File "/anaconda/lib/python3.6/subprocess.py", line 418, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'java -cp "/usr/local/lib/stanford-corenlp-full-2017-06-09/*" -Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -file nlp.txt 2>parse.out' returned non-zero exit status 1.
나는이 문제를 어떻게 해결할 수 : 내가 좋아하는 표준 오류를 얻을, 그리고
import os
import subprocess
import xml.etree.ElementTree as ET
fname = 'nlp.txt'
fname_parsed = 'nlp.txt.xml'
def parse_nlp():
'''Analyze nlp.txt with Stanford Core NLP and output it to xml file.
Do not execute if result file already exists.
'''
if not os.path.exists(fname_parsed):
# Execute StanfordCoreNLP, output standard error to parse.out
subprocess.run(
'java -cp "/usr/local/lib/stanford-corenlp-full-2017-06-09/*"'
' -Xmx2g'
' edu.stanford.nlp.pipeline.StanfordCoreNLP'
' -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref'
' -file ' + fname + ' 2>parse.out',
shell=True, # execute with shell
check=True # error check
)
# analyze nlp.txt
parse_nlp()
# parse xml of result
root = ET.parse(fname_parsed)
# take only word
for word in root.iter('word'):
print(word.text)
: 내 코드는 여기에있다 발행물. 필자는 초보자 코딩을 비교적 쉽게하고 있으며 NLP 분석으로 옮겼습니다. 자세히 설명하면 정말 감사하겠습니다.
여전히 오류가 명령 줄에서 해당 명령이 작동을 확인해야지고합니다. – StanfordNLPHelp
실례합니다. 내 말은, 파이썬으로 xml 파일을 읽는 것을 의미합니까? – user7421972
이 명령을 subprocess로 호출하여 명령 줄 및 Python 스크립트에서 작동시킬 수 있습니까? 명령 : 'java -cp'/ usr/local/lib/stanford-corenlp-full-2017-06-09/* "-Xmx2g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators 토큰 화, ssplit, pos, 보조 정리 , 구문 분석, dcoref -file nlp.txt 2> parse.out ' – StanfordNLPHelp