Пример #1
0
def give_recommendations(user_id):
    user_id = util.lookup_user_id(user_id)

    user_classifier_path = '../cache/{}/classifier.pkl'.format(user_id)
    with open(user_classifier_path) as stream:
        classifier = pickle.load(stream)

    user_tags = util.lookup_user_tags(user_id)

    client = StackExchangeClient(site='stackoverflow',
                                 client_id=config.STACK_EXCHANGE_KEY,
                                 key=config.STACK_EXCHANGE_KEY)
    candidate_questions = []
    for tag in user_tags:
        candidate_questions.extend(
            client.questions.get(order='desc',
                                 sort='creation',
                                 tagged=tag,
                                 filter='!-MBjrdFL(r((hP1ak*y9uHYU*hy7OjR4M'))

    candidate_questions = sorted(candidate_questions,
                                 key=lambda x: x['question_id'])
    unique_candidates = []
    for index, elt in enumerate(candidate_questions):
        if index > 0 and elt['question_id'] != candidate_questions[
                index - 1]['question_id']:
            if elt['score'] >= 0 and 'accepted_answer_id' not in elt:
                unique_candidates.append(elt)

    recommendations = classifier.get_recommendations(unique_candidates, 500)
    return jsonify({'result': recommendations})
Пример #2
0
            'question': q,
            'answer_accepted': False
        } for q in bad_questions])
        user_question_lists[user_id] = labeled_questions

    return user_question_lists


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--client_id',
                        help='Stack Overflow client_id',
                        required=True)
    parser.add_argument('-k',
                        '--key',
                        help='Stack Overflow key',
                        required=True)
    parser.add_argument('-f',
                        '--file',
                        help='JSON file destination',
                        default=None)
    args = parser.parse_args()

    client = StackExchangeClient('stackoverflow', args.client_id, args.key)
    dataset = fetch_dataset(client)

    if args.file is not None:
        with open(args.file, 'w') as stream:
            json.dump(dataset, stream)
Пример #3
0
 def from_credentials(cls, client_id, key):
     client = StackExchangeClient(site='stackoverflow',
                                  client_id=client_id,
                                  key=key)
     return cls(client)
Пример #4
0
import pymongo
import time

from website import config
from database_population import settings
from database_population.methods import tagged_questions
from database_population.log import logger
from stack_exchange.stack_exchange_client import StackExchangeClient

USER_FILTER = '!bWWJdia*x26uv)'

if __name__ == '__main__':
    mongo_client = pymongo.MongoClient(settings.DATABASE_URL)
    stack_overflow_client = StackExchangeClient(
        site='stackoverflow',
        client_id=settings.STACK_EXCHANGE_CLIENT_ID,
        key=settings.STACK_EXCHANGE_KEY)

    extant_tags = set(mongo_client.tagged_questions.collection_names())
    all_tags = set(sum(config.user_id_to_tags.values(), []))
    top_100_tags = list(all_tags - extant_tags)

    logger.info('Getting questions for the tags {}'.format(top_100_tags))

    for tag in top_100_tags:
        start_time = time.time()

        tagged_questions.populate_database(
            stack_overflow_client=stack_overflow_client,
            database_client=mongo_client,
            tag=tag,