<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction
This IPython notebook illustrates how to perform blocking using rule-based blocker.
First, we need to import py_entitymatching package and other libraries as follows
Step1:  Then, read the (sample) input tables for blocking purposes.
Step2:  Generating Features for Blocking
Step3:  Different Ways to Block Using Rule Based Blocker
There are three different ways to do overlap blocking
Step4:  Block Candidate Set
Step5:  Block Two tuples To Check If a Tuple Pair Would Get Blocked
<ASSISTANT_TASK:>
Python Code:
# Import py_entitymatching package
import py_entitymatching as em
import os
import pandas as pd
Explanation: Introduction
This IPython notebook illustrates how to perform blocking using rule-based blocker.
First, we need to import py_entitymatching package and other libraries as follows:
End of explanation
# Get the datasets directory
datasets_dir = em.get_install_path() + os.sep + 'datasets'
# Get the paths of the input tables
path_A = datasets_dir + os.sep + 'person_table_A.csv'
path_B = datasets_dir + os.sep + 'person_table_B.csv'
# Read the CSV files and set 'ID' as the key attribute
A = em.read_csv_metadata(path_A, key='ID')
B = em.read_csv_metadata(path_B, key='ID')
A.head()
B.head()
Explanation: Then, read the (sample) input tables for blocking purposes.
End of explanation
block_f = em.get_features_for_blocking(A, B, validate_inferred_attr_types=False)
block_f
em._block_c['corres']
em._atypes1['birth_year'], em._atypes1['hourly_wage'], em._atypes1['name'], em._atypes1['zipcode']
em._atypes2['birth_year'], em._atypes2['hourly_wage'], em._atypes2['name'], em._atypes2['zipcode']
Explanation: Generating Features for Blocking
End of explanation
rb = em.RuleBasedBlocker()
# Add rule : block tuples if name_name_lev(ltuple, rtuple) < 0.4
rb.add_rule(['name_name_lev_sim(ltuple, rtuple) < 0.4'], block_f)
C = rb.block_tables(A, B, l_output_attrs=['name', 'address'], r_output_attrs=['name', 'address'], show_progress=False)
C.head()
Explanation: Different Ways to Block Using Rule Based Blocker
There are three different ways to do overlap blocking:
Block two tables to produce a candidate set of tuple pairs.
Block a candidate set of tuple pairs to typically produce a reduced candidate set of tuple pairs.
Block two tuples to check if a tuple pair would get blocked.
Block Tables to Produce a Candidate Set of Tuple Pairs
End of explanation
rb = em.RuleBasedBlocker()
rb.add_rule(['birth_year_birth_year_exm(ltuple, rtuple) == 0'], block_f)
D = rb.block_candset(C, show_progress=False)
D.head()
Explanation: Block Candidate Set
End of explanation
A.loc[[0]]
B.loc[[1]]
rb = em.RuleBasedBlocker()
# Add rule : block tuples if name_name_lev(ltuple, rtuple) < 0.4
rb.add_rule(['name_name_lev_sim(ltuple, rtuple) < 0.4'], block_f)
rb.add_rule(['birth_year_birth_year_exm(ltuple, rtuple) == 0'], block_f)
status = rb.block_tuples(A.loc[0], B.loc[0])
print(status)
Explanation: Block Two tuples To Check If a Tuple Pair Would Get Blocked
End of explanation
<END_TASK>