Handwritten Text Recognition for manuscripts and early printed texts
Algorithm 3
1. Algorithm #3
CHANGE and ADD transactions;
Several transactions per master
record
Prepared by Perla P. Cosme 1
2. Recall Algorithm #1
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
if (master_key < trans_key)
{ output master record to new master file
Get_Next_master
}
else if (master_key == trans_key)
{ make a change in the master record
output master record in new master file
Get_Next_Trans
Get_Next_Master
}
else
{ print “no matching record in the master file”
Get_Next_Trans
}
Prepared by Perla P. Cosme 2
3. Recall Algorithm #2
Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
if (master_key < trans_key)
{ output master record to new master file
Get_Next_master
}
else if (master_key == trans_key)
{ make a change in the master record
// output master record in new master file
Get_Next_Trans
//Get_Next_Master
}
else
{ print “no matching record in the master file”
Get_Next_Trans
}
Prepared by Perla P. Cosme 3
4. Think about this ….
If Algorithm #3 is to include ADD transaction on
the existing CHANGE transaction in the
Algorithm #2, then when are we allowed to
ADD or create a record?
b.Master key < transaction key
c. Master key = transaction key
d.Master key > transaction key
Prepared by Perla P. Cosme 4
5. Think about this ….
If Algorithm #3 is to include ADD transaction on
the existing CHANGE transaction in Algorithm
#2, then when are we allowed to ADD or
create a record?
b.Master key < transaction key
c. Master key = transaction key
d.Master key > transaction key
Why (c)? Justify.
Prepared by Perla P. Cosme 5
6. Justification why the Answer to the
previous Question cannot be (a)
Let us prove by citing an example:
MF: 6 7 8
TF 8
A
Note: if master key (7) < transaction key (8), and the
transaction is ADD, you might add a record whose
primary key is the same as the one you are about to
create/add.
Prepared by Perla P. Cosme 6
7. Justification why the Answer to the
previous Question cannot be (b)
Let us show one typical example:
MF: 3 6 11
TF: 3 3
C A
Note: if master key (3) is equal to transaction key (3),
you will be creating duplicate records in the master
file. (The master file should never have duplicates.)
Prepared by Perla P. Cosme 7
8. Question: How should Algorithm #2 look like
now to reflect the error in adding a record
when master key = transaction key?
Prepared by Perla P. Cosme 8
9. Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
if (master_key < trans_key)
{ output master record to new master file
Get_Next_master
}
else if (master_key == trans_key)
{Case update_code
‘A’: print “duplicate record”
Get_Next_Trans
‘C’: make a change in the master record
Get_Next_Trans
Default: print “invalid update code”
Get_Next_Trans
}
else /* no matching record in the master file */
{ print “no matching record in the master file”
Get_Next_Trans
}
Prepared by Perla P. Cosme 9
10. Justification why the Answer to the
previous Question is (c)
• It is in the third case (i.e., master key >
transaction key) where we are allowed to add
a new record. Hence, it will be in such section
of the algorithm where we are going to
concentrate making the modifications to
Algorithm #2 to fit to our new requirements –
CHANGE and ADD transactions with multiple
transactions per master record.
Prepared by Perla P. Cosme 10
11. This is the Algorithm
Get_Next_Master #3 that explicitly
Get_Next_Trans includes the error-
While NOT (master_key==sentinel AND trans_key==sentinel) handling routine
if (master_key < trans_key) when master key is
{ output master record to new master file equal to transaction
Get_Next_master key
}
else if (master_key == trans_key)
{Case update_code
‘A’: print “duplicate record”
Get_Next_Trans
‘C’: make a change in the master record
Get_Next_Trans
Default: print “invalid update code”
Get_Next_Trans
}
else
{ // no matching record in the master file
print “no matching record in the master file”
Get_Next_Trans
}
Prepared by Perla P. Cosme 11
12. Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
if (master_key < trans_key)
{ output master record to new master file
Get_Next_master
}
else if (master_key == trans_key)
{Case update_code
‘A’: print “duplicate record”
These two (2) lines
Get_Next_Trans
will still be
‘C’: make a change in the master record
maintained but only
Get_Next_Trans
when the update
Default: print “invalid update code”
code is C.
Get_Next_Trans
}
else
{ // no matching record in the master file
print “no matching record in the master file”
Get_Next_Trans
}
Prepared by Perla P. Cosme 12
13. Get_Next_Master
Get_Next_Trans
While NOT (master_key==sentinel AND trans_key==sentinel)
if (master_key < trans_key)
{ output master record to new master file
Get_Next_master
}
else if (master_key == trans_key)
{Case update_code
‘A’: print “duplicate record”
Get_Next_Trans
We shall introduce a
‘C’: make a change in the master record
function called NOMATCH
Get_Next_Trans
to handle the ADD
Default: print “invalid update code”
transaction and the
Get_Next_Trans
succeeding ADD and/or
}
CHANGE transactions on
else
the same newly created
{ // no matching record in the master file
record.
NOMATCH
}
Prepared by Perla P. Cosme 13
14. Function NOMATCH
Case update_code
‘A’: Build new record from transaction record
new_key = trans_key
Get_Next_Trans
while (trans_key != sentinel AND trans_key == new_key)
Case update_code
‘A’: print “duplicate add” These are the
lines that were
‘C’: make change in the newly created record
retained from
Default: print “invalid update code” Algorithm #2.
Get_Next_Trans
output new record to new master file
‘C’: print “no matching master record for transaction key”
Get_Next_Trans
Default : print “invalid update code”
Get_Next_Trans
Prepared by Perla P. Cosme 14
15. Let’s simulate the SFO using
Algorithm #3
We shall use the same example as what we
presented previously.
Prepared by Perla P. Cosme 15
16. The Third Algorithm
CHANGE and ADD transactions;
several transactions per master record
MF 3 6 10 11
TF 3 3 11 11 11 11 18
C A A C C A A
Prepared by Perla P. Cosme 16
17. ????
Questions?
Comments?
Suggestions? and
Open Forum
Prepared by Perla P. Cosme 17