APPENDIX CCode for search.py

This appendix displays the code blocks as described and discussed in Chapter 4, “Computational Thinking in Practice.” Each code block is labeled alphabetically for more convenient reference.

A

# search.py
 
# Like in the app.py code, software modules are loaded in to help set up the
# software environment.
# No need to duplicate the code here!
 
# creates the ResultElement object, containing rank value and filename
app = Flask(__name__)
 
app.config['UPLOAD_FOLDER'] = 'Original_Resumes/'
app.config['ALLOWED_EXTENSIONS'] = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
 
class ResultElement:
    def __init__(self, rank, filename):
        self.rank = rank
        self.filename = filename
 
def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1] in app.config['ALLOWED_EXTENSIONS']
 
import re, string, unicodedata # software libraries for regular expressions, strings.
import nltk # natural language toolkit software library
import contractions # software library to handle English's contraction structure
import inflect
# software library for pulling data out of HTML and XML files
from bs4 import BeautifulSoup
# software library for identifying words (tokens) in a stream of text
from nltk import word_tokenize, sent_tokenize
# software library that lists stop words for each language
from nltk.corpus import stopwords
# software library for finding the root words/meanings of words
from nltk.stem import LancasterStemmer, WordNetLemmatizer ...

Get Data Conscience now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.