Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 1 — Levels of Language Processing: Syntactic & Semantic

Lesson 4 of 39 in the free Natural Language Processing notes on Siksha Sarovar, written by Rohit Jangra.

Syntactic and Semantic Analysis

Syntactic Analysis (Parsing)

Syntax concerns how words combine to form grammatically correct sentences. Syntactic analysis checks a sentence against the grammar rules of a language and produces a structural representation, usually a parse tree.

        S
      /   \
    NP      VP
    |      /  \
  "Riya"  V    NP
         |     |
       "reads" "books"

A grammar defines rules such as:

S  -> NP VP
NP -> Det N | N
VP -> V NP
import nltk
from nltk import CFG, ChartParser

grammar = CFG.fromstring("""
S -> NP VP
NP -> 'Riya' | 'books'
VP -> V NP
V -> 'reads'
""")
parser = ChartParser(grammar)
for tree in parser.parse(['Riya', 'reads', 'books']):
    print(tree)
# (S (NP Riya) (VP (V reads) (NP books)))

Syntactic ambiguity arises when a sentence has more than one valid parse tree:

# "I saw the man with a telescope" has two valid parses:
# 1. I used a telescope to see the man   (PP attaches to VP)
# 2. The man had a telescope             (PP attaches to NP "the man")

We study grammars and parsing algorithms (CFG, top-down, bottom-up, CYK) in detail in Unit 2.

Semantic Analysis

Semantics is the study of meaning. While syntax checks whether a sentence is grammatically well-formed, semantics checks whether it is meaningful.

Classic example (Noam Chomsky): "Colorless green ideas sleep furiously." This sentence is syntactically correct (NP + VP structure) but semantically anomalous — "colorless" and "green" contradict, and "ideas" cannot literally "sleep".

Semantic analysis involves:

TaskDescription
Word sense assignmentChoosing the correct meaning of an ambiguous word in context
Semantic role labelingIdentifying who did what to whom ("Riya" = agent, "books" = theme)
Compositional semanticsCombining word meanings into sentence meaning
Named entity semanticsRecognizing that "Paris" can be a city or a person's name
# Semantic role labeling (conceptual)
sentence = "Riya gave Zoya a book."
# Agent:      Riya
# Recipient:  Zoya
# Theme:      a book
# Action:     gave

Semantic analysis is what lets a system understand that "The cat chased the mouse" and "The mouse was chased by the cat" describe the same event, despite different syntax (active vs passive voice).