DS17


Q. 1) Write a Java Script Program to show Hello Good Morning message onload event using alert box
and display the Student registration from. [Marks 15]

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hello Good Morning</title> <script> window.onload = function() { alert("Hello! Good Morning"); };

function showRegistrationForm() {
document.getElementById("registrationForm").style.display = "block";
}
</script>

</head> <body> <!-- Student registration form --> <div id="registrationForm" style="display: none;"> <h2>Student Registration Form</h2> <form> <label for="name">Name:</label> <input type="text" id="name" name="name"><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email"><br><br> <label for="phone">Phone:</label> <input type="text" id="phone" name="phone"><br><br> <input type="submit" value="Submit"> </form> </div>

<button onclick="showRegistrationForm()">Show Registration Form</button>

</body> </html>

Q. 2)Consider text paragraph.So, keep working. Keep striving. Never give up. Fall down seven times, get
up eight. Ease is a greater threat to progress than hardship. Ease is a greater threat to progress than
hardship. So, keep moving, keep growing, keep learning. See you at work.Preprocess the text to remove
any special characters and digits. Generate the summary using extractive summarization process
import re
from nltk.tokenize import sent_tokenize
from nltk.corpus import stopwords
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity

Text paragraph

text = """
So, keep working. Keep striving. Never give up. Fall down seven times, get up eight.
Ease is a greater threat to progress than hardship. Ease is a greater threat to progress than hardship.
So, keep moving, keep growing, keep learning. See you at work.
"""

Preprocess the text to remove special characters and digits

processed_text = re.sub(r'\W+', ' ', text) # Remove special characters
processed_text = re.sub(r'\d+', ' ', processed_text) # Remove digits

Tokenize the text into sentences

sentences = sent_tokenize(processed_text)

Remove stopwords

stop_words = set(stopwords.words("english"))
filtered_sentences = [sentence for sentence in sentences if sentence.lower() not in stop_words]

Calculate importance score for each sentence using CountVectorizer and cosine similarity

vectorizer = CountVectorizer().fit_transform(filtered_sentences)
cosine_matrix = cosine_similarity(vectorizer, vectorizer)

Generate summary by selecting top-ranked sentences

summary_length = 2 # Number of sentences in the summary
summary_indices = cosine_matrix.argsort()[::-1][:summary_length] # Indices of top-ranked sentences
summary = [filtered_sentences[i] for i in sorted(summary_indices)]

Print the summary

print("\n".join(summary))