|
|
|
|
|
from geco_data_generator import basefunctions, attrgenfunct, contdepfunct, generator, corruptor |
|
import random |
|
random.seed(42) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unicode_encoding_used = 'cp932' |
|
|
|
|
|
|
|
|
|
rec_id_attr_name = 'rec-id' |
|
|
|
|
|
|
|
|
|
out_file_name = 'example-data-japanese.csv' |
|
|
|
|
|
|
|
num_org_rec = 10000 |
|
num_dup_rec = 10000 |
|
|
|
|
|
|
|
|
|
max_duplicate_per_record = 3 |
|
|
|
|
|
|
|
|
|
num_duplicates_distribution = 'zipf' |
|
|
|
|
|
|
|
|
|
max_modification_per_attr = 1 |
|
|
|
|
|
|
|
num_modification_per_record = 5 |
|
|
|
|
|
|
|
basefunctions.check_unicode_encoding_exists(unicode_encoding_used) |
|
|
|
|
|
|
|
|
|
|
|
surname_attr = generator.GenerateFreqAttribute( |
|
attribute_name='surname', |
|
freq_file_name='surname-freq-japanese.csv', |
|
has_header_line=False, |
|
unicode_encoding=unicode_encoding_used, |
|
) |
|
|
|
credit_card_attr = generator.GenerateFuncAttribute( |
|
attribute_name='credit-card-number', function=attrgenfunct.generate_credit_card_number |
|
) |
|
|
|
age_normal_attr = generator.GenerateFuncAttribute( |
|
attribute_name='age', |
|
function=attrgenfunct.generate_normal_age, |
|
parameters=[45, 30, 0, 130], |
|
) |
|
|
|
gender_city_comp_attr = generator.GenerateCateCateCompoundAttribute( |
|
categorical1_attribute_name='gender', |
|
categorical2_attribute_name='city', |
|
lookup_file_name='gender-city-japanese.csv', |
|
has_header_line=False, |
|
unicode_encoding=unicode_encoding_used, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
surname_misspell_corruptor = corruptor.CorruptCategoricalValue( |
|
lookup_file_name='surname-misspell-japanese.csv', |
|
has_header_line=False, |
|
unicode_encoding=unicode_encoding_used, |
|
) |
|
|
|
edit_corruptor = corruptor.CorruptValueEdit( |
|
position_function=corruptor.position_mod_normal, |
|
char_set_funct=basefunctions.char_set_ascii, |
|
insert_prob=0.0, |
|
delete_prob=0.0, |
|
substitute_prob=0.6, |
|
transpose_prob=0.4, |
|
) |
|
|
|
missing_val_corruptor = corruptor.CorruptMissingValue() |
|
|
|
|
|
|
|
|
|
|
|
attr_name_list = ['surname', 'age', 'gender', 'city', 'credit-card-number'] |
|
|
|
attr_data_list = [surname_attr, credit_card_attr, age_normal_attr, gender_city_comp_attr] |
|
|
|
|
|
|
|
test_data_generator = generator.GenerateDataSet( |
|
output_file_name=out_file_name, |
|
write_header_line=True, |
|
rec_id_attr_name=rec_id_attr_name, |
|
number_of_records=num_org_rec, |
|
attribute_name_list=attr_name_list, |
|
attribute_data_list=attr_data_list, |
|
unicode_encoding=unicode_encoding_used, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attr_mod_prob_dictionary = { |
|
'surname': 0.5, |
|
'age': 0.2, |
|
'gender': 0.05, |
|
'city': 0.05, |
|
'credit-card-number': 0.2, |
|
} |
|
|
|
|
|
|
|
|
|
|
|
attr_mod_data_dictionary = { |
|
'surname': [(0.9, surname_misspell_corruptor), (0.1, missing_val_corruptor)], |
|
'age': [(0.1, missing_val_corruptor), (0.9, edit_corruptor)], |
|
'gender': [(1.0, missing_val_corruptor)], |
|
'city': [(1.0, missing_val_corruptor)], |
|
'credit-card-number': [(0.1, missing_val_corruptor), (0.9, edit_corruptor)], |
|
} |
|
|
|
|
|
|
|
test_data_corruptor = corruptor.CorruptDataSet( |
|
number_of_org_records=num_org_rec, |
|
number_of_mod_records=num_dup_rec, |
|
attribute_name_list=attr_name_list, |
|
max_num_dup_per_rec=max_duplicate_per_record, |
|
num_dup_dist=num_duplicates_distribution, |
|
max_num_mod_per_attr=max_modification_per_attr, |
|
num_mod_per_rec=num_modification_per_record, |
|
attr_mod_prob_dict=attr_mod_prob_dictionary, |
|
attr_mod_data_dict=attr_mod_data_dictionary, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
rec_dict = test_data_generator.generate() |
|
|
|
assert len(rec_dict) == num_org_rec |
|
|
|
|
|
|
|
rec_dict = test_data_corruptor.corrupt_records(rec_dict) |
|
|
|
assert len(rec_dict) == num_org_rec + num_dup_rec |
|
|
|
|
|
|
|
test_data_generator.write() |
|
|
|
|