#where text is the complete string and dic is a dictionary def replace_all(text, dic): for i, j in dic.items():#.items will give us both key ans value pair #The syntax of replace() is:str.replace(old, new [, count]) text = text.replace(i, j)#i is key and j is value return text a = replace_all(text, dic) a 'because following are because graphical (non-control) characters defined because' import string aa=('bcz,bcz,and bcz') aa 'bcz,bcz,and bcz' new_str = str.replace(aa,'bcz','Because') print(new_str) Because,Because,and Because 3. How do you deal with the English text having Hindi words in between?
Ans: There are two ways to treat Hindi text between English words: Translate the Hindi Words to English: Lookup all the words in English dictionary and tag them such as Remove the Hindi Words: Using the words corpus from NLTK ( The Natural Language Toolkit). Q.4Write R code to connect with this public API - Ans: rm(list = ls()) library(usethis) install.packages("devtools") library(usethis) library(httr) library(jsonlite) Query<-("") result<-GET(url=Query) content(result) class(data) # Shows raw data which is not structured and readable jsonRespText<-content(result,as="text") jsonRespText
You've reached the end of your free preview.
Want to read all 3 pages?