Exemple #1
0
def get_code_snippet():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    java_question_df = DataBaseConnection.select_question_java(
        database_connection, db)
    java_answer_df = DataBaseConnection.select_answer_java(
        database_connection, db)
    java_new_answer = pd.DataFrame(columns=['id', 'code_snippet'])
    java_new_question = pd.DataFrame(columns=['id', 'code_snippet'])

    for chunk in java_question_df:
        for row in chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            snippet = add_class(snippet)
            new_row = {'id': snippet_id, 'code_snippet': snippet}
            java_new_question = java_new_question.append(new_row,
                                                         ignore_index=True)

    for chunk in java_answer_df:
        for row in chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            snippet = add_class(snippet)
            new_row = {'id': snippet_id, 'code_snippet': snippet}
            java_new_answer = java_new_answer.append(new_row,
                                                     ignore_index=True)

    return java_new_answer, java_new_question
def get_code_snippet():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    kotlin_question_df = DataBaseConnection.select_question_kotlin(
        database_connection, db)
    kotlin_answer_df = DataBaseConnection.select_answer_kotlin(
        database_connection, db)
    kotlin_new_answer = pd.DataFrame(columns=['id', 'code_snippet'])
    kotlin_new_question = pd.DataFrame(columns=['id', 'code_snippet'])

    for chunk in kotlin_question_df:
        for row in chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            snippet = add_function(snippet)
            new_row = {'id': snippet_id, 'code_snippet': snippet}
            kotlin_new_question = kotlin_new_question.append(new_row,
                                                             ignore_index=True)
    for chunk in kotlin_answer_df:
        for row in chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            snippet = add_function(snippet)
            new_row = {'id': snippet_id, 'code_snippet': snippet}
            kotlin_new_answer = kotlin_new_answer.append(new_row,
                                                         ignore_index=True)

    return kotlin_new_answer, kotlin_new_question
def main():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    answer_code_select = DataBaseConnection.select_answer_code(database_connection, db)
    for chunk in answer_code_select:
        chunk.set_index('id')

        answer_final_df = delete_code(chunk)
        DataBaseConnection.save_final_answer_code(database_connection, db, answer_final_df)
Exemple #4
0
def main():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    question_code_select = DataBaseConnection.select_question_code(
        database_connection, db)

    for chunk in question_code_select:
        chunk.set_index('id')

        question_final_df = delete_code(chunk)
        DataBaseConnection.save_final_question_code(database_connection, db,
                                                    question_final_df)
def main():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)

    question_df = DataBaseConnection.question_code(database_connection, db)
    for chunk in question_df:

        question_code_df = pd.DataFrame(columns=[
            'id', 'tags', 'code_snippet', 'answer_count', 'comment_count',
            'accepted_answer_id', 'creation_date', 'score', 'view_count',
            'owner_user_id', 'favorite_count', 'post_type_id', 'language'
        ])
        for row in chunk.itertuples():
            id = row[1]
            tags = row[2]
            body = row[3]
            answer_count = row[4]
            comment_count = row[5]
            accepted_answer_id = row[6]
            creation_date = row[7]
            score = row[8]
            view_count = row[9]
            owner_user_id = row[10]
            favorite_count = row[11]
            post_type_id = row[12]

            pattern = r'<code>(.*?)</code>'
            code = re.findall(pattern, body, flags=re.DOTALL)

            for snippet in code:
                new_row = {
                    'id': id,
                    'tags': tags,
                    'code_snippet': snippet,
                    'answer_count': answer_count,
                    'comment_count': comment_count,
                    'accepted_answer_id': accepted_answer_id,
                    'creation_date': creation_date,
                    'score': score,
                    'view_count': view_count,
                    'owner_user_id': owner_user_id,
                    'favorite_count': favorite_count,
                    'post_type_id': post_type_id,
                    'language': ""
                }
                question_code_save = question_code_df.append(new_row,
                                                             ignore_index=True)
                DataBaseConnection.save_question_code(database_connection, db,
                                                      question_code_save)
Exemple #6
0
def main():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)

    answer_df = DataBaseConnection.answer_code(database_connection, db)
    for chunk in answer_df:

        answer_code_df = pd.DataFrame(columns=['id', 'code_snippet', 'owner_user_id', 'parent_id', 'post_type_id', 'score', 'language'])
        for row in chunk.itertuples():
            id = row[1]
            body = row[2]
            creation_date = row[3]
            owner_user_id = row[4]
            parent_id = row[5]
            post_type_id = row[6]
            score = row[7]

            pattern = r'<code>(.*?)</code>'
            code = re.findall(pattern, body, flags=re.DOTALL)

            for snippet in code:
                new_row = {'id': id, 'code_snippet': snippet,  'creation_date': creation_date, 'owner_user_id': owner_user_id, 'parent_id': parent_id, 'post_type_id':post_type_id, 'score': score, 'language': ""}
                answer_code_save = answer_code_df.append(new_row, ignore_index=True)
                DataBaseConnection.save_answer_code(database_connection, db, answer_code_save)
Exemple #7
0
def connect_db():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    return database_connection, db