<jupyter_start><jupyter_text>Find bug seeding patterns---We want to find seeding patterns that may be used by SemSeed. This is supposedto create a table comparing *Mutandis*.<jupyter_code>import pandas as pd
import json
import os
from pathlib import Path
import codecs
import json
from typing import List, Dict, Any
import pandas as pd
from multiprocessing import Pool, cpu_count
from tqdm.notebook import trange, tqdm
benchmarks_dir = '../benchmarks'

# SemSeed
seeded_bugs_file_path  = os.path.join(benchmarks_dir, 'js_benchmark_seeded_bugs_efficiency_test.pkl')
seeded_bugs_files_dir  = os.path.join(benchmarks_dir, 'js_benchmark_seeded_bugs_efficiency_test')
def read_json_file(json_file_path)->Dict:
    try:
        obj_text = codecs.open(json_file_path, 'r', encoding='utf-8').read()
        r = json.loads(obj_text)
        return r
    except FileNotFoundError:
        print(
            "Please provide a correct file p. Eg. ./results/validated-conflicts.json")
        return {}
    except Exception as e:
        # Empty JSON file most likely due to abrupt killing of the process while writing
        # print (e)
        return {}

def read_dataset_given_files(extracted_data_files: List) -> pd.DataFrame:
    d = []
    with Pool(cpu_count()) as p:
        with tqdm(total=len(extracted_data_files)) as pbar:
            pbar.set_description_str(
                desc="Reading dataset from files", refresh=False)
            for i, each_vars in enumerate(
                    p.imap_unordered(read_json_file, extracted_data_files, 20)):
                pbar.update()
                d.append(each_vars)
            p.close()
            p.join()
    # print(d)
    extracted_dataset = pd.DataFrame(d)
    return extracted_dataset

def file_path_to_dataset(dataset_file_path, dir_path):
    if not Path(dataset_file_path).is_file():
        file_paths = list(Path(dir_path).rglob('*.json'))
        print(f"Number of files={len(file_paths)}")
        dataset = read_dataset_given_files(extracted_data_files=file_paths)
        print(f"Saving {dataset_file_path}")
        dataset.to_pickle(dataset_file_path,'gzip')
    else:
        print(f'Reading from {dataset_file_path}')
        dataset = pd.read_pickle(dataset_file_path,'gzip')
    print(f"Dataset contains {len(dataset)} examples")
    return dataset
seeded_bugs = file_path_to_dataset(dataset_file_path=seeded_bugs_file_path, dir_path=seeded_bugs_files_dir)<jupyter_output>Reading from ../../../benchmarks/js_benchmark_seeded_bugs_efficiency_test.pkl
Dataset contains 677217 examples<jupyter_text>Syntax errors in seeded bugsThe above bugs have been seeded on a random sample of 1000 files.<jupyter_code>print(f'Seeded {len(seeded_bugs)} bugs on random sample of 1000 files')
syntax_check = read_json_file(os.path.join(benchmarks_dir,'file_and_syntax_correct.json'))
inc = 0
for f,v in syntax_check.items():
    if not v:
        inc+=1
