Skip to content

Commit 7250f93

Browse files
committed
Drop the recursion check
1 parent 80528f5 commit 7250f93

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

nltk/grammar.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Jason Narad <[email protected]>
77
# Peter Ljunglöf <[email protected]>
88
# Tom Aarsen <>
9-
# Eric Kafe <[email protected]>
109
# URL: <https://www.nltk.org/>
1110
# For license information, see LICENSE.TXT
1211
#
@@ -305,9 +304,6 @@ def rhs(self):
305304
"""
306305
return self._rhs
307306

308-
def is_recursive(self):
309-
return self.lhs() in self.rhs()
310-
311307
def __len__(self):
312308
"""
313309
Return the length of the right-hand side.
@@ -609,12 +605,6 @@ def productions(self, lhs=None, rhs=None, empty=False):
609605
if prod in self._rhs_index.get(rhs, [])
610606
]
611607

612-
def is_recursive(self):
613-
for prod in self.productions():
614-
if prod.is_recursive():
615-
return True
616-
return False
617-
618608
def leftcorners(self, cat):
619609
"""
620610
Return the set of all nonterminals that the given nonterminal

nltk/parse/generate.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ def generate(grammar, start=None, depth=None, n=None):
2727
if not start:
2828
start = grammar.start()
2929
if depth is None:
30-
if grammar.is_recursive():
31-
# This seems to be an almost maximal safe default with Python 3:
32-
depth = (sys.getrecursionlimit() // 3) - 3
33-
else:
34-
depth = sys.maxsize
30+
# Safe default, assuming the grammar may be recursive:
31+
depth = (sys.getrecursionlimit() // 3) - 3
3532

3633
iter = _generate_all(grammar, [start], depth)
3734

0 commit comments

Comments
 (0)