Basic Parsing Techniques
Basic Parsing Techniques
Parsing in Natural Language Processing (NLP) refers to the process of analyzing a sentence or a
string of words to determine its grammatical structure with respect to a given formal grammar.
This involves identifying the parts of speech of the words, their syntactic relationships, and how
they combine to form phrases and sentences. Parsing helps in understanding the syntactic and
semantic meaning of the text.
1. Top-Down Parsing
Definition: Top-down parsing starts with the start symbol and tries to derive the input sentence by
applying production rules. It works from the highest level of the grammar (the start symbol) down
to the terminals.
Example:
1. S→NP VP
2. NP→Det N
3. VP→V NP
4. Det→the
5. N→cat
6. V→sees
7. N→dog
Sentence to Parse:
o S→NP VP
3. Expand NP:
o NP→Det N
4. Expand VP
o VP→V NP
S→Det N V NP
7. Continue with V:
Summary:
Definition: Bottom-up parsing starts with the input sentence and works up to the start symbol,
attempting to reduce the sentence to the start symbol by applying production rules in reverse.
Example:
1. S→NP VP
2. NP→Det N
3. VP→V NP
4. Det→the
5. N→cat
6. V→sees
7. N→dog
Sentence to Parse:
Sentence to Parse:
"The cat sees the dog"
Bottom-Up Parsing Steps:
Stack: []
Input: ["The", "cat", "sees", "the", "dog"]
Stack: ["The"]
Input: ["cat", "sees", "the", "dog"]
4. Reduce "The" to Det:
Stack: [Det]
Input: ["cat", "sees", "the", "dog"]
Using rule Det→the
6. Reduce "cat" to N:
Stack: [Det, N]
Input: ["sees", "the", "dog"]
Using rule N→cat
Stack: [NP]
Input: ["sees", "the", "dog"]
Using rule NP→Det N
8. Shift "sees" onto the Stack:
9. Reduce "sees" to V:
Stack: [NP, V]
Input: ["the", "dog"]
Using rule V→sees
16. Reduce NP VP to S:
Stack: [S]
Input: []
Using rule S→NP VP
Summary: