下面是调试我遇到的错误的分步代码:
from nltk.tree import ParentedTree
teststr = 'a) Any service and handling fee imposed on customers by Used Motor Vehicle Dealers subject to these Rules: \r\n 1) shall be charged uniformly to all retail customers; \r\n 2) may not be presented as mandatory in writing, electronically, verbally, via American Sign Language, or via other media as mandatory; nor presented as mandatory or mandated by any entity, other than the Arkansas Used Motor Vehicle Dealer who or dealership which is legally permitted to invoice, charge and collect the service and handling fee established by these Rules; \r\n 3) must follow the procedures for disclosure set out by these Rules.'
#Using ALLENNLP's parser
from allennlp.predictors.predictor import Predictor
conspredictor = Predictor.from_path("https://s3-us-west-2.amazonaws.com/allennlp/models/elmo-constituency-parser-2018.03.14.tar.gz")
treestr = conspredictor.predict(sentence=teststr)['trees']
ptree = ParentedTree.fromstring(treestr)
以下是我收到的回溯错误:
<ipython-input-391-f600cbe3ff5e> in <module>
10 treestr = conspredictor.predict(sentence=teststr)['trees']
11
---> 12 ptree = ParentedTree.fromstring(treestr)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\nltk\tree.py in fromstring(cls, s, brackets, read_node, read_leaf, node_pattern, leaf_pattern, remove_empty_top_bracketing)
616 if token[0] == open_b:
617 if len(stack) == 1 and len(stack[0][1]) > 0:
--> 618 cls._parse_error(s, match, 'end-of-string')
619 label = token[1:].lstrip()
620 if read_node is not None: label = read_node(label)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\nltk\tree.py in _parse_error(cls, s, match, expecting)
677 offset = 13
678 msg += '\n%s"%s"\n%s^' % (' '*16, s, ' '*(17+offset))
--> 679 raise ValueError(msg)
680
681 #////////////////////////////////////////////////////////////
ValueError: ParentedTree.read(): expected 'end-of-string' but got '(:'
at index 273.
"...es))))))) (: :) (S (..."
^
目前没有回答
相关问题 更多 >
编程相关推荐