ExtractKeySentences.py 1.77 KB
Newer Older
LiniEisha's avatar
LiniEisha committed
1
import nltk
LiniEisha's avatar
LiniEisha committed
2
import os
LiniEisha's avatar
LiniEisha committed
3
from fpdf import FPDF
LiniEisha's avatar
LiniEisha committed
4

LiniEisha's avatar
LiniEisha committed
5
def LectureNotice(notice_name):
LiniEisha's avatar
LiniEisha committed
6

LiniEisha's avatar
LiniEisha committed
7 8
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    FILE_PATH = os.path.join(BASE_DIR, "speechToText\\{}".format(notice_name))
LiniEisha's avatar
LiniEisha committed
9
    DESTINATION_DIR = os.path.join(BASE_DIR, "notices\\Notice_{}".format(notice_name))
LiniEisha's avatar
LiniEisha committed
10 11
    print('destination directory: ', DESTINATION_DIR)

LiniEisha's avatar
LiniEisha committed
12 13
    text = ''
    read_lines = [line.rstrip('\n') for line in open(FILE_PATH, "r")]
LiniEisha's avatar
LiniEisha committed
14 15 16
    sentences_list = []
    sentence_list = nltk.sent_tokenize(read_lines)
    word_search = "important"
LiniEisha's avatar
LiniEisha committed
17
    sentences_with_word = []
LiniEisha's avatar
LiniEisha committed
18 19
    for sentence in sentence_list:
        if sentence.count(word_search)>0:
LiniEisha's avatar
LiniEisha committed
20
            sentences_with_word.append(sentence)
LiniEisha's avatar
LiniEisha committed
21 22 23 24 25 26 27 28 29

    words_search = ["exam", "assignment"]
    word_sentence_dictionary = {"exam":[],"assignment":[]}

    for word in words_search:
        sentences_with_word = []
        for sentence in sentences_list:
            if sentence.count(word)>0:
                sentences_with_word.append(sentence)
LiniEisha's avatar
LiniEisha committed
30 31
                word_sentence_dictionary[word] = sentences_with_word

LiniEisha's avatar
LiniEisha committed
32
    file = open('DESTINATION_DIR', 'w')
LiniEisha's avatar
LiniEisha committed
33 34
    file.close()

LiniEisha's avatar
LiniEisha committed
35

LiniEisha's avatar
LiniEisha committed
36 37 38 39 40 41 42
# def SaveNotices():

    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    # PDF_DESTINATION_DIR = os.path.dirname(os.path.join(BASE_DIR, "summaryPDF\\sample.txt"))
    PDF_DESTINATION_DIR = os.path.join(BASE_DIR, "noticePDF\\Notice{}.pdf".format(notice_name))


LiniEisha's avatar
LiniEisha committed
43 44 45 46 47 48 49 50
    pdf = FPDF()
    # Add a page
    pdf.add_page()
    # set style and size of font
    # that you want in the pdf
    pdf.set_font("Arial", size=15)

    # open the text file in read mode
LiniEisha's avatar
LiniEisha committed
51
    f = open("DESTINATION_DIR", "r")
LiniEisha's avatar
LiniEisha committed
52 53 54 55 56 57

    # insert the texts in pdf
    for x in f:
        pdf.cell(200, 10, txt=x, ln=1, align='C')

    # save the pdf with name .pdf
LiniEisha's avatar
LiniEisha committed
58 59 60
    pdf.output("PDF_DESTINATION_DIR")

    return text