The Parser project focuses on implementing a context-free grammar (CFG) parser to analyze English sentences and extract noun phrases. The goal is to build a tool that can interpret sentence structures and provide insights into their grammatical components.
- Context-Free Grammar Parsing: Utilizes CFG to decompose sentences into their grammatical elements.
- Noun Phrase Extraction: Identifies and extracts noun phrases based on CFG rules.
- Tokenization and Normalization: Processes sentences into tokens and normalizes them for consistent analysis.
- Python 3
nltk
library
- Install NLTK:
pip install nltk
- Download Required NLTK Resources:
import nltk nltk.download('punkt')
parser.py
: Main script implementing the CFG parser and noun phrase extraction.sentences/[sentence_file].txt
: Text files containing sample sentences for parser testing.
-
Run the Parser:
python parser.py sentences/1.txt
- If a filename is specified, the script reads the sentence from that file.
- If no filename is provided, the script will prompt for an input sentence.
-
Example Code:
from parser import preprocess, np_chunk sentence = "The quick brown fox jumps over the lazy dog." tokens = preprocess(sentence) trees = list(parser.parse(tokens)) for tree in trees: tree.pretty_print() for np in np_chunk(tree): print(" ".join(np.flatten()))
- Grammar Definitions: CFG rules are specified in
TERMINALS
andNONTERMINALS
to represent sentence structure and parts of speech. - Preprocessing: The
preprocess
function tokenizes the input sentence, converts it to lowercase, and filters out non-alphabetic words. - Noun Phrase Chunking: The
np_chunk
function extracts noun phrases from the parse tree, avoiding nested noun phrases.
The parser provides visual representations of sentence structure and extracted noun phrases for various sample sentences.
For more information, visit the Parser Project.
parser's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
- Grammar Definitions: CFG rules are specified in