#! /usr/bin/env/ python import sys # Be sure to have a file named 'small.txt' in the same directory as # this program (or change the value of document_name) document_name = "small.txt" # --------------------- # Function #1: match_and def match_and(query,document): """ INPUT: query is a list of search terms, document is a list of words from a document OUTPUT: 1, if all terms are matched 0, if not all terms are matched""" matched = 0 ##### ## Your code goes here! ##### return matched # --------------------- # Function #2: match_or def match_or(query,document): """ INPUT: query is a list of search terms, document is a list of words from a document OUTPUT: 1, if at least one term is matched 0, if no terms are matched""" matched = 0 ##### ## Your code goes here! ##### return matched # ----------------- # Main body of code print "Please enter a query and hit return!" sys.stdout.flush() raw_query = raw_input() #raw_query = raw_input("Please enter a query and hit return!\n") print "Thank you!\n" #print raw_query query_words = raw_query.split() document_file = open(document_name,'r') document = document_file.readlines() document_words = [] for line in document: line = line.rstrip() words = line.split() document_words = document_words + words document_file.close() print "Results of match_and ..." if match_and(query_words,document_words): print "\tAll words in your query are in the document" else: print "\tNot all words in your query are in the document" print print "Results of match_or ..." if match_or(query_words,document_words): print "\tAt least one of the words in your query is in the document" else: print "\tNone of the words in your query are in the document" print