Пример #1
0
def synthesize(client, featureSet='release', latestTrainingSetOut='data/latest-training.txt', classicTrainingSetOut='data/classic-training.txt'):
    from ltr.judgments import judgments_to_file, Judgment
    print('Generating ratings for classic and latest model')
    NO_ZERO = False

    resp = client.log_query('tmdb', 'release', None)

    # Classic film fan
    judgments = []
    print("Generating Classic judgments:")
    for hit in resp:
        rating = get_classic_rating(hit['ltr_features'][0])

        if rating == 0 and NO_ZERO:
            continue

        judgments.append(Judgment(qid=1,docId=hit['id'],grade=rating,features=hit['ltr_features'],keywords=''))

    with open(classicTrainingSetOut, 'w') as out:
        judgments_to_file(out, judgments)

    # Latest film fan
    judgments = []
    print("Generating Recent judgments:")
    for hit in resp:
        rating = get_latest_rating(hit['ltr_features'][0])

        if rating == 0 and NO_ZERO:
            continue

        judgments.append(Judgment(qid=1,docId=hit['id'],grade=rating,features=hit['ltr_features'],keywords=''))


    with open(latestTrainingSetOut, 'w') as out:
        judgments_to_file(out, judgments)
Пример #2
0
def synthesize(client,
               featureSet='release',
               latestTrainingSetOut='data/latest-training.txt',
               classicTrainingSetOut='data/classic-training.txt'):
    from ltr.judgments import judgments_to_file, Judgment
    print('Generating ratings for classic and latest model')
    NO_ZERO = False

    resp = client.log_query('tmdb', 'release', None)

    docs = []
    for hit in resp:
        # Expect clients to return features per doc in ltr_features as ordered list
        feature = hit['ltr_features'][0]

        docs.append([feature])  # Treat features as ordered lists

    # Classic film fan
    judgments = []
    for fv in docs:
        rating = get_classic_rating(fv[0])

        if rating == 0 and NO_ZERO:
            continue

        judgments.append(
            Judgment(qid=1,
                     docId=rating,
                     grade=rating,
                     features=fv,
                     keywords=''))

    with open(classicTrainingSetOut, 'w') as out:
        judgments_to_file(out, judgments)

    judgments = []
    for fv in docs:
        rating = get_latest_rating(fv[0])

        if rating == 0 and NO_ZERO:
            continue

        judgments.append(
            Judgment(qid=1,
                     docId=rating,
                     grade=rating,
                     features=fv,
                     keywords=''))

    with open(latestTrainingSetOut, 'w') as out:
        judgments_to_file(out, judgments)

    print('Done')
Пример #3
0
def rate_results():
    from sys import argv

    esUrl = 'http://localhost:9200/tmdb/'

    judgFile = argv[1]
    full_judgments, existing_kws, last_qid = load_judgments(judgFile)

    keywords = "-"
    new_qid = last_qid + 1
    while len(keywords) > 0:
        input_kws = input("Enter the Keywords ('GTFO' to exit) ")

        if input_kws == "GTFO":
            break

        keywords, search_with, orig_query_judgments, existing_qid, fuzzy, copy_src_kws =\
                handleKeywords(input_kws, existing_kws, full_judgments)
        curr_qid = 0
        if existing_qid > 0:
            curr_qid = existing_qid
            print("Updating judgments for qid:%s" % curr_qid)
        else:
            existing_kws.add(keywords)
            curr_qid = new_qid
            print("New Keywords %s qid:%s" % (keywords, curr_qid))
            new_qid += 1

        new_query_judgments = []
        if copy_src_kws is not None:
            print("Copying from %s <- %s" % (keywords, copy_src_kws))
            for judg in orig_query_judgments:
                judgment = Judgment(int(judg.grade),
                                    qid=new_qid,
                                    keywords=keywords,
                                    docId=judg.docId)
                new_query_judgments.append(judgment)
            existing_kws.add(keywords)
            curr_qid = new_qid
            new_qid += 1
        else:
            results = get_potential_results(esUrl, search_with, fuzzy)
            new_query_judgments = grade_results(results, keywords, curr_qid)

        foldInNewRatings(full_judgments, orig_query_judgments,
                         new_query_judgments)

    with open(judgFile, 'w') as f:
        judgments_to_file(f, full_judgments)
Пример #4
0
    judgFile = argv[1]
    fullJudgments, existingKws, lastQid = loadJudgments(judgFile)

    keywords = "-"
    newQid = lastQid + 1
    while len(keywords) > 0:
        inputKws = input("Enter the Keywords ('GTFO' to exit) ")

        if inputKws == "GTFO":
            break

        keywords, searchWith, origQueryJudgments, existingQid, fuzzy = handleKeywords(
            inputKws, fullJudgments)
        currQid = 0
        if existingQid > 0:
            currQid = existingQid
            print("Updating judgments for qid:%s" % currQid)
        else:
            existingKws.add(keywords)
            currQid = newQid
            print("New Keywords %s qid:%s" % (keywords, currQid))
            newQid += 1

        results = getPotentialResults(esUrl, searchWith, fuzzy)
        newQueryJudgments = gradeResults(results, keywords, currQid)

        foldInNewRatings(fullJudgments, origQueryJudgments, newQueryJudgments)

    judgments_to_file(judgFile, fullJudgments)