250 likes | 469 Views
Outline Signature Files - Signature for attribute values - Signature for records - Searching a signature file Signature Trees - Signature tree construction - Searching a signature tree - About balanced signature trees. Signature file
E N D
Outline • Signature Files • - Signature for attribute values • - Signature for records • - Searching a signature file • Signature Trees • - Signature tree construction • - Searching a signature tree • - About balanced signature trees Dr. Yangjun Chen ACS-3902
Signature file • - A signature file is a set of bit strings, which are called signatures. • In a signature file, each signature is constructed for a record in a table, a block of text, or an image. • - When a query arrives, a query signature will be constructed according to the key words involved in the query. Then, the signature file will be searched against the query signature to discard non-qualifying signatures, as well as the objects represented by those signatures. Dr. Yangjun Chen ACS-3902
Signature file • Generate a signature for an attribute value • Before we generate the signature for an attribute value, three parameters have to be determined • F: number of 1s in bit string • m: length of bit string • D: number of attribute values in a record (or average number of the key words of in a block of • text) • Optimal choice of the parameters: • m ln2 = FD Dr. Yangjun Chen ACS-3902
Signature file • - Decompose an attribute value (or a key word) into a series of triplets • - Using a hash function to map a triplet to an integer p, indicating that the pth bit in the signature will be set to 1. • Example: Consider the word “professor”. We will decompose it into 6 triplets: • “pro”, “rof”, “ofe”, “fes”, “ess”, “sor”. • Assume that hash(pro) = 2, hash(rof) = 4, hash(ofe) =8, and hash(fes) = 9. • Signature: 010 100 011 000 Dr. Yangjun Chen ACS-3902
Signature file • - Generate a signature for a record (or a block of text) block: ... SGML ... databases ... information ... word signature: SGML 010 000 100 110 database 100 010 010 100 information 010 100 011 000 object signature (OS) 110 110 111 110 superimposing Dr. Yangjun Chen ACS-3902
Signature file • - Generate a signature for a record (or a block of text) signature file: relation: name sex s1 1011 0110 ... ... John male s2 1011 1001 ... ... s3 1010 0111 s4 0111 0110 s5 0111 0101 s6 0101 1100 s7 1110 0100 s8 1010 1011 Dr. Yangjun Chen ACS-3902
Signature file • Search a signature file • When a query arrives, the query signature will be constructed and the object signatures are scanned and many non-qualifying objects are discarded. • - When comparing the query signature sq and an object signature s, three possible outcomes: (1) the object matches the query; that is, for every bit set in sq, the corresponding bit in the object signature s is also set (i.e., ssq = sq) and the object contains really the query word; (2) the object doesn’t match the query (i.e., ssqsq); and (3) the signature comparison indicates a match but the object in fact doesn’t match the search criteria (false drop). Dr. Yangjun Chen ACS-3902
Signature file • - Search a signature file block: ... SGML ... databases ... information ... object signature (OS): 110 110 111 110 queries: query signatures: matching results: SGML 010 000 100 110 match with OS XML 011 000 100 100 no match with OS informatik 110 100 100 000 false drop Dr. Yangjun Chen ACS-3902
s 1011 0110 1 s 1011 1001 2 s 1010 0111 3 s 0111 0110 4 s 0111 0101 5 s 0101 1100 6 s 1110 0100 7 s 1010 1011 8 • Signature file • - Search a signature file query: John male query signature: 1010 0101 Dr. Yangjun Chen ACS-3902
Signature tree • Signature tree construction • Consider a signature si of length m. We denote it as si = si[1].. si[m], where each si[j] {0, 1} (j = 1, ..., m). We also use si(j1, ..., jh) to denote a sequence of pairs with respect to si: (j1, si[j1])(j2, si[j2]) ... (jh, si[jh]), where 1 jkm for k {1, ..., h}. • Definition (signature identifier)Let S = s1.s2 ... .sn denote a signature file. Consider si (1 in). If there exists a sequence: j1, ..., jh such that for any k i (1 kn)we have si(j1, ..., jh)sk(j1, ..., jh), then we say si(j1, ..., jh) identifies the signature si or say si(j1, ..., jh) is an identifier of si. Dr. Yangjun Chen ACS-3902
s 1011 0110 1 s 1011 1001 2 s 1010 0111 3 s 0111 0110 4 s 0111 0101 5 s 0101 1100 6 s 1110 0100 7 s 1010 1011 8 • Signature tree • - Signature tree construction • Example: • s8(5, 1, 4) = (5, 1)(1, 1)(4, 0) • For any i 8 we have si(5, 1, 4)s8(5, 1, 4). For instance, • s5(5, 1, 4) = (5, 0)(1, 0)(4, 1) s8(5, 1, 4), s2(5, 1, 4) = (5, 1)(1, 1)(4, 1) s8(5, 1, 4), and so on. • s1(5, 4, 1) = (5, 0)(4, 1)(1, 1) • For any i 1 we have si(5, 4, 1)s1(5, 4, 1). Dr. Yangjun Chen ACS-3902
Signature tree • - Signature tree construction • Definition (signature tree) A signature tree for a signature file S = s1.s2 ... .sn, • where sisjfor i j and |sk| = m for k = 1, ..., n, is a binary tree T such that • For each internal node of T, the left edge leaving it is always labeled with 0 and the right edge is always labeled with 1. • T has n leaves labeled 1, 2, ..., n, used as pointers to n different positions of s1, s2, ... and snin S. Let v be a leaf node. Denote p(v) the pointer to the corresponding signature. • 3. Each internal node v is associated with a number, denoted sk(v), to tells which bit will be checked. • 4. Let i1, ..., ihbe the numbers associated with the nodes on a path from the root to a leaf v labeled i (then, this leaf node is a pointer to the ith signature in S, i.e., p(v) = i). Let p1, ..., phbe the sequence of labels of edges on this path. Then, (j1, p1) ... (jh, ph) makes up a signature identifier for si, si(j1, ..., jh). Dr. Yangjun Chen ACS-3902
s1 011 001 000 101 8 5 7 4 7 1 4 s2 111 011 001 111 s3 111 101 010 111 s4 011 001 101 111 s5 011 101 110 101 s6 011 111 110 101 s7 011 001 111 111 s8 111 011 111 111 • Signature tree • - Signature tree construction 1 0 0 1 1 0 1. 3. 0 1 0 1 2. 8. 0 1 0 1 4. 7. 5. 6. Dr. Yangjun Chen ACS-3902
Algorithmsig-tree-generation(file) begin construct a root node r with sk(r) = 1; /*where r corresponds to the first signature s1 in the signature file*/ forj = 2 to n do call insert(sj); end Procedure insert(s) begin stack root; whilestack not empty do 1 {v pop(stack); 2 ifv is not a leaf then 3 {i sk(v); 4 ifs[i] = 1 then {let a be the right child of v; push(stack, a);} 5 else {let a be the left child of v; push(stack, a);} 6 } 7 else (*v is a leaf.*) Dr. Yangjun Chen ACS-3902
8 { compare s with the signature s0 pointed to by p(v); 9 assume that the first k bit of s agree with s0; 10 but s differs from s0 in the (k + 1)th position; 11 w v; replace v with a new node u with sk(u) = k + 1; 12 if s[k + 1] = 1 then make s and w be respectively the right and leftchildren of u 13 else make w and s be the right and left children of u, respectively;} 14 } end Dr. Yangjun Chen ACS-3902
Signature tree • - Signature tree construction 1 Insert s2 0 Insert s1 1 S 1 011001000101 s 1 S 2 111011001111 s 1 s 2 S 3 111101010111 S 4 011001101111 Signature file 1 1 Insert s4 0 1 1 0 7 4 s 1 4 Insert s3 0 1 1 0 1 0 s 1 s 4 s 2 s 3 s 2 s 3 Dr. Yangjun Chen ACS-3902
Signature tree • - Searching of a signature tree • Let sq be a query signature. The ith position of sqis denoted • as sq[i]. During the traversal of a signature tree, the inexact • matching is done as follows: • (i) Let v be the node encountered and sq[i] be the position to • be checked. • (ii) If sq[i] = 1, we move to the right child of v. • (iii) If sq[i] = 0, both the right and left child of v will be explored. Dr. Yangjun Chen ACS-3902
Algorithmsignature-tree-search input: a query signature sq; output: a set of signatures which survive the checking; 1. R . 2. Push the root of the signature tree into stackp. 3. If stackpis not empty, v pop(stackp); else return(R). 4. If v is not a leaf node, i sk(v); If sq(i) = 0, push cr and clinto stackp; (where cr and clare v’s right and left child, respectively.) otherwise, push only cr into stackp. 5. Compare sqwith the signature pointed by p(v). /*p(v) - pointer to the block signature*/ If sqmatches, R R {p(v)}. 6. Go to (3). Dr. Yangjun Chen ACS-3902
1 7 4 4 7 8 5 • Signature tree • - Searching of a signature tree • query signature: sq= 000 100 100 000. 1 0 0 1 0 1 1. 3. 0 1 0 1 2. 8. 0 1 0 1 4. 7. 5. 6. Dr. Yangjun Chen ACS-3902
S1: 100 100 100 100 S2: 010 010 010 010 S3: 001 001 001 001 S4: 000 110 010 010 S5: 000 011 001 001 S6: 000 001 100 100 S7: 000 000 110 010 S8: 000 000 010 110 • Signature tree • - About balanced signature trees • A signature tree can be quite skewed. 1 2 1. 3 2. 41 3. 5 4. 6 5. 7 6. 8. 7. Dr. Yangjun Chen ACS-3902
Signature tree • - About balanced signature trees • Weight-based method: • A signature file S = s1.s2 ... .sn can be considered as a boolean matrix. We use S[i] to represent the ith column of S. We calculate the weight of each S[i], i.e., the number of 1s appearing in S[i], denoted w(S[i]). Then, we choose an j such that |w(S[i]) – n/2| is minimum. Here, the tie is resolved arbitrarily. Using this j, we divide S into two groups g1 = { , ..., } with each [j] = 0 (p = 1, ..., k) and g2 = { , ..., } with each [j] = 1 (q = k + 1, ..., n). Dr. Yangjun Chen ACS-3902
Signature tree • - About balanced signature trees • Weight-based method (continued): • In a next step, we consider each gi (i = 1, 2) as a single signature file and perform the same operations as above, leading to two trees generated for g1 and g2, respectively. Replacing g1 and g2 with the corresponding trees, we get another tree. We repeat this process until the leaf nodes of a generated tree cannot be divided any more. Dr. Yangjun Chen ACS-3902
8 5 2 8 S1: 100 100 100 100 g11 g1 g12 g22 g21 g2 S2: 010 010 010 010 S3: 001 001 001 001 S4: 000 110 010 010 S5: 000 011 001 001 S6: 000 001 100 100 S7: 000 000 110 010 S8: 000 000 010 110 • Signature tree • - About balanced signature trees • Example: g1 = {s1,s3, s5, s6} g2 = {s2,s4, s7, s8} g11 = {s3, s5} g12 = {s6,s1} g21 = {s8, s7} g22 = {s4,s2} Dr. Yangjun Chen ACS-3902
Signature tree • - About balanced signature trees • Algorithmbalanced-tree-generation(file) • input: a signature file. • output: a signature tree. • Begin • let S = file; N |S|; • ifN > 1 then { • choose j such that |w(S[i]) – N/2| is minimum; • let g1 = { , ..., } with each [j] = 0 (p = 1, ..., k); • let g2 = { , , ..., } with each [j] = 1 (q = k + 1, ..., N) Dr. Yangjun Chen ACS-3902
2 8 2 5 5 1 7 generate a tree containing a root r and two child nodes marked with g1 and g2, respectively; skip(r) j; replace the node marked g1 with balanced-tree-generation(g1); replace the node marked g2 with balanced-tree-generation(g2);} else return; end 2. 3 5. 6. 1. 8. 7. 4. Dr. Yangjun Chen ACS-3902