s np vp pp p np np det n np pp p vp v np vp pp vp det det a the n dog cat v chased sat p on in s np vp np vp n p vp p n dog cat p on in s np vp pp p np np det n np pp p vp v np vp pp vp det det a the n dog cat v chased sat p on in s np vp np vp n p vp p n dog cat p on in
import unittest

import nltk
from nltk.grammar import CFG


class ChomskyNormalFormForCFGTest(unittest.TestCase):
    def test_simple(self):
        grammar = CFG.fromstring(
            
        )
        self.assertFalse(grammar.is_flexible_chomsky_normal_form())
        self.assertFalse(grammar.is_chomsky_normal_form())
        grammar = grammar.chomsky_normal_form(flexible=True)
        self.assertTrue(grammar.is_flexible_chomsky_normal_form())
        self.assertFalse(grammar.is_chomsky_normal_form())

        grammar2 = CFG.fromstring(
            
        )
        self.assertFalse(grammar2.is_flexible_chomsky_normal_form())
        self.assertFalse(grammar2.is_chomsky_normal_form())
        grammar2 = grammar2.chomsky_normal_form()
        self.assertTrue(grammar2.is_flexible_chomsky_normal_form())
        self.assertTrue(grammar2.is_chomsky_normal_form())

    def test_complex(self):
        grammar = nltk.data.load("grammars/large_grammars/atis.cfg")
        self.assertFalse(grammar.is_flexible_chomsky_normal_form())
        self.assertFalse(grammar.is_chomsky_normal_form())
        grammar = grammar.chomsky_normal_form(flexible=True)
        self.assertTrue(grammar.is_flexible_chomsky_normal_form())
        self.assertFalse(grammar.is_chomsky_normal_form())