這是我的代碼:不支持的操作類型爲>>:「builtin_function_or_method」和「_io.TextIOWrapper」
def _parse(self, text):
"""
This is the core interaction with the parser.
It returns a Python data-structure, while the parse()
function returns a JSON object
"""
# CoreNLP interactive shell cannot recognize newline
if '\n' in text or '\r' in text:
to_send = re.sub("[\r\n]", " ", text).strip()
else:
to_send = text
self.corenlp.sendline(to_send)
max_expected_time = max(300.0, len(to_send)/3.0)
# repeated_input = self.corenlp.except("\n") # confirm it
t = self.corenlp.expect(["\nNLP> ", pexpect.TIMEOUT, pexpect.EOF,
"\nWARNING: Parsing of sentence failed, possibly because of out of memory."],
timeout=max_expected_time)
incoming = self.corenlp.before
lag = incoming.split(b"\r\n")
incoming = b"\r\n".join(lag).decode('latin-1').encode('utf-8')
if t == 1:
# TIMEOUT, clean up anything left in buffer
print >>sys.stderr, {'error': "timed out after %f seconds" % max_expected_time,
'input': to_send,
'output': incoming}
raise TimeoutError("Timed out after %d seconds" % max_expected_time)
elif t == 2:
# EOF, probably crash CoreNLP process
print >>sys.stderr, {'error': "CoreNLP terminates abnormally while parsing",
'input': to_send,
'output': incoming}
raise ProcessError("CoreNLP process terminates abnormally while parsing")
elif t == 3:
# out of memory
print >>sys.stderr, {'error': "WARNING: Parsing of sentence failed, possibly because of out of memory.",
'input': to_send,
'output': incoming}
raise OutOfMemoryError
if VERBOSE:
print("%s\n%s" % ('=' * 40, incoming))
try:
results = parse_parser_results(incoming)
except ixception as e:
if VERBOSE:
print(traceback.format_exc())
raise e
self.pre_loaded_analisys_dict[to_send] = results
with open(self.pre_analysis,"w", encoding = 'utf-8') as f:
json.dump(self.pre_loaded_analisys_dict,f)
return results
而且我得到這個錯誤(我解析了很多方面的它是第一次,我已經得到了錯誤):
不支持的操作類型爲>>:「builtin_function_or_method」和「_io.TextIOWrapper」
什麼想法?
編輯:printint傳入變量i已經得到了這樣的:
b'Q \ r \ nAnnotation管道定時信息:\ r \ nTokenizerAnnotator: 0.0秒\ r \ nWordsToSentencesAnnotator:0.0秒\。 r \ nPagaggerAnnotator:0.0秒。\ r \ nMorphaAnnotator:0.1秒\ r \ nNERCombinerAnnotator:0.4秒。\ r \ n總計:0.6秒。在606.1 令牌337級的令牌/秒\ r \ nPipeline設置:0.0秒\ r \ n總時間 StanfordCoreNLP管道:138.7秒\ r \ n」
時,我應該得到這樣的事情。 :
b'Contusion膝關節\ r \ nSentence#1(3個令牌):\ r \ 膝蓋\ r \ n [文本的nContusion =挫傷CharacterOffsetBegin = 0 CharacterOffsetEnd = 9 PartOfSpeech = NN引理=挫傷NamedEntityTag = O] [Text = CharacterOffsetBegin = 10 CharacterOffsetEnd = 12 PartOfSpeech = IN引理= NamedEntityTag = O] [Text =膝蓋CharacterOffsetBegin = 13 CharacterOffsetEnd = 17 PartOfSpeech = NN引理=膝蓋NamedEntityTag = O] \ r」
錯誤發生在哪一行? –
我有這樣的:'Annotation pipeline timing information ...' – AEU