print(f'{inc} or {inc/len(seeded_bugs)*100}% Syntactically incorrect')
def get_only_idf_lit_containing_patterns(all_changes):
    """
    It is possible that every bug-fix pattern can not be used to seed bugs.
    We filter some of them here. For example:
        * we may filter very long change patterns (although we do it once while aggregating data from MongoDB)
        * we may select only those chage patterns that has atleast 'N' frequency
    """
    filtered_change_patterns = []

    # # ----------------------- Filtering number of tokens -------------------------
    # max_number_of_tokens = 10
    # for change_pattern in self.all_training_change_patterns:
    #     print('\n\n \t *** ***  Selecting only change patterns having total {} tokens *** ***'.format(max_number_of_tokens*2))
    #     if len(change_pattern['fix']) <= max_number_of_tokens and len(change_pattern['buggy']) <= max_number_of_tokens:
    #         filtered_change_patterns.append(change_pattern)

    # ----------------------- Filtering based on the frequency of the change patterns -----------------
    # min_frequency = 4
    # print('\n \t *** ***  Filtering only change patterns having minimum frequency  {} *** ***\n'.format(min_frequency))
    # mapping_of_change_patterns = SeedBugs._str_mapping_change_pattern_to_change(
    #     all_changes)

    # for mapped_seq in mapping_of_change_patterns:
    #     if len(mapping_of_change_patterns[mapped_seq]) >= min_frequency:
    #         filtered_change_patterns.extend(
    #             mapping_of_change_patterns[mapped_seq])

    # print("\tTotal {} change patterns and {} filtered change patterns ".format(
    #     len(mapping_of_change_patterns), len(filtered_change_patterns)))

    # ------------------- Remove those change patterns that does not contain any Identifiers/Literals ------------
    for t in all_changes:
        # If the change pattern contains at-least one Identifier/Literal, we use that.
        # Else the change pattern is discarded
        if 'Idf_' in ' '.join(t['fix']) or 'Idf_' in ' '.join(t['buggy']) or 'Lit_' in ' '.join(
                t['fix']) or 'Lit_' in ' '.join(t['buggy']):
            filtered_change_patterns.append(t)

    return filtered_change_patterns
with open(os.path.join(benchmarks_dir, 'training_changes.json'),'r') as f:
    patterns = json.load(f)
patterns = get_only_idf_lit_containing_patterns(patterns)
patterns  = pd.DataFrame(patterns)
print(f'Found {len(patterns)} patterns')
def select_only_single_token_changes(all_change_patterns):
    only_single_operator_change = []
    only_single_idf_change = []
    only_single_lit_change = []

    for _,r in patterns.iterrows():
        pattern = r.to_dict()
        # Operator ------------------
        f = []
        b = []
        for t in pattern['fix']:
            if 'Lit_' not in t and 'Idf_' not in t:
                f.append(t)
        for t in pattern['buggy']:
            if 'Lit_' not in t and 'Idf_' not in t:
                b.append(t)
        
        di_f_b_op = len(set(f)-set(b)) == 1
        di_b_f_op = len(set(b)-set(f)) == 1
        

        # Identifier and Literal ------------
        f_idf = []
        b_idf = []
        for t in pattern['fix']:
            if 'Idf_' in t:
                f_idf.append(t)
        for t in pattern['buggy']:
            if 'Idf_' in t:
                b_idf.append(t)
        
        di_f_b_idf = len(set(f_idf)-set(b_idf)) == 1
        di_b_f_idf = len(set(b_idf)-set(f_idf)) == 1
        
        
        
        f_lit = []
        b_lit = []
        for t in pattern['fix']:
            if 'Lit_' in t:
                f_lit.append(t)
        for t in pattern['buggy']:
            if 'Lit_' in t:
                b_lit.append(t)
        
        di_f_b_lit = len(set(f_lit)-set(b_lit)) == 1
        di_b_f_lit = len(set(b_lit)-set(f_lit)) == 1
        
        if di_f_b_op and di_b_f_op and di_f_b_idf==0==di_b_f_idf and di_f_b_lit==0== di_b_f_lit:
            only_single_operator_change.append(pattern)

        if di_f_b_idf and di_b_f_idf and di_f_b_op == 0 == di_b_f_op and di_f_b_lit==0== di_b_f_lit:
            only_single_idf_change.append(pattern)

        if di_f_b_lit and di_b_f_lit and di_f_b_op == 0 == di_b_f_op and di_f_b_idf==0==di_b_f_idf:
            only_single_lit_change.append(pattern)
    return pd.DataFrame(only_single_operator_change), pd.DataFrame(only_single_idf_change), pd.DataFrame(only_single_lit_change)

single_operator_patterns, single_idf_patterns, single_lit_patterns = select_only_single_token_changes(patterns)

