text paragraph
BookInfo.xml
<?xml version="1.0" encoding="utf-8"?> <BookList> <Book> <Title>The Great Gatsby</Title> <Author>F. Scott Fitzgerald</Author> <Year>1925</Year> <Price>$7.99</Price> </Book> <Book> <Title>To Kill a Mockingbird</Title> <Author>Harper Lee</Author> <Year>1960</Year> <Price>$8.99</Price> </Book> <Book> <Title>The Catcher in the Rye</Title> <Author>J.D. Salinger</Author> <Year>1951</Year> <Price>$9.99</Price> </Book> </BookList> Html file : <!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <script> function getBookDetails(bookName) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var xmlDoc = this.responseXML; var book = xmlDoc.getElementsByTagName("Book"); for (var i = 0; i < book.length; i++) { if (book[i].getElementsByTagName("Title")[0].childNodes[0].nodeValue == bookName) { alert("Author: " + book[i].getElementsByTagName("Author") [0].childNodes[0].nodeValue + "\n" + "Year: " + book[i].getElementsByTagName("Year")[0].childNodes[0].nodeValue + "\ n" + "Price: " + book[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue); } } } }; xhttp.open("GET", "BookInfo.xml", true); xhttp.send(); } // Call the getBookDetails function getBookDetails("The Catcher in the Rye"); </script> </body> </html>Importre
Importnltk
Fromnltk.corpusi
Fromnltk.tokeni
mportstopwords
zeimportsent_tokeni
ze,word_tokeni
Fromheapqimportnlargest
#Sampletextparagraphyoucanwriteanytext
Text=“Naturallanguageprocessi
ze
ng(NLP)isasubfieldoflingui
informati
onengineering,andarti
fici
alintel
ligenceconcernedwiththei
computersandhumanlanguages,inparticul
alcharactersand
stics,computersci
ence,
nteracti
onsbetween
arhowtoprogramcomputerstoprocessand
analyzelargeamountsofnaturall
anguagedata.Challengesinnaturall
anguageprocessing
frequentl
yinvolvespeechrecogni
tion,naturall
generati
on.Thehistoryofnaturall
anguageunderstanding,andnaturall
anguageprocessinggenerall
anguage
ystartedinthe1950s,al
though
workcanbefoundfromearlierperiods.”
#Removespecialcharactersanddigits
Text=re.sub(‘
[^a-zA-Z]
’,‘‘
,text)
#Tokenizethetextintosentences
Sentences=sent_tokeni
ze(text)
#Tokenizeeachsentenceintowordsandremovestopwords
Stop_words=set(stopwords.words(‘
english’
Words=[]
Forsentenceinsentences:
Words.extend(word_tokeni
ze(sentence))
))
Words=[word.lower()forwordinwordsifword.l
ower()notinstop_words]
#Calculatewordfrequency
Word_freq=nltk.FreqDi
st(words)
#Calculatesentencescoresbasedonwordfrequency
Sentence_scores={}
Forsentenceinsentences:
Forwordinword_tokenize(sentence.
Ifwordinword_freq:
Iflen(sentence.
split(‘‘
))<30:
lower()):
Ifsentencenotinsentence_scores:
Sentence_scores[sentence]=word_freq[
Else:
word]
Sentence_scores[sentence]+=word_freq[
word]
#Generatesummarybyselectingtop3sentenceswithhighestscores
Summary_sentences=nlargest(3,sentence_scores,key=sentence_scores.
get)
Summary=‘‘.join(summary_sentences)
Print(summary)