2.2 XML Similarity Joins
2.3.2 Token-based Similarity Functions
Many similarity functions unfold two basic operations: a) transformation of entities of interest into sets containing the smallest units of information, which we call hence- forth tokens, and, afterwards, b) assessment of their similarity based on the number of tokens they have in common; additionally, prior to b), c) weights can be associated with tokens to quantify their relative importance. We refer to operation a) as tokeniza- tion, b) as set-overlap measurement, c) as weighting, and similarity functions employing these operations as token-based similarity functions11. Figure 2.6 depicts the course
11Alternatively, such functions can be referred to as set-overlap-based similarity functions [RH08b]. The
choice is based on which operation is emphasized: tokenization or set-overlap measurement. Therefore, here and in Chapters 3 and 4, we shall use the term token-based. In Chapter 5, we switch to set-overlap-based, as we focus on the set-overlap measurement operation.
of a token-based similarity function along its three components towards a similarity value. We discuss each of these components in the following.
Tokenization
Tokenization is essentially a method for selecting and organizing relevant pieces of information from entities. It can be applied to the content part of an XML document, its structural part, or both, to capture information such as patterns in strings and node relationships. The key idea behind tokenization methods is that most of the tokens derived from significantly similar entities should agree accordingly. As a result, the token sets of two similar entities would only have a large overlap and, in turn, a high similarity value.
Tokenization is carried out by a tokenization function which splits an entity into a set of tokens. We denote by tok [ρ1, . . . , ρn]a tokenization function, where ρ1, . . . , ρn
are free parameters; given an entity e, we refer to the set of tokens tok [ρ1, . . . , ρn](e)
as the tok [ρ1, . . . , ρn]profile of e. Whenever clear from the context or unimportant for
the discussion, we will omit the list of parameters of a tokenization function, i.e., referring to the corresponding set of tokens as the tok profile of a entity e, or even omit the tokenization function altogether (e.g, simply saying the profile of e). In the latter case, we denote by P an arbitrary profile.
Further, we denote by t1 ◦ t2 the concatenation of two arbitrary tokens t1 and t2.
The symbol ◦ denotes a special pattern that cannot be derived from an entity by any tokenization or transformation method. Thus, we have t1◦ t2 = t3iff t3represents the
concatenation of tokens t01 and t 0
2 and t1 = t01, t2 = t02.
We now discuss tokenization functions for content and structure with emphasis on the former. Several structural tokenization functions are presented and evaluated in Chapter 3. The generation of tokens that jointly capture textual and structural information is introduced in Chapter 4.
The concept of q-grams is a well-known approach to tokenize strings [Ukk92]. In- formally, a q-gram is a substring of size q. We denote by qgram[q] the tokenization function that maps a string s to the profile qgram[q](s). There are several ways of splitting a string into a set of q-grams — hence, several variants of the qgram func- tion exist; many of these techniques are designed for filtering-based SED algorithms [Nav01]. For token-based methods, the common procedure consists of ”sliding“ a window of size q over the characters of s. It results in the following profile cardinal- ity: |qgram[q](s)| = |s| − q + 1.
Example 2.7. Consider the strings s1 = Kaiserslauternand s2 = Kaserslatern. Their
qgram[3]profiles profiles are:
qgram[3 ](s1) ={’Kai’, ’ais’, ’ise’, ’ser’, ’ers’, ’rsl’, ’sla’, ’lau’, ’aut’, ’ute’, ’ter’, ’ern’},
qgram[3 ](s2) ={’Kas’, ’ase’, ’ser’, ’ers’, ’rsl’, ’sla’, ’lat’, ’ate’, ’ter’, ’ern’}.
The value of q presents a trade-off between efficiency and effectiveness. Higher values of q are likely to result in less frequent grams for a dataset — the frequency
Figure 2.7: q-grams affected by editing operations, q-2 and q=3
of a string cannot be higher than that of any of its substrings. Intuitively, it leads to fewer strings having a q-gram in common and, thus, more comparisons can be safely avoided (because empty profile overlap means ”no similarity“). In Chapter 5, we de- scribe methods that exploit token frequency, token set size, and the threshold value to reduce even more the number of set-overlap calculations. Unfortunately, the accu- racy normally drops as the value of q increases. To see why, observe that the number of q-grams ”destroyed“ in qgram[q](s) due to edit operations on s is related to the value of q: O(kq) q-grams are destroyed after k edit operations [Ukk92]. Figure 2.7 illustrates this aspect for q = 2 and q = 3. Thus, higher values for q penalize more character mismatches; as q increases, q-gram-based similarity gets closer to equality comparisons. It has been empirically observed that q = 2 and q = 3 give the best accuracy results [CHK+07]. Note that for q = 1, different strings containing identical
(multi-) sets of characters have the same qgram profile and, hence, maximum simi- larity. For q > 1, more complex patterns are required to get this (unwanted) effect [Ukk92]12.
It is common to (conceptually) extend a string s by prefixing and suffixing it with q−1null symbols. Therefore, all characters in s participate in exact q q-grams and mis- matches at any position of s are uniformly weighted. In addition, all white spaces be- tween two words can be replaced by q −1 null symbols [CHK+07]. As a result, q-gram
similarity is made fully insensitive to word ordering, e.g., ”Leonardo Ribeiro“ = ”Ribeiro Leonardo“. Again, such approaches trade efficiency for accuracy. Addi- tional characters result in larger sets and therefore more processing overhead.
Structural tokenization functions operate on element nodes. The most basic func- tion consists of collecting all element node labels of a tree in a bag of labels, thus ignoring all the tree structure. We call this tokenization function labels. More elabo- rate methods exploit parent-child, ancestor-descendant, and sibling relationships. We give an example of a tokenization function based on the parent-child relationship in the following.
12Note that, therefore, token-based similarity functions define a pseudo-metric, because strict positive-
Example 2.8. Consider a structural tokenization function parchild which collects all pairs of
element nodes involved in parent-child relationships. The parchild profiles of the subtrees a) and b) shown in Figure 2.4 are:
parchild (a) ={exame ◦ patient, patient ◦ study, study ◦ id, study ◦ description, patient ◦ name, patient ◦ relatives, relatives ◦ mother},
parchild (b) ={exame◦study, study◦patient, patient◦name, patient◦mother, study◦
id, study ◦ description}.
Weighting Schemes
In many domains, tokens show non-uniformity regarding some semantic properties, such as discriminating power. In fact, previous work consistently revealed that not all tokens are equally important for similarity evaluation [SM83, Jon72, CHK+07].
The process of quantifying this importance is referred to as weighting and the method employed for assigning weights to tokens is called weighting scheme. In other words, a weighting scheme ws converts a profile P = {t0, . . . , tn} into a weighted profile
ws(P) = {ht0, w (t0)i, . . . , hw (tn)i}, where w (t0)is the associated weight of token ti.
Common wisdom from the IR field dictates that tokens appearing very frequently in a collection of documents contribute to the discrimination of them to a lesser de- gree, whereas rare tokens usually carry more content information and are more dis- criminative. Such observation is in accordance with the frequency-based approxima- tion of Newcombe et al. in the EM context, as observed before. The inverse document frequency (IDF) weighting scheme is popularly used to capture this intuition. The idf weight of a token t is inversely proportional to the total number of trees freq(t, C), in which t appears in a collection C.13 A typical idf formulation is given by:
idf (t) = ln(1 + |C|
freq(t, C)). (2.7)
The term frequency (TF), i.e., the frequency of a token in a tree, is also used for weighting. Given a token t appearing freq(t, T ) times in a tree T , its tf weight can be computed as follows:
tf (t) = 1 + ln(freq(t, T )) . (2.8)
The product of both term statistics constitutes the well-known TF-IDF weighting scheme. Several other weighting schemes have been successfully used in IR. In par- ticular, we mention the Okapi BM25 [RW94], which is based on probabilistic retrieval models. An adaptation of Okapi BM25 to XML data is presented in [TSW05].
The utility of the tf weight for string-to-string similarity comparison has been ques- tioned [HCKS08]. In IR, a user-formulated query is compared to normally much larger documents and it is reasonable to consider the frequency of a query token in a
13Note that we have overloaded freq(t, C). In Section 2.1.1, freq(v, C) denotes the frequency of value
in a collection C, whereas, here, freq(t, C) denotes the number of trees in which a token appears, irrespective of how many times it occurs in each tree.
document as an indication that the document is relevant to the query. However for string-to-string comparison, the intuition is just the opposite: frequency discrepancy of the same token present in two strings should decrease their similarity. Moreover, EM systems usually perform comparisons on much shorter strings, e.g., author name fields. A simple solution consists of converting a profile P, composed by a bag of tokens, into a profile Pa, composed by a set of annotated tokens, by concatenating the
symbol of a sequential ordinal number to each occurrence of a token. For example, profile P = {a, b, b} is converted to Pa = {a ◦ 1, b ◦ 1, b ◦ 2}. For annotated tokens, we
have freq(t, T ) = 1, ∀t; thus, their tf-idf weights are determined by the idf weight only. Furthermore, divergence in term frequencies of a token will penalize the similarity of the related strings by a stronger degree, because subsequent occurrences of the referenced token have decreased the document frequency in a collection (and, there- fore, increased the idf weight). Unless stated otherwise, we use annotated profiles (without indication in the subscripts).
Set-overlap Measurement
Tokenization delivers an XML tree represented as a set of tokens. Afterwards, similar- ity assessment can be reduced to the problem of set overlap, where different ways to measure the overlap raise various notions of similarity. Fortunately, there are several set-overlap similarity measures available; most of them can be rewritten into equiv- alent set-overlap predicates [SK04, CGK06]. Next, we formally define the Jaccard, a widely used set-overlap similarity measure and its version for weighted profiles. We present the corresponding set-overlap predicate for Jaccard as well as for other measures in Chapter 5.
Definition 2.3(Jaccard Similarity (JS)). Let P1 and P2 be two profiles. The Jaccard simi-
larity (JS) of P1 and P2is defined as follows:
JS (P1, P2) =
|P1 ∩ P2| |P1| + |P2| − |P1∩ P2|
. (2.9)
Definition 2.4(Weighted Jaccard similarity (WJS)). Let ws(P1)be a weighted profile and
w (t, ws(P1)) be the weight of a token t in ws(P1). Let the weight of ws(P1) be given by
w (ws(P1)) = Pt∈ws(P1)w (t, ws(P1)). Similarly, consider a profile ws(P2). The weighted
Jaccard similarity (WJS) of ws(P1)and ws(P2)is defined as follows:
WJS (ws(P1), ws(P2)) =
w (ws(P1) ∩ ws(P2))
w (ws(P1)) + w (ws(P2)) − w (ws(P1) ∩ ws(P2))
, (2.10)
where the set overlap of ws(P1)and ws(P2)is given by:
w (ws(P1)) ∩ ws(P2) =
X
t∈ws(P1)∩ws(P2)
In the definition above, minimum (min) is used to aggregate varying token weights across different profiles. This situation happens, for example, when the weights are normalized like in [HCKS08]. Another example is the weighting scheme presented in Section 3.2.1.
Example 2.9. Consider the strings s1 = Kaiserslauternand s2 = Kasersluternand their
respective qgram profiles qgram[3 ](s1)and qgram[3 ](s2)shown in Example 2.7. Therefore,
we have:
JS (s1, s2) =
6
12 + 10 − 6 = 0.375.