0
我正在使用Python使用斯坦福大學的NLP。所以,我有一個函數輸入一些文本文件並將它們轉換爲xml文件(由Stanford CoreNLP生成)。現在,我想編寫另一個函數來輸入這些xml文件,並輸出相應的文件,其中包含相同的文本,但命名實體替換爲它們的標記,並用「STOP」字標記句子末尾,刪除標點符號。文件的開頭也有「STOP」字樣。 給XML文件中的功能是:如何使用Python中的Stanford CoreNLP輸出一個文件,其中的命名實體被替換爲標籤?
import subprocess
def generate_xml(input,output):
p = subprocess.Popen('java -cp stanford-corenlp-2012-07-09.jar:stanford-corenlp-2012-07-06-models.jar:xom.jar:joda-time.jar -Xmx3g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner -filelist /Users/akritibahal/Downloads/stanford-corenlp-2012-07-09/myfile_list.txt -outputDirectory /Users/akritibahal/Downloads/stanford-corenlp-2012-07-09', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
print line
retval = p.wait()
的功能是將給出一個輸出文件,命名實體標籤:
def process_file(input_xml,output_file):
任何人可以幫助我如何獲得這樣的輸出文件名爲實體標籤?