From 4881fff318adbcf2abfa2e2c07a5cc08e0585b14 Mon Sep 17 00:00:00 2001 From: Daksh Shah Date: Wed, 23 Dec 2020 14:38:06 +0530 Subject: [PATCH] Remove duplicate productions in CNF for CFGs (#2435) Co-authored-by: Steven Bird --- AUTHORS.md | 1 + nltk/grammar.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index aa40a24d4e..20180034e2 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -263,6 +263,7 @@ - Nicolas Darr - Hervé Nicol - Alexandre H. T. Dias +- Daksh Shah - Jacob Weightman - Bonifacio de Oliveira - Armins Bagrats Stepanjans diff --git a/nltk/grammar.py b/nltk/grammar.py index fe04c01b97..97e6741ef4 100644 --- a/nltk/grammar.py +++ b/nltk/grammar.py @@ -770,7 +770,8 @@ def chomsky_normal_form(self, new_token_padding="@$@", flexible=False): if flexible: return step2 step3 = CFG.remove_unitary_rules(step2) - return step3 + step4 = CFG(step3.start(),list(set(step3.productions()))) + return step4 @classmethod def remove_unitary_rules(cls, grammar):