Site-level web template extraction based on hyperlink analysis
Abstract
[EN] Method for automatic template extraction based on similarity analysis between the DOM trees of a collection of webpages
Full text
Master’s Thesis Julián Alarte Aleixandre September 12, 2014
2 Site-Level Web Template Extraction Based on Hyperlink Analysis
Abstract Web templates are one of the main development resources for website engineers. Templates allow them to increase productivity by plugin content into already formatted and prepared pagelets. Templates are also useful for the final users, because they provide uniformity and a common look and feel for all webpages. However, from the point of view of crawlers and indexers, templates are an important problem, because templates usually contain irrelevant information such as advertisements and banners. Processing and storing this information is likely to lead to a waste of resources (storage space, bandwidth, etc.). It has been measured that templates represent between 40% and 50% of data on the Web. Therefore, identifying templates is essential for indexing tasks. This work proposes a novel method for automatic template extraction that is based on similarity analysis between the DOM trees of a collection of webpages that are detected using menus information.
Resumen En el desarrollo Web, el uso de plantillas es uno de los recursos más importantes para los ingenieros. Las plantillas les permiten incrementar la productividad mediante la inserción de contenido dentro de páginas previamente formateadas con un diseño definido. Las plantillas también son de gran utilidad para el usuario final, porque proporcionan uniformidad y un diseño común al sitio web. Sin embargo, desde el punto de vista de los buscadores e indexadores, las plantillas pueden suponer un importante problema, porque normalmente suelen contener información irrelevante como publicidad, etc. El procesamiento y almacenamiento de toda esa información incide en un mal aprovechamiento de recursos tales como espacio de almacenamiento, ancho de banda, etc. Algunos estudios indican que entre el 40 % y el 50 % de los datos totales de las páginas web forman parte de las plantillas. Por lo tanto, la identificación de las plantillas es fundamental para llevar a cabo tareas como la indexación. Este trabajo propone un nuevo método para la extracción automática de plantillas basado en el análisis de la similitud de árboles DOM extraídos de una colección de páginas web seleccionadas mediante la información de sus menús.
2
Contents 1 Introduction 5 1.1 Template detection . . . . . . . . . . . . . . . . . . . . . . . . 5 1.2 RelatedWork........................... 7 1.3 Preliminary definitions . . . . . . . . . . . . . . . . . . . . . . 9 2 Identifying webpages sharing a template 15 2.1 Templates............................. 15 2.2 Finding template candidates in a website topology . . . . . . 16 2.2.1 Hyperlink analysis . . . . . . . . . . . . . . . . . . . . 18 2.2.2 Hyperlink distance . . . . . . . . . . . . . . . . . . . . 20 2.2.3 DOM distance . . . . . . . . . . . . . . . . . . . . . . 24 2.2.4 Hyperlinks order . . . . . . . . . . . . . . . . . . . . . 26 2.2.5 Extracting the n-CS . . . . . . . . . . . . . . . . . . . 30 3 Template detection 33 3.1 Parameters ............................ 33 3.2 Attributes............................. 33 3.3 Exact top-down mapping . . . . . . . . . . . . . . . . . . . . 37 3.4 Extraction algorithm . . . . . . . . . . . . . . . . . . . . . . . 38 4 Implementation 41 4.1 Implementation.......................... 41 4.2 The firefox toolbar . . . . . . . . . . . . . . . . . . . . . . . . 43 4.3 Examples ............................. 44 5 Empirical evaluation 47 5.1 Experiments............................ 47 5.2 Optimizations and tunning . . . . . . . . . . . . . . . . . . . 49 5.2.1 Optimization experiments . . . . . . . . . . . . . . . . 49 5.2.2 Determining n and t parameters . . . . . . . . . . . . 50 5.2.3 Making precise the comparison of DOM nodes . . . . . 51 5.2.4 Domain boundaries . . . . . . . . . . . . . . . . . . . . 53 5.2.5 Implementation and experiments download . . . . . . 53 3
4CONTENTS 6 Benchmark suite 55 6.1 Introduction............................ 55 6.2 The TECO Benchmark Suite . . . . . . . . . . . . . . . . . . 56 6.2.1 Producing the gold standard . . . . . . . . . . . . . . 57 6.2.2 Benchmark details . . . . . . . . . . . . . . . . . . . . 57 6.2.3 Guidelines for using the suite . . . . . . . . . . . . . . 62 7 Conclusions 65 8 Future work 67 9 Contributions 69 9.1 International publications . . . . . . . . . . . . . . . . . . . . 69 9.2 National publications . . . . . . . . . . . . . . . . . . . . . . . 70
Chapter 1 Introduction 1.1 Template detection A web template (in the following just template) is a prepared HTML page where formatting is already implemented and visual components are ready to insert content. Templates allow developers to compose their webpages with independent blocks that can be reused. This is good for web development because many tasks can be automated and webpage sections can be maintained separately. In fact, many webpage development environments and code generators offer collections of templates that already include Javascript, CSS, Flash, etc. Templates are also good for users, which can benefit from intuitive and uniform designs with a common vocabulary of colored and formatted visual elements. This fact improves the user experience and the usability of the website. Contrarily, templates suppose an important problem for crawlers and indexers, because they judge the relevance of a webpage according to the frequency and distribution of terms and hyperlinks. Since templates contain a considerable number of common terms and hyperlinks that are replicated in a large number of webpages, relevance may turn out to be inaccurate, leading to incorrect results (see, e.g., [2, 21, 23]). Moreover, in general, templates do not contain relevant content, they usually contain one or more pagelets [6, 2] (i.e., self-contained logical regions with a well defined topic or functionality) where the main content must be inserted. Therefore, detecting templates can help indexers to identify the main content of the webpage. Figure 1.1 shows two webpages belonging to the UPV website. Both webpages share a header where we can distinguish the university logo and an accessibility menu. Below the logo we can find the main menu and all its options. In both webpages, the main content, which obviously does not belong to the template, is found inside the dotted square. The footer is shared by both webpages and it can be found below the main content. In 5
6CHAPTER 1. INTRODUCTION this case, the template could be the union of the header and the footer. Figure 1.1: UPV webpage template Modern crawlers and indexers do not treat all terms in a webpage in the same way. First of all, the template is identified by preprocessing the webpages. Template detection allows them to identify those pagelets that only contain noisy information such as advertisements and banners. This content should not be indexed in the same way as the relevant content. Indexing the non-content part of templates not only affects accuracy, it also affects performance. The processing and treatment of this amount of irrelevant data can lead to a waste of storage space, bandwidth and time. Template detection enhance indexers by isolating the main content and assigning higher weights to the really relevant terms. As the main content is usually complementary to the template, the result of removing the template will probably isolate the main content. Once templates have been extracted, they are processed for indexing—they can be analyzed only once for all webpages using the same template—. Moreover, links in templates allow indexers to discover the topology of a website (e.g., through navigational content such as menus), thus identifying the main webpages. They are also essential to compute pageranks. Gibson et al. [9] determined that templates represent between 40% and 50% of data on the Web and that around 30% of the visible terms and hyperlinks appear in templates. This justifies the importance of template removal [23, 21] for web mining and search. This approach to template detection is based on the DOM [7] structures that represent webpages. Roughly, given a webpage in a website, the first step is to identify a set of webpages that are likely to share a template with it. Then these webpages have to be analyzed to identify the part of their DOM trees that they share with the original webpage. This slice of the DOM tree is returned as the template. This technique exploits a new idea to automatically find a set of webpages that potentially share a template. The process detects the template’s
1.3. PRELIMINARY DEFINITIONS 13 Figure 1.7: ETDM mapping example between the key page and 2 webpages
14 CHAPTER 1. INTRODUCTION
Chapter 2 Identifying webpages sharing a template 2.1 Templates Templates are often composed of a set of pagelets. Two of the most important pagelets in a webpage are the menu and the main content. Example 2.1.1 Consider two webpages that belong to the ZME website in Figure 2.1. At the top of the webpages we see the main menu containing links to all ZMEscience principal topics. In the left webpage we can also see an example of a submenu showing the subsections of topic "Research". The left webpage belongs to "Robotics" subsection of topic "Science", while the right webpage belongs to "Animals" section of topic "Environment". Both share the same menu, their respective submenus, and general structure. In both webpages the main content, i.e., the news, is inside the pagelet in the dashed square. In addition to the main content, there is a common pagelet called "Popular this week" with the most relevant news, and another one for subscription and social networks. Additionally, a set of related news (different for each webpage) is shown between the menu and the main content. Example 2.1.2 Figure 2.2 shows two webpages that belong to the BBC website. The one on the left is the main UK news webpage, and the one on the right is the US and Canada main news webpage. At the top of both websites there are two menus, one on the top with the main sections of the BBC website and another one with the subsections of each section. These both websites are subsections of the main section "News". Both webpages share their header which includes the logo, the main menu and the submenu. They also share the footer which does not appear in the pictures. The central part of the websites is divided into two pagelets. The pagelet on the left, is the main content of the website. The pagelet on the right contains sections like videos, the most popular news, ads, etc. 15
16CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE Figure 2.1: Webpages of ZMEscience sharing a template Figure 2.2: Webpages of BBC sharing a template Our approach is very simple yet powerful: 1. Starting from the key page, it identifies a complete subdigraph (CS) in the website topology, and then 2. it extracts the template by calculating an ETDM between the DOM tree of the key page and some of the DOM trees of the webpages in the complete subdigraph. Both processes are explained in the following sections. 2.2 Finding template candidates in a website topology Analyzing the hyperlinks of a website is good way of identifying its topology. We observed that webpages linked by the items in a menu are usually
2.2. FINDING TEMPLATE CANDIDATES IN A WEBSITE TOPOLOGY17 mutually linked, thus, they form a complete subdigraph. Identifying the CS is a new way of identifying the webpages that contain the menu. At the same time, these webpages are the roots of the sections linked by the menu. The following example illustrates why menus provide very useful information about the interconnection of webpages in a given website. Example 2.2.1 Consider the ZMEscience website. Two of its webpages are shown in Figure 2.1. In this website all webpages share the same template, and this template has a main menu that is present in all webpages, and a submenu for each item in the main menu. The site map of the ZMEscience website may be represented with the topology shown in Figure 2.3. Figure 2.3: ZMEscience Website topology In this figure, each node represents a webpage and each edge represents a link between two webpages (we only draw some of the edges for clarity). Solid edges are bidirectional, and dashed and dotted edges are directed. Black nodes are the webpages pointed by the main menu. Because the main menu is present in all webpages, then all nodes are connected to all black nodes. Therefore all black nodes together form a complete graph (i.e., there is an edge between each pair of nodes). Grey nodes are the webpages pointed by a submenu, thus, all grey nodes together also form a complete graph. White nodes are webpages inside one of the sections of the submenu, therefore, all of them have a link to all black and all grey nodes. Not all the webpages in a website implement the same template, some of them only implement a subset of a template. For this reason, one of the main problems of template detection is deciding what webpages should be analyzed. Minimizing the number of webpages analyzed is essential to reduce the task. In our technique we introduce a new idea to select the webpages that must be analyzed: we identify a menu in the key page and we analyze the webpages pointed out by this menu. Observe that we only need to investigate the webpages linked by the key page, because they will for sure contain a CS that represents the menu. In order to ensure high precision, we search for a CS that contains enough webpages that implement the template. It is important to remark that
18CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE a webpage can contain several menus and submenus; and not all of them produce equally good CSs. For instance, consider again the topology shown in Figure 2.3. If we assume that the key page is one of the white nodes, then, a CS formed with the grey nodes (the submenu) will be probably better than a CS formed by the black nodes (the main menu). This happens because the white nodes belong to one of the items in the submenu, and thus, they (probably) are more related semantically, and they (probably) share more syntax components. Note that at least the submenu is a common substructure shared by all grey and white nodes (but not necessarily by the black nodes). Example 2.2.2 Consider again the graph in Figure 2.3. Figures 2.4, 2.5 and 2.6 provide examples to illustrate the differences between each kind of node. Firstly, Figure 2.4 represents a white node because it is a webpage pointed by a submenu option, that submenu option is pointed by the “news” main menu option. This webpage shares several components with the grey nodes also pointed by the “news” main menu option, like the webpages in Figure 2.5. They all share their header, they both are formed by two columns, a wider one on the left and another thinner on the right. They also share the footer element and the boxes style and distribution. Figure 2.6 webpages represent black node pages, they are links from the main menu. Comparing this pair of webpages with the webpage in Figure 2.4 shows that they have only a few blocks in common, like the footer and the main menu, even the header is now different between them, so they share only a small part of the template. Figure 2.4: White node belonging to bbc.co.uk 2.2.1 Hyperlink analysis By analyzing the links in the key page, it is possible to select those links that most likely produce the best CS. This is essential to avoid analyzing all links and thus significantly increasing the performance. Our strategy to identify
2.2. FINDING TEMPLATE CANDIDATES IN A WEBSITE TOPOLOGY19 Figure 2.5: Gray nodes belonging to bbc.co.uk Figure 2.6: Black nodes belonging to bbc.co.uk the links that should be analyzed is based on the structure of the website. We obtain information about the structure of the website from the URLs of the links. Example 2.2.3 Consider a key page Pwhose URL is: www. upv. es/ research/ maths/ index. html Consider that Pcontains four links with the following URLs: •URL 1 = www. tesco. es/ •URL 2 = www. upv. es/ research/ maths/ pi. html •URL 3 = www. upv. es/ sport/ •URL 4 = www. upv. es/ research/ maths/ news/ computers. html URL 1 points to a webpage in another domain. Therefore, the template of this webpage is probably completely different from the template of the key page. URL 2 points to a webpage in the same folder as the key page. Hence, very likely, they both belong to the same section in the hierarchy of the website,
20CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE and thus their structure is probably similar. URL 3 points to a webpage (index.html) of a folder that is two levels above the current directory. It probably points to another section (e.g., to another section in the main menu called sport). Therefore, the structures of the key page and the webpage pointed by URL 3 are possibly different. Probably, they will only share a small part of their templates. URL 4 points to a webpage located in a subfolder of the current folder. Probably, this webpage is semantically related to the key page, and it contains specialized information (it possibly extends the template with additional information). 2.2.2 Hyperlink distance Analyzing the links in the key page, we can establish an order of relevance. In order to formally define a partial order that can be used by our algorithms to sorts the links, we need first to provide a notion of link and distance between links. Definition 2.2.4 (hyperlink) Ahyperlink (or just link) is a sequence of words separated by slash: h“ pdir{q`. The length of a link his represented with |h|and it denotes the number of words in the sequence: |h| “ "1 if h“dir{ 1` |h1|if h“dir{h1where h1is a link (2.1) Note that this definition deliberately ignores the name of the resource pointed by the URL; it only focusses on the structure (directories or domains). It is general enough as to include URLs such as www.upv.es{, research{and research{maths{. In the following we use headphqto refer to the first word in a link. E.g., headpdir1{dir2{dir3{q “ dir1. We now provide a notion of distance between two URLs. Definition 2.2.5 (hyperlink distance) Given two hyperlinks h, h1, the distance from hto h1is defined as: hDistanceph, h1q “ $ ’ ’ ’ ’ & ’ ’ ’ ’ % 0 if h“h1 `|h1|if h1“hh1 ´|h1|if h“h1h1 ´|h1|if h“h0h1and h1“h0h2and headph1q ‰ headph2q ´|h|if headphq ‰ headph1q (2.2) Observe that the distance is defined from the first link to the second link. This is illustrated in Figure 2.7 that represents a tree of directories that contain webpages. There, we can see the distance of all webpages to the webpage in the gray directory. Some particular examples follow:
2.2. FINDING TEMPLATE CANDIDATES IN A WEBSITE TOPOLOGY21 hDistance(research/maths/, research/maths/) = 0 hDistance(research/maths/, research/maths/geometry/) = +1 hDistance(research/maths/, research/) = -1 hDistance(research/maths/, research/physics/dynamics) = -1 hDistance(research/maths/, www.upv.es/research/) = -2 Figure 2.7: Hyperlink distance Intuitively, given two links h1and h2, a distance of 0 means that both links point to the same directory. A positive distance from h1to h2, means that h2points to a subdirectory inside the directory pointed by h1. A negative distance from h1to h2, means that h2points to a directory outside the directory pointed by h1. We use the url of the key page as a reference link to compute distances. And we compare the distances of the links in the key page. Those links with distance 0 are preferred. Then those with a positive distance, and finally those with a negative distance. Example 2.2.6 Consider the BBC website in Figure 2.8. Some examples of distances between its hyperlinks are the following: Figure 2.8: BBC news webpage 1. Distance between the news webpage in Figure 2.8 and the tech news category webpage:
22CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE The tech news webpage is referenced by the news webpage. The tech Figure 2.9: Hyperlink distance in a website hierarchy news webpage is stored in a subdirectory of the news directory, so the distance between them is a positive distance with value 1. hDistance(www.bbc.com/news/technology, www.bbc.com/news) = +1 2. Distance between the news webpage in Figure 2.8 and the main webpage: The root directory contains the main webpage and the news directory Figure 2.10: Hyperlink distance in a website hierarchy is a subdirectory of the root directory, so in this example the hyperlink distance is negative with value 1. hDistance (www.bbc.com/news, www.bbc.com) = -1 3. Distance between the news webpage in Figure 2.8 and the European news webpage: The europe directory is a subdirectory of world, which is a subdirectory of news. That is, there is a positive distance with value 2 between the pages inside the news directory and the europe directory.
2.2. FINDING TEMPLATE CANDIDATES IN A WEBSITE TOPOLOGY29 Figure 2.16: Partial DOM tree of www.bbc.com/news/ dDistance(A3,A1)=6 dDistance(A3,A2)= 3 dDistance(A3,A4)=7 dDistance(A3,A5)=7 dDistance(A5,A1)= 5 dDistance(A5,A2)=6 dDistance(A5,A3)=7 dDistance(A5,A4)=6 The minimum values of the distances above, following the DOM relevance algorithm, indicate that link(A5) is prior to link(A3), so the correct order of the first two links is: {www.bbc.com/news/also_in_the_news/, www.bbc.com/news/uk/} Then, we can add the following hyperlink, link(A4), in the link relevance order: {www.bbc.com/news/also_in_the_news/, www.bbc.com/news/uk/, www.bbc.com/news/world/europe/} The following two hyperlinks link(A2) and link(A4) in the link relevance order are drawn, so we need the DOM relevance algorithm: dDistance(A2,A1)=5 dDistance(A2,A3)= 3
30CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE dDistance(A2,A4)=6 dDistance(A2,A5)=6 dDistance(A4,A1)= 5 dDistance(A4,A2)=6 dDistance(A4,A3)=7 dDistance(A4,A5)=6 The minimum values of the distances above, following the DOM relevance algorithm, indicate that link(A4) is prior to link(A2), therefore the set of links is ordered as follows: {www.bbc.com/news/also_in_the_news/, www.bbc.com/news/uk/, www.bbc.com/news/world/europe/, www.bbc.com/sport/0/football/28497920/, www.bbc.com} 2.2.5 Extracting the n-CS Now we are in a position to describe our algorithm that identifies a CS in a website. This algorithm is Algorithm 2. Algorithm 2 Extract a n-CS from a website Input: An initialLink that points to a webpage and the expected size nof the CS. Output: A set of links to webpages that together form a n-CS. If a n-CS cannot be formed, then they form the biggest m-CS with m ăn. begin keyPage “loadWebPagepinitialLinkq; reachableLinks “getLinkspkeyPageq; processedLinks “ H; connections “ H; bestCS “ H; foreach link in reachableLinks webPage “loadWebPageplinkq; existingLinks “getLinkspwebP ageq X reachableLinks; processedLinks “processedLinks Y tlinku; connections “connections Y tplink ÑexistingLinkq | existingLink PexistingLinksu; CS “ tls PPpprocessedLinksq | link Pls ^ @l, l1Pls . plÑl1q,pl1Ñlq P connectionsu; maximalCS “cs PCS such that @cs1PCS . |cs|ě|cs1|; if |maximalCS| “ nthen return maximalCS; if |maximalCS|ą|bestCS |then bestCS “maximalCS; return bestCS ; end The algorithm uses two trivial functions: •loadWebPageplinkq, which loads and returns the webpage pointed by the input link, and
2.2. FINDING TEMPLATE CANDIDATES IN A WEBSITE TOPOLOGY31 •getLinkspwebpageq, which returns the collection of (non-repeated) links2 in the input webpage (ignoring self-links). Function sortLinks corresponds to Algorithm 1. Observe that the main loop iteratively explores the links of the webpage pointed by the initialLink (i.e., the key page) until it founds a n-CS. Note also that it only loads those webpages needed to find the n-CS, and it stops when the n-CS has been found. We want to highlight the mathematical expression CS “ tls PPpprocessedLinksq | link Pls ^ @l, l1Pls . plÑl1q,pl1Ñlq P connectionsu where PpXqreturns all possible partitions of set X. This line is used to find the set of all CS that can be constructed with the current link. The current link must be part of the CS (link Pls) to ensure that we make progress (not repeating the same search of the previous iteration). Moreover, because the CS is constructed incrementally, the statement if |maximalCS| “ nthen return maximalCS ensures that whenever a n-CS can be formed, it is returned. Figure 2.17 shows an IEEE webpage on the left, and 4 hyperlinks forming a 4-CS obtained from that IEEE webpage on the right. 2In our implementation, this function removes those links that point to other domains because they are very unlikely to contain the same template. Here, we do not impose this restriction to keep the algorithm general.
32CHAPTER 2. IDENTIFYING WEBPAGES SHARING A TEMPLATE Figure 2.17: 4-CS in the IEEE website
Chapter 3 Template detection 3.1 Parameters Once we have found a set of webpages linked by a menu of the website (the CS), we need to decide what nodes in the DOM tree of the key page belong to the template. Of course, those nodes that belong to the DOM trees of all webpages in the CS should be considered part of the template. But the question is: what should we do with those nodes that appear in only some of the webpages? Probably, a node that appears in all webpages but one belongs to the template. It is just that for some reason this webpage has skipped this part of the template. What should be the general criterion? To how many CS webpages should belong a node to mark it as part of the template? What is the best CS size? We have answered these questions with empirical evaluation. Given a n-CS, we call tto the threshold used to decide in how many webpages must be a node to be considered part of the template. The process to obtain the optimal nand tvalues is explained in Section 5.2.2. Here we present the formalization of our algorithm that is parametric and can be used with any value for nand t. Given a concrete values for n and t, we first obtain a n-CS with Algorithm 2, and then we use the ETDM formalism to determine how many webpages contain a given node of the key page. In particular, all those nodes that belong to an ETDM between the key page and twebpages of the n-CS are considered part of the template. 3.2 Attributes We need to enhance the nodes with new attributes that we will use in the rest of the section to infer whether a node belong to a template. The new node attributes are described in the following definition. Definition 3.2.1 (node attributes) Every node nin a DOM tree T“ pN, Eqcontains the attributes specified in the DOM model [7] including: 33
34 CHAPTER 3. TEMPLATE DETECTION Tag: We refer to the tag of a DOM node by using tagpnqand it corresponds to the DOM attribute nodeName. Id: We refer to the id of a DOM node by using idpnqand it corresponds to the DOM attribute id. Classes: We refer to the set of classes assigned to a DOM node by using classespnqand it corresponds to the DOM attribute className. Attributes: We refer to the set of attribute names defined in a DOM node by using attributespnqand it corresponds to the DOM attribute attributes where we remove the attributes named class and id. Child Index: We refer to the child index of a DOM node using childIndexpnq and it is derived from the DOM attributes parentNode and childNodes. With these node attributes, we can find out whether two nodes are equal. This information is crucial to check the template membership of a node. If a node is equal to a node in the key page, then we can relate both webpages and start to infer the template. Our notion of equality cannot be defined with an exact formula, because DOM trees belonging to different webpages rarely share exactly the same nodes. Instead of that, we use a notion based on probabilities. We use each attribute of the nodes to infer individuals probabilities that we join in the last step to give a probability for two nodes to be equal. When we join these individual probabilities, we can give different weights to each of them. We chose to let this information as a parameter, allowing us to test with empirical evaluation (described in Section 4) the best values for each one. Apart form these parameters, we need another ones to define the probability of two nodes when one of the attributes is not present in both nodes, so we defined a parameter for missed attributes for each individual probability. Our notion of equality is formalized in the following definition. Definition 3.2.2 (equality probability) The probability P“for two nodes n1and n2to be equal is calculated as follows. P“pn1, n2q “ $ ’ ’ ’ ’ ’ & ’ ’ ’ ’ ’ % 0if tagpn1q ‰ tagpn2q 1if tagpn1q “ tagpn2q ^ idpn1q “ idpn2q wcˆPcpn1, n2, Pncq ` waˆPapn1, n2, Pnaq ` wch ˆPchpn1, n2, Pnchq ` wpˆPppn1, n2qotherwise where: •Pcis the probability to be equal according to the nodes classes. It is defined as follows: Pcpn1, n2, Pncq “ #Pnc if classespn1q “ H ^ classespn2q“H |classespn1qŞclassespn2q| |classespn1qŤclassespn2q| otherwise
3.2. ATTRIBUTES 35 •Pais the probability to be equal according to the nodes attributes. It is defined as follows: Papn1, n2, Pnaq “ #Pna if attributespn1q “ H ^ attributespn2q“H |attributespn1qŞattributespn2q| |attributespn1qŤattributespn2q| otherwise •Pch is the probability to be equal according to the number of children. It is defined as follows: Pchpn1, n2, Pnchq “ #Pnch if |childrenpn1q| “ 0^ |childrenpn2q| “ 0 minp|childrenpn1q|,|childrenpn2q|q maxp|childrenpn1q|,|childrenpn2q|q otherwise •Ppis the probability to be equal according to the nodes position. It is defined as follows: Given two trees T“ pN, Eqand T1“ pN1, E1q, four nodes pPT, p1PT1,nPTsuch that ppÑnq P E,n1PT1such that pp1Ñn1q P E1, cand c1the number of children of pand p1respectively, iand i1the child positions starting from the left of nand n1respectively, jand j1 the child position starting from the right of nand n1respectively, and c˚ “ minpc, c1q.Ppis the probability of nto be n1(and n1to be n) according to the nodes position and is calculated as follows: –If c1=cthen 1 – (|i–i1| / c˚) –If c1>cthen 1 – (max(0, i–i1,j–j1) / c˚) –If c1<cthen 1 – (max(0, i1–i,j1–j) / c˚) Ppshows how to assign a position probability to each pair of nodes of different trees. Roughly speaking, the probability is higher as more similar are both positions in their trees. Once their positions are less similar, their probability descends as well. We show two examples showing this idea. Example 3.2.3 Figure 3.1 shows that the fourth node starting from the left in the tree A has a probability of 100% of being the fourth node starting from the left in the tree B. In addition, it is the first node starting from the right in the tree A, so the first node starting from the right in the tree B will also have a 100% probability. Example 3.2.4 Figure 3.2 shows that the fourth node starting from the left in the tree A has a probability of 100% of being the fourth node starting from the left in the tree B. In addition, it is the second node starting from the right in the tree A, so the second node starting from the right in the tree B will also have a 100% probability.
36 CHAPTER 3. TEMPLATE DETECTION Figure 3.1: Position probability example Figure 3.2: Position probability example Example 3.2.5 Consider the two DOM trees in Figure 3.3. The gray node of the DOM tree on the left has the following attributes: 1. ClassName = "Author" 2. Attributes = {float:left, color: black, background-color:silver} 3. Children = 2 4. Position = 11 The gray node of the DOM tree on the right has the following attributes: 1. ClassName = "Author" 2. Attributes = {float:left, color: gray, background-color:silver} 3. Children = 3 4. Position = 9 We assume we obtained the following values with empirical evaluation: wc= 0.4, wa= 0.1, wch = 0.1 and wp= 0.4. Now, we can calculate the probability for the two nodes to be equal applying the definition 3.2.5:
3.3. EXACT TOP-DOWN MAPPING 37 The tag of both nodes is DIV but the id is not present, so the probability cannot be 0 or 1 and we have to infer it from the attributes. 1. Pc= 1 because the ClassName of both nodes is equal. 2. Pa= 0.66 because they share two of their three attributes. 3. Pch = 0.66 because the first node only has two children and the other has three. 4. Pp= 0.95 because of their position. If we sum all the partial probabilities we get: P“pn1, n2q “ wcˆPc`waˆ Pa`wch ˆPch `wpˆPp“0.4ˆ1`0.1ˆ0.66`0.1ˆ0.66`0.4ˆ0.95 “0.912 In consequence, their probability of being the same node is 91.20%. If there is not another pair of nodes pn1, n2qwith higher probability, they will be considered the same node. Figure 3.3: DOM trees 3.3 Exact top-down mapping Before introducing our algorithm to extract the template, we need to define a mapping between two sets of nodes. This mapping is essential to relate the nodes of two DOM trees because it allows us to discard those parts that are not equal. The mapping that we use here is an exact top-down mapping according to Definition 1.3.4 and it is mainly based on the equality probability of Definition 3.2.2. The following definition describes and formalizes our mapping.
38 CHAPTER 3. TEMPLATE DETECTION Definition 3.3.1 (exact top-down mapping based on equality probability) The exact top-down mapping between two sets of nodes N1and N2 according to the equality probability is defined as follows. mappingpN1, N2q “ pn1, n2qŤ mappingpbeforepn1, N1q,beforepn2, N2qŤ mappingpafterpn1, N1q,afterpn2, N2qq where: •n1PN1, n2PN2such that Epn1 1, n1 2q P N1ˆN2. P“pn1 1, n1 2q ą P“pn1, n2q ^ P“pn1, n2q ą Pt, being Ptan arbitrary constant •beforepn, Nq“tn1PN|childIndexpn1q ă childIndexpnqu •afterpn, Nq“tn1PN|childIndexpn1q ą childIndexpnqu The key idea in the mapping calculation is that given two sets of nodes we select the best matching nodes among all the possible combinations. After this step, we divide the rest of nodes into two groups (nodes before and after the selected nodes), then, we continue calculating the mapping between these sets separately. The constant Ptis a threshold used to decide whether two nodes n1and n2are the same based on a given probability P“pn1, n2q. 3.4 Extraction algorithm We are now in a position to describe our algorithm. After we have found a set of webpages linked by the menu of the site (the complete subdigraph), we identify an ETDM between the key page and all webpages in the set. For achieve this, we use Algorithm 3 that is mainly based on the function ETDM . This function computes the biggest ETDM between a tree and a set of trees. It iterates between the children of the root of the given tree T. For each child n1, it first looks for nodes that match n1among the set of trees P. This matching is checked with an exact top-down mapping based on equality probability, as defined in Definition 3.3.1. With the results of this search a new set of trees P1is built. This set includes the subtrees of the matching nodes. Note that, at this point, some of the trees that form Pcan be skipped. With the set P1and the subtree of n1, a recursive call is made with the ETDM of the subtrees. This ETDM is joined to the ETDM computed for the other children of the root of T. The function includes a third parameter, a number tthat represents the minimum number of coincidences (i.e., threshold) that have to share a node in tree Twith nodes in set Pto include it in the ETDM. The nodes that do not fulfill this condition will be discarded by means of the first condition of the function.
4.3. EXAMPLES 45 Figure 4.5: Eclipse.org website: Before and after extracting the template Figure 4.6: Water.org website: Before and after extracting the template the webpage. It contains a logo, a main menu and two buttons. There are three columns below the header. The left column contains a secondary menu, the central column contains the main content and the right column contains other secondary blocks. We can also find a footer at the bottom of the webpage. The template detection process keeps as template the entire header, the left and the right columns, and finally the footer. It does not mark as template the central column, which contains the main content of the webpage.
46 CHAPTER 4. IMPLEMENTATION
Chapter 5 Empirical evaluation 5.1 Experiments Several experiments were conducted with real, online webpages to provide a measure of the average performance regarding recall, precision and the F1 measure (see, e.g., [10] for a discussion on these metrics). Initially, we wanted to use a public standard collection of benchmarks, but we did not find any public dataset for template detection. In particular, we could not use the standard CleanEval suite [3] of content extraction benchmarks, because it contains a gold standard prepared for content extraction (each part of the webpages is labelled as main-content or non-content), but it is not prepared for template detection. Then, we tried to use the same benchmark set as the authors of other template detection papers. However, due to privacy restrictions, copyright, or unavailability1of the benchmarks we could not use a previous dataset. Therefore, we decided to produce a new suite of benchmarks. We have produced a new publicly accessible dataset, with an automatizable gold standard. It is one of the main contributions of our work. This benchmark suite is explained in detail in Chapter 6. The dataset is composed of a collection of web domains with different layouts and page structures. This allows us to study the performance of the techniques in different contexts (e.g., company websites, news articles, forums, etc.). To measure our technique, we randomly selected an evaluation subset. Table 5.1 summarizes the results of the performed experiments. The first column contains the URLs of the evaluated website domains (the URL of the key page). For each benchmark, column DOM nodes shows the number of nodes of the key page’s DOM tree; column Template shows the number of nodes of the gold standard template; column Retrieved shows the number of nodes that were identified by the tool as the template; column Recall shows 1Some authors answered that their benchmarks were not stored for future use, or that they did not save the gold standard. 47
48 CHAPTER 5. EMPIRICAL EVALUATION the number of correctly retrieved nodes divided by the number of nodes in the gold standard; column Precision shows the number of correctly retrieved nodes divided by the number of retrieved nodes; finally, column F1 shows the F1 metric that is computed as p2˚P˚Rq{pP`Rqbeing Pthe precision and Rthe recall. DOM Template Total Template Recall Precision F1 Benchmark nodes nodes retreived retreived % % % water.org 948 711 665 665 93,53 % 100 % 96,66 % www.jdi.org.za 626 305 305 305 100 % 100 % 100 % stackoverflow.com 6450 447 459 447 100 % 97,39 % 98,68 % www.eclipse.org 256 156 160 152 97,44 % 95,00 % 96,20 % www.history.com 1246 669 579 576 86,10 % 99,48 % 92,31 % www.landcoalition.org 1247 393 433 387 98,47 % 89,38 % 93,70 % es.fifa.com 1324 276 239 234 84,78 % 97,91 % 90,87 % cordis.europa.eu/fp7/ict/fire/ 959 335 327 326 97,01 % 99,39 % 98,19 % clotheshor.se 459 231 225 225 97,40 % 100 % 98,68 % www.emmaclothes.com 1080 374 360 360 96,26 % 100 % 98,09 % www.cleanclothes.org 1335 266 286 264 99,25 % 92,31 % 95,65 % www.mediamarkt.es 805 337 329 329 97,63 % 100 % 98,80 % www.ikea.com/gb/en/ 1545 407 564 406 99,75 % 71,99 % 83,63 % www.swimmingpool.com 607 499 349 349 69,94 % 100 % 82,31 % www.skipallars.cat/en/ 1466 842 828 828 98,34 % 100 % 99,16 % www.tennis.com 1300 624 542 542 86,86 % 100 % 92,97 % www.tennischannel.com 661 303 227 227 74,92 % 100 % 85,66 % www.turfparadise.com 1057 726 815 724 99,72 % 88,83 % 93,96 % riotimesonline.com 2063 879 861 861 97,95 % 100 % 98,97 % www.beaches.com 1928 1306 1171 1171 89,66 % 100 % 94,55 % users.dsic.upv.es/˜jsilva/ 197 163 163 163 100 % 100 % 100 % /wwv2013/index2.html users.dsic.upv.es/˜dinsa/en/ 241 74 89 74 100 % 83,15 % 90,80 % www.engadget.com 1818 768 445 439 57,16 % 98,65 % 72,38 % www.bbc.co.uk/news/ 2991 364 353 353 96,98 % 100 % 98,47 % www.vidaextra.com 2331 1137 992 992 87,25 % 100 % 93,19 % www.ox.ac.uk/staff/ 948 525 533 522 99,43 % 97,94 % 98,68 % clinicaltrials.gov 543 389 392 378 97,17 % 96,43 % 96,80 % en.citizendium.org 1083 414 447 414 100 % 92,62 % 96,17 % www.filmaffinity.com/es/ 1333 351 355 351 100 % 98,87 % 99,43 % edition.cnn.com 3934 192 174 174 90,63 % 100 % 95,08 % www.lashorasperdidas.com 1822 553 536 536 96,93 % 100 % 98,44 % labakeryshop.com 1368 218 169 159 72,94 % 94,08 % 82,17 % www.felicity.co.uk 300 232 232 232 100 % 100 % 100 % www.thelawyer.com 3349 1293 1443 1213 93,81 % 84,06 % 88,67 % www.us-nails.com 249 171 227 171 100 % 75,33 % 85,93 % www.informatik.uni-trier.de 3085 64 56 56 87,50 % 100 % 93,33 % www.wayfair.co.uk 2671 660 665 640 96,97 % 97,71 % 97,34 % catalog.atsfurniture.com 340 301 304 301 100 % 99,01 % 99,50 % www.glassesusa.com 1794 1506 1498 1498 99,47 % 100 % 99,73 % www.mysmokingshop.co.uk 575 407 421 407 100 % 96,67 % 98,31 % Average 1458 497 480 461 93,53 % 96,15 % 94,34 % Table 5.1: Results of the experimental evaluation Experiments reveal a very high average precision and recall: more than 93% in both cases. This is the highest recall and precision that we have seen in a tool for template detection. We have observed that other techniques obtain good values of F1 in certain webpages, but their average precision,
5.2. OPTIMIZATIONS AND TUNNING 49 recall and F1 are significantly lower than ours. For instance, in [2] the average precision is always lower than 91% in template removal. In [21], the authors get an F1 higher than 95% in some cases, but their average F1 is significantly lower than ours. Other techniques related to content extraction like [10] and [22] get F1 values between 80% and 94% in certain cases Observe that some benchmarks produced a recall of about 70%. These benchmarks are particularly difficult ones that produce the same problem in previous techniques such as [21]. The problem in these benchmarks is that some webpages pointed by the key page’s links do not use exactly the same template than the key page (i.e., some webpages feature the menu, or the necessary links in some form, but they do not implement the whole template). Therefore, the intersection with these webpages produces one with less items, that is, a webpage with a lower recall. The interested reader is referred to the code of these webpages and their gold standard that are publicly available in the benchmarks repository. 5.2 Optimizations and tunning In our theoretical formalization we presented our technique in an abstract way. Some definitions such as hyperlink distance, DOM distance, and relevance, reveal features of a website that must be considered when extracting templates. Other features, however, have been left as parameters of our algorithms. For instance, Algorithm 2 can compute a CS of any specified size; and the voting system of Algorithm 3 needs to know how many votes are needed to consider a DOM node as part of the template. In this section we discuss how to know the impact of these parameters, and we give concrete values to our algorithms based on empirical evaluation. 5.2.1 Optimization experiments In order to determine the best parameters, we created a set of 20 training benchmarks. Then, we prepared a set of experiments that helped us to determine all the variables we wanted to test. At the end we did 478720 experiments repeating the set of 20 training benchmarks with different parameter combinations. Each experiment took 4.5 seconds on average. Therefore, the execution time for all the experiments was about 600 hours. The execution of all the experiments produced the following average values: 1. Average precission = 63,39 2. Average recall = 94.91 3. Average F1 = 67,15
50 CHAPTER 5. EMPIRICAL EVALUATION But, the optimal combination of values obtained is: 1. Optimal precission = 93,53 2. Optimal recall = 96,15 3. Optimal F1 = 94,34 The following sections present the optimal values found for each parameter. 5.2.2 Determining n and t parameters Algorithm 2 computes a n-CS in a website. As we previously explained, there are several combinations of webpages that form a CS. One could think that the more links the key page has, the better; so we could even think in calculating the maximal CS. Nevertheless, this is not a good idea. Firstly, because computing the maximal CS has an exponential cost. And secondly, because experiments reveal that increasing the size of the CS does not necessarily imply a better precision or recall. As we introduced in section 3.1, given a n-CS, we call tto the threshold used to decide in how many webpages must be a node to be considered part of the template. We evaluated a collection of webpages with different sizes for the CS, from size 1 to size 8, and with all possible values of t. We determined that the best value for n is 8 and the best value for t is 4. But we have considered that the best values are not the optimal values because the time needed to compute an 8-CS with t“4is excessively high. Therefore, we determined that the optimal value for n is 3 and the optimal value for t is 2. There are better combinations for n and t, but they increase the time to compute the ETDM. In certain cases, increasing the n parameter in one unit almost doubles the time needed to compute the ETDM. Therefore we consider n“3and t“2optimal values because the computing time with these values is reasonably acceptable. As a result, all our experiments have been done using these values for nand t. tzn 1 2 2 4 5 6 7 8 175,90 % 89,22 % 88,97 % 86,82 % 86,84 % 86,28 % 86,08 % 86,06% 288,16 % 92,35 % 92,11 % 92,08 % 93,82 % 93,31 % 93,15% 388,26 % 92,81 % 92,81 % 92,54 % 92,24 % 94,11% 487,04 % 92,84 % 92,15 % 92,52 % 94,63% 586,60 % 91,87 % 92,28 % 92,68% 686,46 % 90,86 % 91,73% 783,58 % 90,49% 883,52% BEST 75,90% 89,22% 92,35% 92,81% 92,84% 93,82% 93,31% 94,63% Table 5.2: Determining values nand t Figure 5.2 shows the F1 values obtained with different combinations of values for nand t. We have chosen n“3and t“2as the best combination
5.2. OPTIMIZATIONS AND TUNNING 51 considering F1 and computation time; but there are several better combinations like n“4and t“3,n“5and t“4, etc. if we only consider F1. Our choice produces a value for F1 very similar to other combinations but a significantly better computation time. We observed that increasing nand tmakes the time to compute the ETDM sensibly higher. Therefore, we repeated the experiments to measure the time needed to compute all the possible combinations. tzn 1 2 3 4 5 6 7 8 13 s. 6,1 s. 10,7 s. 13,1 s. 15,91 s. 21,17 s. 23,08 s. 22,65 s. 24,9 s. 10,4 s. 12,7 s. 15,44 s. 20,76 s. 22,4 s. 22,65 s. 36,91 s. 12,7 s. 15,45 s. 20,68 s. 22,42 s. 22,71 s. 48,8 s. 15,41 s. 20,72 s. 22,51 s. 22,77 s. 510,62 s. 20,7 s. 22,39 s. 22,76 s. 613,34 s. 22,49 s. 22,8 s. 715,03 s. 22,74 s. 815,97 s. Table 5.3: Determining values nand t Figure 5.3 presents the average time needed to compute the ETDM in seconds for different nand tvalues. Our selected combination (n“3and t“2) has a computation time of 10.4 seconds, and the best combination (n“8and t“4) has a computation time of 22.77 seconds. However, the best combination only gets an F1 value 2.3% higher than our selected combination. This is why we choose n“3and t“2in our implementation: it is almost as good as the best combination, but it needs less than half of the computation time. 5.2.3 Making precise the comparison of DOM nodes Algorithm 3 needs to compare DOM nodes to define a ETDM. As we introduced in section 3.2, deciding whether two DOM nodes of two different webpages are the same node is an important problem. From the implementation point of view, it is a difficult problem because some parts of the DOM tree can be missing, or changed. There can exist new DOM nodes that change the relative position between the original nodes, etc. In section 3.2 we explained that in order to compare two DOM nodes we consider the following information: •The HTML tag of the node •Node identifier •Class name of the node •Position of the node in the DOM tree
52 CHAPTER 5. EMPIRICAL EVALUATION •Attributes of the node •Children of the node in the DOM tree We also assigned a weighting system based on the following DOM node components: Classes, Position, Attributes and Children. At first, the weighting was 40% for classes, 40% for position, 10% for attributes and 10% for children. We experimented changing the weights and finally we found that the best results happen when the weights of the position and attributes were 20%. The weight of the children is only 10% relevant. As a result, we observed that the classes is the most important aspect when comparing two nodes, 50%. This optimization increased the F1 value in a 2%. The node comparison added another need to the implementation. When comparing the classes of two nodes, we found the need to determine what happened when the nodes had no classes. When the classes attribute was not defined, the node could not be reliably compared with other nodes without classes attribute. We needed to add a penalization when comparing two nodes with no classes, because we cannot be sure if two nodes without classes are the same or not. This penalization is defined as a constant called not- ClassesProbability. Our experiments demonstrate that a value higher than 0,75 and lower than 1 produced the best results. Likewise, we had to define a similar constant to determine what happened when two nodes had no attributes, which is called notAttributesProbability, and another one to determine when two nodes had no children, called notChildrenProbability. Experiments revealed that the best values for these constants are 0,25 for notAttributesProbability and 1 for notChildrenProbability. We also defined a boolean variable called activatePosition. When this variable is true, it checks the order of the nodes when they match with other nodes, e.g., if the algorithm resolves that two nodes A and B are the same, another node prior to A cannot match to a node after B. This is used to guarantee the order of the nodes when comparing nodes to find the template, if the order of the nodes is not correct, we will be unable to find the correct template. Experiments revealed that this optimization provides an improvement about 1% to the F1 value. The addition of a constant called similarityThreshold has been an important optimization. This constant establishes the nodes mapping threshold value that was introduced in Definition ??. Two nodes cannot be the same if their calculated probability is lower than the probability threshold. If this constant is not used, the mapping between two nodes will be always produced, even if their are not probably the same node because their probability is low. Therefore, this constant prevents the mapping of two nodes with low probability. Our experiments reveal that with the introduction of this constant, the F1 value has been improved about a 2,5%.
5.2. OPTIMIZATIONS AND TUNNING 53 5.2.4 Domain boundaries Another important optimization is related to the domain boundaries of the websites analyzed. It is possible that several webpages of different domains are mutually linked. Sometimes this is even usual between the main webpages of different companies in an alliance. They all point to the others, e.g., with a set of logos. Nevertheless, the templates of the companies are often different. In fact, in our experiments, we did not find a shared template between different domains. Therefore, for efficiency reasons, external domains are omitted when computing the CS. In our implementation, the CS represents a set of intra-domain linked webpages (usually by a common menu). 5.2.5 Implementation and experiments download Our implementation and all the experimentation is public. All the information related to the experiments, the source code of the benchmarks, the source code of the tool and other material can be found at: http://www.dsic.upv.es/~jsilva/retrieval/templates/
54 CHAPTER 5. EMPIRICAL EVALUATION
6.2. THE TECO BENCHMARK SUITE 61 Id VL TT PT DT Notes (peculiarities) 1 9 0 9 0 All pages add a block in the footer that does not belong to the key page. 2 10 10 0 0 3 4 4 0 0 4 8 8 0 0 5 12 5 6 1 The website uses two different footers (hence, two templates). Therefore, some pages only implement partially the template of the key page. 6 26 7 19 0 All pages share the same header and footer but there are pages with a different layout. 7 8 0 8 0 Some pages use two columns while other use three. All of them are different to the key page. 8 24 5 19 0 Some pages use two columns while other use three. All of them are different to the key page. 9 6 6 0 0 10 6 6 0 0 11 6 6 0 0 12 16 16 0 0 13 10 0 10 0 The submenu appears inside the main content. 14 16 16 0 0 The main content of the key page uses a layout that is different to the other pages. 15 42 42 0 0 16 13 13 0 0 17 29 0 29 0 All pages use more blocks than the key page. For instance, advertisement blocks. 18 74 74 0 0 19 23 23 0 0 20 77 77 0 0 21 12 12 0 0 22 5 5 0 0 23 65 65 0 0 24 5 0 5 0 There are several different templates (but they are very similar). 25 7 7 0 0 26 7 7 0 0 All pages share the same template. There is a breadcrumb inside the main content. 27 36 36 0 0 28 32 32 0 0 29 32 32 0 0 30 13 13 0 0 All pages share the same template, but the header is a bit different between the key page and the other pages. 31 11 11 0 0 All pages share the same template, but the header is a bit different between the key page and the other pages. 32 l4 4 0 0 All pages share the same template. There is a big amount of javascript. 33 6 6 0 0 34 69 69 0 0 35 10 10 0 0 36 6 5 0 1 One page linked from the main menu uses a different template. 37 377 377 0 0 38 6 6 0 0 39 86 86 0 0 40 35 35 0 0 Table 6.3: Template data of the benchmarks
62 CHAPTER 6. BENCHMARK SUITE 6.2.3 Guidelines for using the suite Downloading and configuring the suite TECO is freely distributed and can be downloaded from the URL: http://www.dsic.upv.es/„jsilva/retrieval/teco After downloading the suite, a directory that contains 40 folders, one for each website, is created. Table 6.4 shows the path to the key page of each benchmark. Rules for using the suite and report All researchers and developers that use TECO must follow two basic principles: 1. They must publish their results so that they are publicly available. 2. They must provide enough information so that anyone can easily duplicate their experiments.
6.2. THE TECO BENCHMARK SUITE 63 Id Path to the key page 1 pages/water.org/index.html 2 pages/www.jdi.org.za/index.html 3 pages/stackoverflow.com/index.html 4 pages/www.eclipse.org/index.html 5 pages/www.history.com/index.html 6 pages/www.landcoalition.org/index.html 7 pages/es.fifa.com/index.html 8 pages/cordis.europa.eu/fp7/ict/fire.html 9 pages/clotheshor.se/index.html 10 pages/www.emmaclothes.com/index.html 11 pages/www.cleanclothes.org/index.html 12 pages/www.mediamarkt.es/index.html 13 pages/www.ikea.com/gb/en.html 14 pages/www.swimmingpool.com/index.html 15 pages/www.skipallars.cat/en.html 16 pages/www.tennis.com/index.html 17 pages/www.tennischannel.com/index.html 18 pages/www.turfparadise.com/index.html 19 pages/riotimesonline.com/index.html 20 pages/www.beaches.com/index.html 21 pages/users.dsic.upv.es/„jsilva/wwv2013/index2.html 22 pages/users.dsic.upv.es/„dinsa/en/index.html 23 pages/www.engadget.com/index.html 24 pages/www.bbc.co.uk/news/index.html 25 pages/www.vidaextra.com/index.html 26 pages/www.ox.ac.uk/staff/index.html 27 pages/clinicaltrials.gov/ct2/search/index/index.html 28 pages/en.citizendium.org/index.html 29 pages/www.filmaffinity.com/es/main.html 30 pages/edition.cnn.com/index.html 31 pages/www.lashorasperdidas.com/index.html 32 pages/labakeryshop.com/index.html 33 pages/www.felicity.co.uk/index.html 34 pages/www.thelawyer.com/index.html 35 pages/www.us-nails.com/Unternehmen/Ueber_Uns/ueber_uns_l2-dat=5860687c.php.html 36 pages/www.informatik.uni-trier.de/„ley/pers/hd/s/Silva_Josep.html 37 pages/www.wayfair.co.uk/index.html 38 pages/catalog.atsfurniture.com/index.html 39 pages/www.glassesusa.com/index.html 40 pages/www.mysmokingshop.co.uk/index2.html Table 6.4: Path to the key page of each benchmark
64 CHAPTER 6. BENCHMARK SUITE
Chapter 7 Conclusions Web templates are a very useful tool for website developers. By automatically inserting content into templates, website developers and content providers of large web portals achieve high levels of productivity. Not only is the productivity improved, but also the usability. Website developers using web templates produce webpages that are more usable thanks to their uniformity. This work presents a new technique for template detection. The technique provides a great benefit for website developers because they can automatically extract a clean HTML template of any webpage. This feature is particularly interesting in order to reuse components of other webpages. Moreover, the technique can be used by other systems and tools such as indexers or wrappers as a preliminary stage. Extracting the template allows them to identify the structure of the webpage and the topology of the website by analyzing the navigational information of the template. In addition, the template is useful to identify menus, pagelets, repeated advertisement panels, and what is particularly important, the main content. The technique is also beneficial for indexers and crawlers in another way because they can easily detach the content from the template. As a result, they can save resources and optimize the storage space by analyzing the web templates only once. Our technique uses the initial webpage hyperlinks for identifying a set of webpages that share the same template with a high probability. Then, it uses the DOM structure of the webpages in that set to identify the blocks that are common to the major part of them. These blocks together form the template. To the best of our knowledge, the idea of using the webpage hyperlinks to locate the template is new, and it allows us to quickly find a set of webpages from which we can extract the template. This is especially interesting for performance, because loading webpages to be analyzed is expensive, and this part of the process is minimized in our technique. Our implementation and experiments have shown the usefulness of the technique. 65
66 CHAPTER 7. CONCLUSIONS This approach could be also used for content extraction. Detecting and removing the template of a webpage is very helpful in order to detect the main content. Firstly, the main content must be formed by DOM nodes that do not belong to the template, so removing the template of a website may result in the main content or the main content plus any other information. Secondly, the main content is usually inside one of the pagelets that are more centered and visible, and with a higher concentration of text. To sum up, this template detection technique is not only helpful to extract the template of a website, it can also provide significant improvements to content extraction algorithms by removing the template.
Chapter 8 Future work •Reduction of the number of webpages loaded: We plan to investigate a strategy to further reduce the amount of webpages loaded with our technique. The idea is to directly identify the menu in the key page by measuring the density of links in its DOM tree. The menu has probably one of the higher densities of links in a webpage. Therefore, our technique could benefit from measuring the links–DOM nodes ratio to directly find the menu in the key page, and thus, a complete subdigraph in the website topology. •Integration with content extraction: The template detection algorithm can be integrated with a content extraction algorithm, like [12], in order to improve its performance. Using a content extraction algorithm before detecting the template makes the template detection process more efficient. The process has to use the content extraction algorithm to remove the main content, thus webpages will have less nodes and the process of computing the ETDM will be more efficient because most of those nodes will belong to the template with a high probability. Our technique can also provide a benefit to content extraction algorithms like [12]. Removing the template reduces the amount of DOM information that a content extraction algorithm has to analyze. This could result in more efficient content extraction algorithms because they should analyze less amount of data. •Improved DOM node comparison: This technique needs to compare DOM nodes in order to define a ETDM. As we introduced in section 3.2, the main problem is to decide if two nodes from two different webpages are the same or not. This problem appears because two different webpages surely have two different DOM trees, even if they have share the same template. There can also be new DOM nodes that change the relative position between the original nodes, etc. We plan 67
68 CHAPTER 8. FUTURE WORK to improve the algorithm with the comparison of DOM subtrees. If a template is present in two or more webpages, their DOM trees will share similar parts. Those parts of their DOM trees could be in different positions, but if they really share the template, they will share some DOM subtrees. •Atypical template detection: Sometimes one of the webpages included in the n-CS does not follow the template at all. In this case, the algorithm needs a mechanism to detect that webpages with atypical template, so they can be replaced by another webpage. This feature could be implemented in the algorithm that computes the ETDM. If there are several nodes that match with high probability in all webpages but one (always the same), this webpage will probably implement a different template.
Chapter 9 Contributions During the thesis writing process, the following articles have been published: 9.1 International publications 1. Julian Alarte, David Insa, Josep Silva, and Salvador Tamarit. Template Extraction Based on Menu Information. In Josep Silva and Antonio Ravara, editors, Proceedings of the 9th International Workshop on Automated Specification and Verification of Web Systems (WWV 13), page Article 5, 2013. This paper provides an approach to the template etraction process based on the information provided by the menu of the webpage. The links analyzed to buid the complete subdigraph are in the main menu, so all the webpages that belong to the complete subdigraph share the same menu. Then, an ETDM is obtained with the pages of the CS. Once the ETDM is obtained, the nodes that belong to it are the template nodes. 2. Julian Alarte, David Insa, Josep Silva, and Salvador Tamarit. Automatic Detection of Webpages Candidates for Site-Level Web Template Extraction. In Josep Silva and Antonio Ravara, editors, Invited Conference of the 10th International Workshop on Automated Specification and Verification of Web Systems (WWV 14), page Article 13, 2014. This publication is an approach to improve the method of the building a complete subdigraph from a website. It is based on the hyperlink analysis of a webpage. 3. Julián Alarte, David Insa, Josep Silva, and Salvador Tamarit. Automatic Detection of Webpages that Share the Same web Template. In Maurice H. ter Beek and António Ravara, editors, Proceedings 10th International Workshop on Automated Specification and Verification 69
70 CHAPTER 9. CONTRIBUTIONS of Web Systems, Vienna, Austria, July 18, 2014, volume 163 of Electronic Proceedings in Theoretical Computer Science, pages 2–15. Open Publishing Association, 2014. The article presents a new way of computing a complete subdigraph of a website based on the analysis of the hyperlinks in the key webpage. The algorithm uses concepts like hyperlink distance,DOM distance,link relevance and DOM relevance to ensure that the CS really represents the website template. 9.2 National publications 1. Julián Alarte, David Insa, Josep Silva, and Salvador Tamarit. Site- Level Template Extraction Based on Hyperlink Analysis. Proceedings of the 14th Spanish Workshop on Programming Languages (PROLE’14), sep 2014. to appear in proceedings of PROLE 2014. This publication uses two of the main ideas presented in this thesis, the building of a complete subdigraph based on hyperlink analysis, and then, the compute of an ETDM using the CS. However, the ETDM in an simpler way.