single_operator_patterns
single_idf_patterns
single_lit_patterns
patterns<jupyter_output><empty_output><jupyter_text>Generic mutation operators for branch conditionsThere are three sets of mutation operators. Set one is for *loop statement*, set two for *conditional statement* andthe final set is for *return statement*. Many mutation operators for set one and two overlap. For SemSeed itdoes not matter if the mutation is made to a binary operator in a loop or a conditional. Hence we do not separatethis. The following are the SemSeed counterparts of all mutation operators. 1. Change literal value in the condition<jupyter_code># Collect the patterns that is also seeded by mutandis
list_of_all_patterns_also_seded_by_mutandis = set()

selected_patterns = []
for _,r in single_lit_patterns.iterrows():
    pattern = r.to_dict()
    if pattern['buggy_tokenType'] == 'BinaryExpression' == pattern['fix_tokenType']:
        selected_patterns.append(pattern)
        list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 17<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[6,4])
print(selected_patterns.iloc[9,4])<jupyter_output>https://github.com/meteor/meteor/commit/339706882b22e9f9caa667638ac93d9aa343285d
https://github.com/webpack/webpack/commit/59656c9717c4d1b78232563d8fbe077067dd4c20<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[6,4]]
p<jupyter_output><empty_output><jupyter_text>2. Replace relational operators<jupyter_code>relational_operators = {'<', '>', '<=', '>=', '==', '!=', '===', '!=='}
selected_patterns = []
for _,r in single_operator_patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    if pattern['buggy_tokenType'] == 'BinaryExpression' == pattern['fix_tokenType']:
        for t in pattern['fix']:
            if 'Lit_' not in t and 'Idf_' not in t:
                f.append(t)
        for t in pattern['buggy']:
            if 'Lit_' not in t and 'Idf_' not in t:
                b.append(t)
        
        if len(f) == 1 == len(b) and f != b and relational_operators.intersection(set(f)) and relational_operators.intersection(set(b)):
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 11<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[4,4])
print(selected_patterns.iloc[5,4])<jupyter_output>https://github.com/discourse/discourse/commit/1dd6699bf22d9a3f387fee36a1b46671c284d9ce
https://github.com/adobe/brackets/commit/30d50a59efd095b3788bad4d19c5c827c115fe67<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sample(5)
p<jupyter_output><empty_output><jupyter_text>3. Replace logical operators<jupyter_code>logical_operators = {'&&', '||'}
selected_patterns = []
for _,r in single_operator_patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    if pattern['buggy_tokenType'] == 'LogicalExpression' == pattern['fix_tokenType']:
        for t in pattern['fix']:
            if 'Lit_' not in t and 'Idf_' not in t:
                f.append(t)
        for t in pattern['buggy']:
            if 'Lit_' not in t and 'Idf_' not in t:
                b.append(t)
        f_lops = logical_operators.intersection(set(f))
        b_lops = logical_operators.intersection(set(b))

        if  f != b and f_lops and b_lops and f_lops != b_lops :
            selected_patterns.append(pattern)
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 4<jupyter_text>Selected the following Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[2,4]]
p<jupyter_output><empty_output><jupyter_text>4. Swap consecutive nested for/whileWe can't have this pattern since we look for single line changes  5. Replace arithmetic operators<jupyter_code>arithmetic_operators = {'+' '-' '/' '*' '%' '**', '+=', '-='}
selected_patterns = []
for _,r in single_operator_patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    # if pattern['buggy_tokenType'] == 'LogicalExpression' == pattern['fix_tokenType']:
    for t in pattern['fix']:
        if 'Lit_' not in t and 'Idf_' not in t:
            f.append(t)
    for t in pattern['buggy']:
        if 'Lit_' not in t and 'Idf_' not in t:
            b.append(t)
    f_lops = arithmetic_operators.intersection(set(f))
    b_lops = arithmetic_operators.intersection(set(b))

    if  f != b and f_lops and b_lops and f_lops != b_lops :
        list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 1<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[0, 4])<jupyter_output>https://github.com/mozilla/pdf.js/commit/4acb744f77a3828efdd26d08f6ffd9517302b3a8
