Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
0
def save_code_df(java_new_answer, java_new_question):
    database_connection, db = connect_db()
    DataBaseConnection.save_java_answer_update(database_connection, db,
                                               java_new_answer)
    DataBaseConnection.save_java_question_update(database_connection, db,
                                                 java_new_question)
Exemplo n.º 8
0
def connect_db():
    database_connection = DataBaseConnection()
    db = DataBaseConnection.connect_database(database_connection)
    return database_connection, db
Exemplo n.º 9
0
def get_snippet_answer():
    java_answers = pd.DataFrame(columns=[
        'id', 'code_snippet', 'valid_file', 'upperel', 'typename',
        'summaryjavadoc', 'operatorwrap', 'fallthrough', 'nofinalizer',
        'javadocsingle', 'variablename', 'methodname', 'modifierorder',
        'multiplevariable', 'braces', 'parenpad', 'methodparenpad',
        'nolinewrap', 'overloadmethod', 'javadocparagraph',
        'javadocindentation', 'javadocmethod', 'abbreviation', 'leftcurly',
        'rightcurly', 'whitespace', 'emptyline', 'emptyblock', 'separatorwrap',
        'indentation', 'commentindentation', 'annotation', 'toplevel',
        'arraytype', 'invalidposition', 'membername', 'filetabcharacter',
        'switchdefault', 'importerror', 'parametername'
    ])
    connection, db = get_connection()
    answer_df = DataBaseConnection.select_java_answer_update(connection, db)
    for java_chunk in answer_df:
        for row in java_chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            temp_file(snippet, "Answer_Class.java")
            exception_count, upper_l_count, type_name_count, summary_javadoc_count, operator_wrap_count, fall_through_count, no_finalizer_count, javadoc_single_count, variable_name_count, method_name_count, modifier_order_count, multiple_variable_count, braces_count, paren_pad_count, method_paren_pad_count, no_line_wrap_count, overload_method_count, javadoc_paragraph_count, javadoc_indentation_count, javadoc_method_count, abbreviation_count, left_curly_count, right_curly_count, right_curly2_count, whitespace_count, empty_line_count, empty_block_count, separator_wrap_count, indentation_count, comment_indentation_count, annotation_count, top_level_count, array_type_count, invalid_position_count, member_name_count, file_tab_character_count, switch_default_count, import_error_count, parameter_name_count = checkstyle_cmd(
            )
            if exception_count != 0:
                java_file = False
            else:
                java_file = True
            new_row = {
                'id': snippet_id,
                'code_snippet': snippet,
                'valid_file': java_file,
                'upperel': upper_l_count,
                'typename': type_name_count,
                'summaryjavadoc': summary_javadoc_count,
                'operatorwrap': operator_wrap_count,
                'fallthrough': fall_through_count,
                'nofinalizer': no_finalizer_count,
                'javadocsingle': javadoc_single_count,
                'variablename': variable_name_count,
                'methodname': method_name_count,
                'modifierorder': modifier_order_count,
                'multiplevariable': multiple_variable_count,
                'braces': braces_count,
                'parenpad': paren_pad_count,
                'methodparenpad': method_paren_pad_count,
                'nolinewrap': no_line_wrap_count,
                'overloadmethod': overload_method_count,
                'javadocparagraph': javadoc_paragraph_count,
                'javadocindentation': javadoc_indentation_count,
                'javadocmethod': javadoc_method_count,
                'abbreviation': abbreviation_count,
                'leftcurly': left_curly_count,
                'rightcurly': right_curly_count + right_curly2_count,
                'whitespace': whitespace_count,
                'emptyline': empty_line_count,
                'emptyblock': empty_block_count,
                'separatorwrap': separator_wrap_count,
                'indentation': indentation_count,
                'commentindentation': comment_indentation_count,
                'annotation': annotation_count,
                'toplevel': top_level_count,
                'arraytype': array_type_count,
                'invalidposition': invalid_position_count,
                'membername': member_name_count,
                'filetabcharacter': file_tab_character_count,
                'switchdefault': switch_default_count,
                'importerror': import_error_count,
                'parametername': parameter_name_count
            }
            java_answers = java_answers.append(new_row, ignore_index=True)
    save_answer(java_answers)
Exemplo n.º 10
0
def save_question(question_df):
    connection, db = get_connection()
    DataBaseConnection.save_checkstyle_questions(connection, db, question_df)
Exemplo n.º 11
0
def save_answer(answer_df):
    connection, db = get_connection()
    DataBaseConnection.save_checkstyle_answers(connection, db, answer_df)
Exemplo n.º 12
0
def get_snippet():
    kotlin_answers = pd.DataFrame(columns=[
        'id', 'code_snippet', 'valid_file', 'indention_error',
        'semicolon_error', 'wildcard_error', 'blank_line_error',
        'whitespace_error', 'return_error', 'redundant_error', 'break_error'
    ])
    kotlin_questions = pd.DataFrame(columns=[
        'id', 'code_snippet', 'valid_file', 'indention_error',
        'semicolon_error', 'wildcard_error', 'blank_line_error',
        'whitespace_error', 'return_error', 'redundant_error', 'break_error'
    ])

    connection, db = get_connection()
    answer_df = DataBaseConnection.select_kotlin_answer_update(connection, db)
    question_df = DataBaseConnection.select_kotlin_question_update(
        connection, db)
    for kotlin_chunk in answer_df:
        for row in kotlin_chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            temp_file(snippet)
            indentation_error_count, semicolon_error_count, wildcard_error_count, blank_lines_error_count, whitespace_error_count, return_error_count, redundant_error_count, break_error_count, kotlin_file_error_count = ktlint_cmd(
            )
            if kotlin_file_error_count != 0:
                kotlin_file = False
            else:
                kotlin_file = True
            new_row = {
                'id': snippet_id,
                'code_snippet': snippet,
                'valid_file': kotlin_file,
                'indention_error': indentation_error_count,
                'semicolon_error': semicolon_error_count,
                'wildcard_error': wildcard_error_count,
                'blank_line_error': blank_lines_error_count,
                'whitespace_error': whitespace_error_count,
                'return_error': return_error_count,
                'redundant_error': redundant_error_count,
                'break_error': break_error_count
            }
            kotlin_answers = kotlin_answers.append(new_row, ignore_index=True)

    for kotlin_chunk in question_df:
        for row in kotlin_chunk.itertuples():
            snippet_id = row[1]
            snippet = row[2]
            temp_file(snippet)
            indentation_error_count, semicolon_error_count, wildcard_error_count, blank_lines_error_count, whitespace_error_count, return_error_count, redundant_error_count, break_error_count, kotlin_file_error_count = ktlint_cmd(
            )
            if kotlin_file_error_count != 0:
                kotlin_file = False
            else:
                kotlin_file = True
            new_row = {
                'id': snippet_id,
                'code_snippet': snippet,
                'valid_file': kotlin_file,
                'indention_error': indentation_error_count,
                'semicolon_error': semicolon_error_count,
                'wildcard_error': wildcard_error_count,
                'blank_line_error': blank_lines_error_count,
                'whitespace_error': whitespace_error_count,
                'return_error': return_error_count,
                'redundant_error': redundant_error_count,
                'break_error': break_error_count
            }
            kotlin_questions = kotlin_questions.append(new_row,
                                                       ignore_index=True)
    return kotlin_answers, kotlin_questions
Exemplo n.º 13
0
def save_df(answer_df, question_df):
    connection, db = get_connection()
    DataBaseConnection.save_ktlint_answers(connection, db, answer_df)
    DataBaseConnection.save_ktlint_questions(connection, db, question_df)