I am using python3 and nltk using the stanford dependency analyzer to parse a list of sentences. Then, with the proposal, I collect all the information about the nodes. The following is my code, and it runs in python3 and in a virtualenv environment called .python:
from nltk.parse.stanford import StanfordDependencyParser parser = StanfordDependencyParser('stanford-parser-full-2015-12-09/stanford-parser.jar', 'stanford-parser-full-2015-12-09/stanford-parser-3.6.0-models.jar'); graph_nodes = sum([[dep_graph.nodes for dep_graph in dep_graphs] for dep_graphs in parser.raw_parse_sents(sentences)], []);
I will find out that the stanford dependency analyzer continues to cause statement errors in some sentences. Here are the errors I get:
graph_nodes = sum([[dep_graph.nodes for dep_graph in dep_graphs] for dep_graphs in self.parser.raw_parse_sents(sentences)], []); File "/Users/user/sent_code/.python/lib/python3.5/site-packages/nltk/parse/stanford.py", line 150, in raw_parse_sents return self._parse_trees_output(self._execute(cmd, '\n'.join(sentences), verbose)) File "/Users/user/sent_code/.python/lib/python3.5/site-packages/nltk/parse/stanford.py", line 91, in _parse_trees_output res.append(iter([self._make_tree('\n'.join(cur_lines))])) File "/Users/user/sent_code/.python/lib/python3.5/site-packages/nltk/parse/stanford.py", line 339, in _make_tree return DependencyGraph(result, top_relation_label='root') File "/Users/user/sent_code/.python/lib/python3.5/site-packages/nltk/parse/dependencygraph.py", line 84, in __init__ top_relation_label=top_relation_label, File "/Users/user/sent_code/.python/lib/python3.5/site-packages/nltk/parse/dependencygraph.py", line 328, in _parse assert cell_number == len(cells) AssertionError
Then I found a suggestion that caused this error. It:
'for all of its insights into the dream world of teen life , and its electronic expression through cyber culture , the film gives no quarter to anyone seeking to pull a cohesive story out of its 2 1/2-hour running time . \n'
I changed the sentence several times to find out what caused the approval error. It seems that when I remove the "/" from it, the sentence can be analyzed. When I include "/" in it, an assertion error occurs.
I wonder if there are special characters that cause the problem. I go back to the nltk source code to check what causes this assertion error (search for βapproveβ on the website: http://www.nltk.org/_modules/nltk/parse/dependencygraph.html ), but could not figure out what caused the errors.
Can someone explain why the error occurs and how to fix it?