https://github.com/photonstorm/phaser/commit/b48c2a8173b357b391aa4c16ccbfa3346dd9038f<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]]
p<jupyter_output><empty_output><jupyter_text>6. Replace x++/x-- with ++x/--x**Note:** Could not find an instance where this happens<jupyter_code>UpdateOperator = {'++', '--'}
selected_patterns = []
for _,r in single_operator_patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    # if pattern['buggy_tokenType'] == 'LogicalExpression' == pattern['fix_tokenType']:
    for t in pattern['fix']:
        if 'Lit_' not in t and 'Idf_' not in t:
            f.append(t)
    for t in pattern['buggy']:
        if 'Lit_' not in t and 'Idf_' not in t:
            b.append(t)
    f_lops = UpdateOperator.intersection(set(f))
    b_lops = UpdateOperator.intersection(set(b))

    if  f != b and f_lops and b_lops and f_lops != b_lops :
        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
if len(selected_patterns):
    selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 0<jupyter_text>7. Remove 'break'/'continue'**Note:** Could not find removing the statements. We could only find instances where either of thesestatements has been replaced with another.<jupyter_code>selected_patterns = []
toks = ['break', 'continue']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    for t in pattern['fix']:
        if 'Lit_' not in t and 'Idf_' not in t:
            f.append(t)
    for t in pattern['buggy']:
        if 'Lit_' not in t and 'Idf_' not in t:
            b.append(t)
    for op in toks:

        if op in f and op not in b:
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                selected_patterns.append(pattern)
        if op not in f and op in b:
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 1<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[0,4])
# print(selected_patterns.iloc[1,4])<jupyter_output>https://github.com/webpack/webpack/commit/114abeeb4d1023b3da8f5ac22686c83ff78356a7<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]]
p<jupyter_output><empty_output><jupyter_text>8. Replace 0/1 with false/true and vice-versa in the condition<jupyter_code>selected_patterns = []
toks = ['0', '1']
rep_toks = ['false', 'true']
seen_url = set()
for _,r in single_lit_patterns.iterrows():
    pattern = r.to_dict()
    for idx, tk in enumerate(toks):
        if tk in pattern['fix_actual'] and rep_toks[idx] in pattern['buggy_actual']:
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                selected_patterns.append(pattern)
        if rep_toks[idx] in pattern['fix_actual'] and tk in pattern['buggy_actual']:
                    if pattern['url'] not in seen_url:
                        seen_url.add(pattern['url'])
                        list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 4<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]]
p<jupyter_output><empty_output><jupyter_text>9. Remove returnNot possible in our pattern<jupyter_code>selected_patterns = []
tk = 'return'
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    copy_patter = list(pattern['fix_actual'])
    if tk in pattern['fix_actual'] and tk not in pattern['buggy_actual']:
        copy_patter.remove(tk)
        if pattern['buggy_actual'] == copy_patter:
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]
print(selected_patterns.iloc[0,4])
print(selected_patterns.iloc[5,4])<jupyter_output>https://github.com/jquery/jquery/commit/a8bafe78745247dd13e3472582df29471e50aa28
https://github.com/sequelize/sequelize/commit/95d5ebac6eb0ebda411218c47e6db33cd210f005<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[4,4]]
p<jupyter_output><empty_output><jupyter_text>10. Replace return true with return false and vice versa<jupyter_code>selected_patterns = []
toks = ['returntrue', 'returnfalse']
rep_toks = ['returnfalse', 'returntrue']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    for idx, tk in enumerate(toks):
        if tk in ''.join(pattern['fix_actual']) and rep_toks[idx] in ''.join(pattern['buggy_actual']):
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                selected_patterns.append(pattern)
        if rep_toks[idx] in ''.join(pattern['fix_actual']) and tk in ''.join(pattern['buggy_actual']):
                    if pattern['url'] not in seen_url:
                        seen_url.add(pattern['url'])
                        list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 4<jupyter_text>selected the following<jupyter_code>print(selected_patterns.iloc[0, 4])
