Creating Rule-Based Grammar Objects
Learn how to create and define rule-based grammar objects and get hands-on to implement rule-based grammar objects.
We'll cover the following
Steps to creating grammar objects
Creating rule-based grammar objects is a relatively straightforward process. We will perform the following in order to build our grammar objects:
Define the grammar rules that we want to check for.
Implement each of the grammar rules into its own Python function.
Split the input text into sentences and iterate over each of our grammar objects for any violations.
Defining grammar rules
Since this is a toy project, we will focus on a small subsample of common grammatical errors to check for, and within that, just the "ideal case" meaning we will not be catching all possible English rules. Pseudocode will be provided here to assist with implementation at the end of this lesson, with most of the omitted implementation being around using our POS tagger to determine parts of speech (e.g., using our POS tagger to determine if a word is plural). We will be implementing the three rules below:
Subject-verb agreement: This simply means that when using an article (e.g., "a", "an"), the article agrees with the proceeding word. We would not say "a orange" we would say "an orange".
Get hands-on with 1400+ tech skills courses.