vector_space_model/Int/VSM-master/vsm.py
def do_search():
    """Asks the user what they would like to search for, and returns a
    list of relevant documents, in decreasing order of cosine
    similarity."""
    query = tokenize(raw_input("Search query >> "))
    if query == []:
        sys.exit()
    # find document ids containing all query terms.  Works by
    # intersecting the posting lists for all query terms.
    relevant_document_ids = intersection(
            [set(postings[term].keys()) for term in query])
    if not relevant_document_ids:
        print "No documents matched all query terms."
    else:
        scores = sorted([(id,similarity(query,id))
                         for id in relevant_document_ids],
                        key=lambda x: x[1],
                        reverse=True)
        print "Score: filename"
        for (id,score) in scores:
            print str(score)+": "+document_filenames[id]
Asks the user what they would like to search for, and returns a
    list of relevant documents, in decreasing order of cosine
    similarity.
Asks the user what they would like to search for, and returns a
list of relevant documents, in decreasing order of cosine
similarity.
Asks the user what they would like to search for and returns a list of relevant documents in decreasing order of cosine similarity .
def do_search():
    query = tokenize(raw_input("Search query >> "))
    if query == []:
        sys.exit()
    relevant_document_ids = intersection(
            [set(postings[term].keys()) for term in query])
    if not relevant_document_ids:
        print "No documents matched all query terms."
    else:
        scores = sorted([(id,similarity(query,id))
                         for id in relevant_document_ids],
                        key=lambda x: x[1],
                        reverse=True)
        print "Score: filename"
        for (id,score) in scores:
            print str(score)+": "+document_filenames[id]
def do_search ( ) : query = tokenize ( raw_input ( "Search query >> " ) ) if query == [ ] : sys . exit ( ) relevant_document_ids = intersection ( [ set ( postings [ term ] . keys ( ) ) for term in query ] ) if not relevant_document_ids : print "No documents matched all query terms." else : scores = sorted ( [ ( id , similarity ( query , id ) ) for id in relevant_document_ids ] , key = lambda x : x [ 1 ] , reverse = True ) print "Score: filename" for ( id , score ) in scores : print str ( score ) + ": " + document_filenames [ id ]
Asks the user what they would like to search for, and returns a
list of relevant documents, in decreasing order of cosine
similarity.
Asks the user what they would like to search for and returns a list of relevant documents in decreasing order of cosine similarity .
"""Asks the user what they would like to search for, and returns a
    list of relevant documents, in decreasing order of cosine
    similarity.""" # find document ids containing all query terms.  Works by # intersecting the posting lists for all query terms.