print(selected_patterns.iloc[1, 4])<jupyter_output>https://github.com/emberjs/ember.js/commit/7aaf128c0098d020ccf67e16642dccddb937bdef
https://github.com/lodash/lodash/commit/a2a71a107e2aa5cfb7ab9cfa8c10b41885334160<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sample(5)
p<jupyter_output><empty_output><jupyter_text>JavaScript-Specific Mutation Operators 1. Adding/Removing the var keyword<jupyter_code>selected_patterns = []
toks = ['var']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    for t in pattern['fix']:
        if 'Lit_' not in t and 'Idf_' not in t:
            f.append(t)
    for t in pattern['buggy']:
        if 'Lit_' not in t and 'Idf_' not in t:
            b.append(t)
    for op in toks:
        di_f_b = len(set(f)-set(b)) == 1
        di_b_f = len(set(b)-set(f)) == 1

        if op in f and op not in b:
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                if 'const' not in pattern['buggy_actual']:
                    list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                    selected_patterns.append(pattern)
        if op not in f and op in b:
            if pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                if 'let' not in pattern['fix_actual']:
                    list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                    selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 24<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[13,4])
print(selected_patterns.iloc[28,4])<jupyter_output>https://github.com/Reactive-Extensions/RxJS/commit/d3e10f70cca7c7a32d765cc91877f503a10b47ca
https://github.com/alvarotrigo/fullPage.js/commit/bd1bc752c4520508f6be646b6889b0c34a30d17f<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[19,4]].sample(5).sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>2. Remove global search flag from replace**Not found**<jupyter_code>selected_patterns = []
toks = ['replace']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    for idx,t in enumerate(pattern['fix']):
        if 'Idf_' in t:
            f.append(pattern['fix_actual'][idx])
    for idx,t in enumerate(pattern['buggy']):
        if 'Idf_' in t:
            b.append(pattern['buggy_actual'][idx])
    for op in toks:
        if op in f and op in b:
            f_idx = pattern['fix_actual'].index(op)
            b_idx = pattern['buggy_actual'].index(op)
            f_regex = pattern['fix_actual'][f_idx+2:f_idx+3]
            b_regex = pattern['buggy_actual'][f_idx+2:f_idx+3]
            # print(b_regex)
            # print(f_regex)
            cr = (b_regex[0][-1]=='g' and f_regex[0][-1]!='g') or (b_regex[0][-1]!='g' and f_regex[0][-1]=='g')
            if cr and pattern['url'] not in seen_url:
                seen_url.add(pattern['url'])
                selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 7<jupyter_text>Selected the following<jupyter_code>print(selected_patterns.iloc[1,4])
