Beispiel #1
0
def search(query, scorer, index):
    """
    Retrieve documents matching a query using the specified scorer.

    1) Tokenize the query.
    2) Convert the query tokens to a vector, using Index.query_to_vector.
    3) Call the scorer's score function.
    4) Return the list of document ids in descending order of relevance.

    NB: Due to the inconsistency of floating point arithmetic, when sorting,
    round the scores to 6 decimal places (e.g., round(x, 6)). This will ensure
    replicable results.

    Params:
      query....A string representing a search query.
      scorer...A ScoringFunction to retrieve documents.
      index....A Index storing postings lists.
    Returns:
      A list of document ids in descending order of relevance to the query.
    """
    query_tokened = index.tokenize(query)
    query_vector = index.query_to_vector(query_tokened)
    score = scorer.score(query_vector, index)
    sortedlist = sorted(score.items(),
                        key=lambda x: round(x[1], 5),
                        reverse=True)
    return [i[0] - 1 for i in sortedlist]
Beispiel #2
0
def search(query, scorer, index):
    """
    Retrieve documents matching a query using the specified scorer.

    1) Tokenize the query.
    2) Convert the query tokens to a vector, using Index.query_to_vector.
    3) Call the scorer's score function.
    4) Return the list of document ids in descending order of relevance.

    NB: Due to the inconsistency of floating point arithmetic, when sorting,
    round the scores to 6 decimal places (e.g., round(x, 6)). This will ensure
    replicable results.

    Params:
      query....A string representing a search query.
      scorer...A ScoringFunction to retrieve documents.
      index....A Index storing postings lists.
    Returns:
      A list of document ids in descending order of relevance to the query.
    """
    query_tokened = index.tokenize(query)
    query_vector = index.query_to_vector(query_tokened)
    score = scorer.score(query_vector, index)
    sortedlist = sorted(score.items(), key = lambda x: round(x[1],5), reverse=True)
    return [i[0] -1 for i in sortedlist]
Beispiel #3
0
def getLowestScoreFunc(score):
    func = []
    lowest_score = score[len(score)]['score']
    for key, val in score.items():
        if val['score'] == lowest_score:
            func.append(val['func'])
    print(func)
    return func
Beispiel #4
0
def plotting_score(way,score):
    student_score = list()
    for key, value in score.items():
        student_score.append(int(value))

    std = numpy.std(numpy.array(student_score))
    print("The student's standard score is : {}".format(std))
    input("Press any key to leave ...")
Beispiel #5
0
def median_score(way,score):
    student_score = list()
    for key, value in score.items():
        student_score.append(int(value))

    std = numpy.median(numpy.array(student_score))
    print("The student's median score is : {}".format(std))
    input("Press any key to leave ...")