Context-free grammar

We have seen the basic concept of context-free grammar in Chapter 3, Understanding Structure of Sentences. We have already seen the formal definition of the CFG to find a moment and recall it. Now we will see how the rules of grammar are important when we build a parser.

CFG is also referred to as phrase structure grammar. So, CFG and phrase structure grammar are two terms but refer to one concept. Now, let's see some examples related to this type of grammar and then talk about the conventions that are followed in order to generate a more natural form of grammar rules. Refer to the grammar rules, lexicons, and sentences in Figure 5.6:

Figure 5.6: CFG rules, lexicon, and sentences

Here, S is the starting point of grammar. ...

Get Python Natural Language Processing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.