print(selected_patterns.iloc[5,4])<jupyter_output>https://github.com/select2/select2/commit/b422d4efef486e8ac724220229e0c6d42b7f28ad
https://github.com/emberjs/ember.js/commit/2e99d1ff3b8a28f966b52c12cb5109b377216c10<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[5,4]].sort_values(by='mean_similarity')
p
p.iloc[1,0]<jupyter_output><empty_output><jupyter_text>3. Removing the integer base argument from parseInt**Note:** Although many patterns exist that contain *parseInt* there does not existanything that captures exactly what mutandis does<jupyter_code>selected_patterns = []
toks = ['parseInt']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    for idx,t in enumerate(pattern['fix']):
        if 'Idf_' in t:
            f.append(pattern['fix_actual'][idx])
    for idx,t in enumerate(pattern['buggy']):
        if 'Idf_' in t:
            b.append(pattern['buggy_actual'][idx])
    for op in toks:
        if op in f and op in b:
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]
p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[1,4]].sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>4. Changing setTimeout function**Note:** The exact pattern as expected by mutandis does not exist<jupyter_code>selected_patterns = []
toks = ['setTimeout','setInterval']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    for idx,t in enumerate(pattern['fix']):
        if 'Idf_' in t:
            f.append(pattern['fix_actual'][idx])
    for idx,t in enumerate(pattern['buggy']):
        if 'Idf_' in t:
            b.append(pattern['buggy_actual'][idx])
    for op in toks:
        if op in f and op in b:
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 5<jupyter_text>5. Replacing 'undefined' with 'null'**None found**<jupyter_code>selected_patterns = []
toks = ['undefined']
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    f = []
    b = []
    if len(pattern['fix']) != len(pattern['buggy']):
        continue
    for idx,t in enumerate(pattern['fix']):
        if 'Idf_' in t:
            f.append(pattern['fix_actual'][idx])
    for idx,t in enumerate(pattern['buggy']):
        if 'Idf_' in t:
            b.append(pattern['buggy_actual'][idx])
    for op in toks:
        if op in f  and 'null' in pattern['buggy_actual']:
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]
print(selected_patterns.iloc[0,8])
print(selected_patterns.iloc[0,14])<jupyter_output>['s', '.', 'dataType', '===', '"script"', '&&', 's', '.', 'cache', '===', 'undefined']
['s', '.', 'dataType', '===', '"script"', '&&', 's', '.', 'cache', '===', 'null']<jupyter_text>Selected the following Selected the following<jupyter_code>print(selected_patterns.iloc[5,4])<jupyter_output>https://github.com/lerna/lerna/commit/2fa02a835c2c898dce5e8aa1d27d3eed3854c529<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>6. Removing 'this' keyword<jupyter_code>selected_patterns = []
tok = 'this'
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if tok in pattern['fix_actual'] and tok not in pattern['buggy_actual'] and len(pattern['buggy_actual'])+1==len(pattern['fix_actual']):
        selected_patterns.append(pattern)
        list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 2<jupyter_text>Selected the following<jupyter_code>selected_patterns.iloc[0]<jupyter_output><empty_output><jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sample(5).sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>7. Replacing (function()!==false) by (function())**Note:** Could not find any instance<jupyter_code>selected_patterns = []
tok = ')!==false'
rep_tok = ')'
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if tok in ''.join(pattern['fix_actual']) and rep_tok in ''.join(pattern['buggy_actual']):
        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 1<jupyter_text>Variable mutationThe following are few mutation operators that do not overlap with the branch mutationoperators Change the value assigned to the variable<jupyter_code>selected_patterns = []
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if ['var', 'Idf_1', '=']==pattern['fix'][0:3] == pattern['buggy'][0:3]:
        if pattern['fix'][3] !=  pattern['buggy'][3]:
            selected_patterns.append(pattern)
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]
selected_patterns.sample(3)<jupyter_output><empty_output><jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[57,4]].sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>Remove variable declaration<jupyter_code>selected_patterns = []
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if ['var', 'Idf_1', '=']==pattern['fix'][0:3] and pattern['buggy'][0:2] == ['Idf_1', '=']:
            list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
            selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 15<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>Change variable type<jupyter_code>def get_type_of_value(val):
    nmbr = True
    if val == 'true' or val == 'false':
        return 'boolean'
    
    for c in val:
        if not c.isdigit():
            nmbr=False
    if nmbr:
        return 'number'
    return 'string'

selected_patterns = []
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if ['Idf_1', '=', 'Lit_1']==pattern['fix'][0:3] and pattern['buggy'][0:3] == ['Idf_1', '=', 'Lit_2']:
            buggy_value = pattern['buggy_actual'][2]
            fix_value = pattern['fix_actual'][2]
            fx_type = get_type_of_value(fix_value)
            bg_type = get_type_of_value(buggy_value)
            if bg_type != fx_type:
                list_of_all_patterns_also_seded_by_mutandis.add(pattern['commit_hash'])
                selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 1<jupyter_text>Matching seeded bug<jupyter_code>p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[0,4]].sort_values(by='mean_similarity')
