Giter VIP home page Giter VIP logo

ex-6--aai's Introduction

NAME: Shaik Shoaib Nawaz

REGISTER NO: 212222240094

EX. NO.6

DATE:

Implementation of Semantic ANalysis

Aim:

To perform Parts of speech identification and Synonym using Natural Language Processing (NLP) techniques. </H3> 

Algorithm:

Step 1: Import the nltk library.
Step 2: Download the 'punkt', 'wordnet', and 'averaged_perceptron_tagger' resources.
Step 3:Accept user input for the text.
Step 4:Tokenize the input text into words using the word_tokenize function.
Step 5:Iterate through each word in the tokenized text.
• Perform part-of-speech tagging on the tokenized words using nltk.pos_tag.
• Print each word along with its corresponding part-of-speech tag.
• For each verb , iterate through its synsets (sets of synonyms) using wordnet.synsets(word).
• Extract synonyms and antonyms using lemma.name() and lemma.antonyms()[0].name() respectively.
• Print the unique sets of synonyms and antonyms.

Program:

!pip install nltk
import nltk
#import wordnet
nltk.download( 'punkt' )
nltk.download('wordnet')
from nltk.tokenize import word_tokenize
nltk.download( 'averaged_perceptron_tagger' )
sentence=input()
# Tokenize the sentence into words
words = word_tokenize(sentence)
# Identify the parts of speech for each word
pos_tags= nltk.pos_tag(words)
# Print the parts of speech
for word, tag in pos_tags:
	print(word, tag)
 from nltk.corpus import wordnet

# Identify synonyms and antonyms for each word
synonyms =[]
antonyms =[]
for word in words:
	for syn in wordnet.synsets(word) :
		for lemma in syn.lemmas():
			synonyms . append (lemma . name( ) )
			if lemma . antonyms():
				antonyms . append ( lemma. antonyms ( ) [0] . name ( ) )
# Print the synonyms and antonyms
print ( "Synonyms : " ,set (synonyms) )
print ( "Antonyms : " ,set(antonyms) )

Output

i.) Sample Input

image

ii.) Sample Output

image

image

Result:

Thus ,the program to perform the Parts of Speech identification and Synonymis executed sucessfully.

ex-6--aai's People

Contributors

lavanyajoyce avatar shoaib3136 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.