I need help shorting my code! what can I do to write a cleaner code, or just reduce the paragraphs in my code by doing a list or loop? Can you revise my code and then give me an example code. Here's the code I did.  # importing the PyPDF2 module import PyPDF2 # This is to get the sentence from the pdf files library import re # creating a pdf file object and giving loaction of pdf file pdfFileobj=open('C:/Users/jalej/Downloads/new artcle.pdf','rb') # creating a pdf reader object pdfReader=PyPDF2.PdfFileReader(pdfFileobj) # creating a page object pageObj=pdfReader.getPage(0) # extracting text from page print(pageObj.extractText()) # finally closing the pdf file object pdfFileobj.close() from pdfminer.high_level import extract_text # extracting the text from page numbers 1-8 result = extract_text('C:/Users/jalej/Downloads/new artcle.pdf',page_numbers=[0,1,2,3,4,5,6,7])   print(result) text = pageObj.extractText() # Getting the MHz from the pdf file  searched_parameter = 'MHz' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+MHz+[^.](?:.\d+)?)', result) print(sentences) # Getting the KHz from the pdf file  searched_parameter = 'KHz' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+KHz+[^.](?:.\d+)?)', result) print(sentences) # Getting the keyword of frequency from the pdf file searched_parameter = 'center frequency' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+center frequency+[^.](?:.\d+)?)', result) print(sentences) # Getting the Intensity from the pdf file searched_parameter = 'Isppa' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+Isppa+[^.](?:.\d+)?)', result) print(sentences) # Getting the Intensity from the pdf file searched_parameter = 'W/cm^2' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+ W/cm^2+[^.](?:.\d+)?)', result) print(sentences) # Getting the Intensity from the pdf file searched_parameter = 'I_spta' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+I_spta+[^.](?:.\d+)?)', result) print(sentences) # Getting the Intensity from the pdf file searched_parameter = 'Intensity' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+Intensity+[^.](?:.\d+)?)', result) print(sentences) # Getting the pressure from the pdf file  searched_parameter = 'MPa' number_of_ocurrences = result.count(searched_parameter) print(number_of_ocurrences) sentences = re.findall(r'([^.]+MPa+[^.](?:.\d+)?)', result) print(sentences)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I need help shorting my code! what can I do to write a cleaner code, or just reduce the paragraphs in my code by doing a list or loop? Can you revise my code and then give me an example code. Here's the code I did. 

# importing the PyPDF2 module
import PyPDF2
# This is to get the sentence from the pdf files library
import re

# creating a pdf file object and giving loaction of pdf file
pdfFileobj=open('C:/Users/jalej/Downloads/new artcle.pdf','rb')

# creating a pdf reader object
pdfReader=PyPDF2.PdfFileReader(pdfFileobj)

# creating a page object
pageObj=pdfReader.getPage(0)

# extracting text from page
print(pageObj.extractText())

# finally closing the pdf file object
pdfFileobj.close()

from pdfminer.high_level import extract_text

# extracting the text from page numbers 1-8
result = extract_text('C:/Users/jalej/Downloads/new artcle.pdf',page_numbers=[0,1,2,3,4,5,6,7])
 
print(result)
text = pageObj.extractText()

# Getting the MHz from the pdf file 
searched_parameter = 'MHz'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+MHz+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the KHz from the pdf file 
searched_parameter = 'KHz'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+KHz+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the keyword of frequency from the pdf file
searched_parameter = 'center frequency'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+center frequency+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the Intensity from the pdf file
searched_parameter = 'Isppa'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+Isppa+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the Intensity from the pdf file
searched_parameter = 'W/cm^2'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+ W/cm^2+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the Intensity from the pdf file
searched_parameter = 'I_spta'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+I_spta+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the Intensity from the pdf file
searched_parameter = 'Intensity'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+Intensity+[^.](?:.\d+)?)', result)
print(sentences)

# Getting the pressure from the pdf file 
searched_parameter = 'MPa'
number_of_ocurrences = result.count(searched_parameter)
print(number_of_ocurrences)
sentences = re.findall(r'([^.]+MPa+[^.](?:.\d+)?)', result)
print(sentences)

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education