p<jupyter_output><empty_output><jupyter_text>Swap Parameters**None Found**<jupyter_code>selected_patterns = []
seen_url = set()
for _,r in patterns.iterrows():
    pattern = r.to_dict()
    if "(Idf_3,Idf_4)" in ''.join(pattern['fix']) and "(Idf_4,Idf_3)" in ''.join(pattern['buggy']):
        selected_patterns.append(pattern)
selected_patterns = pd.DataFrame(selected_patterns)
print(f'Number of selected patterns = {len(selected_patterns)}')
selected_patterns[['fix_actual','buggy_actual']]<jupyter_output>Number of selected patterns = 10<jupyter_text>Matching seeded bug<jupyter_code>for i in range(len(selected_patterns)):
    p = seeded_bugs[seeded_bugs['seeding_pattern_url']==selected_patterns.iloc[i,4]].sort_values(by='mean_similarity')
    print(p)<jupyter_output>Empty DataFrame
Columns: [file_name_where_intended, target_token_sequence-Correct, target_token_sequence-Buggy, token_sequence_abstraction-Correct, token_sequence_abstraction-Buggy, target_line_range, num_of_available_identifiers_to_choose_from, num_of_available_literals_to_choose_from, error, mean_similarity, seeding_pattern_url]
Index: []
Empty DataFrame
Columns: [file_name_where_intended, target_token_sequence-Correct, target_token_sequence-Buggy, token_sequence_abstraction-Correct, token_sequence_abstraction-Buggy, target_line_range, num_of_available_identifiers_to_choose_from, num_of_available_literals_to_choose_from, error, mean_similarity, seeding_pattern_url]
Index: []
Empty DataFrame
Columns: [file_name_where_intended, target_token_sequence-Correct, target_token_sequence-Buggy, token_sequence_abstraction-Correct, token_sequence_abstraction-Buggy, target_line_range, num_of_available_identifiers_to_choose_from, num_of_available_literals_to_choose_from, error, mean_similarity, se[...]<jupyter_text>Remove Parameters<jupyter_code>seeded_bugs[seeded_bugs['seeding_pattern_url']=='https://github.com/jquery/jquery/commit/ed1144816b07fbb2ea94217fd967626619344ad9'].sort_values(by='mean_similarity')
print(f'Of {len(patterns)} patterns, {len(list_of_all_patterns_also_seded_by_mutandis)} could be seeded by mutandis')

seeded_bugs['commit_hash'] = seeded_bugs['seeding_pattern_url'].apply(lambda x: x.split('/')[-1])
possibly_seeded_by_mutandis = seeded_bugs.loc[seeded_bugs['commit_hash'].isin(list_of_all_patterns_also_seded_by_mutandis)]
print(f'Of all {len(seeded_bugs)} bugs, {len(possibly_seeded_by_mutandis)} could be possibly seeded by mutandis')<jupyter_output>Of all 677217 bugs, 12787 could be possibly seeded by mutandis
{'fraction_non_alphanumeric': 0.12668203975597653, 'fraction_numerical': 0.018797980092822325, 'mean_word_length': 4.369905956112853, 'pattern_counts': {'":': 0, '<': 168, '<?xml version=': 0, '>': 169, 'https://': 17, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '48', 'dir': 'jupyter-structured-clean-dedup', 'id': '641953', 'license': 'MIT', 'n_tokens_mistral': 12255, 'n_tokens_neox': 11717, 'n_words': 2168, 'path': 'compare_real_bug_finding_ability/syntax_check_mutandis_compare.ipynb', 'repo_name': 'sola-st/SemSeed', 'size': '34259'}