Changes between Initial Version and Version 1 of Justext/Algorithm


Ignore:
Timestamp:
03/24/15 16:08:48 (10 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Justext/Algorithm

    v1 v1  
     1== Introduction ==
     2The algorithm uses a simple way of segmentation. The contents of some HTML tags are (by default) visually formatted as blocks by Web browsers. The idea is to form textual blocks by splitting the HTML page on these tags. The full list of the used block-level tags includes: BLOCKQUOTE, CAPTION, CENTER, COL, COLGROUP, DD, DIV, DL, DT, FIELDSET, FORM, H1, H2, H3, H4, H5, H6, LEGEND, LI, OPTGROUP, OPTION, P, PRE, TABLE, TD, TEXTAREA, TFOOT, TH, THEAD, TR, UL. A sequence of two or more BR tags also separates blocks.
     3
     4Though some of such blocks may contain a mixture of good and boilerplate content, this is fairly rare. Most blocks are homogeneous in this respect.
     5
     6Several observations can be made about such blocks:
     7
     81. Short blocks which contain a link are almost always boilerplate.
     92. Any blocks which contain many links are almost always boilerplate.
     103. Long blocks which contain grammatical text are almost always good whereas all other long block are almost always boilerplate.
     114. Both good (main content) and boilerplate blocks tend to create clusters, i.e. a boilerplate block is usually surrounded by other boilerplate blocks and vice versa.
     12
     13Deciding whether a text is grammatical or not may be tricky, but a simple heuristic can be used based on the volume of function words (stop words). While a grammatical text will typically contain a certain proportion of function words, few function words will be present in boilerplate content such as lists and enumerations.
     14
     15The key idea of the algorithm is that long blocks and some short blocks can be classified with very high confidence. All the other short blocks can then be classified by looking at the surrounding blocks.
     16
     17== Preprocessing ==
     18In the preprocessing stage, the contents of <header>, <style> and <script> tags are removed. The contents of <select> tags are immediately labeled as bad (boilerplate). The same applies to blocks containing a copyright symbol (©).
     19
     20== Context-free classification ==
     21After the segmentation and preprocessing, context-free classification is executed which assigns each block to one of four classes:
     22
     23* bad -- boilerplate blocks
     24* good -- main content blocks
     25* short -- too short to make a reliable decision about the class
     26* near-good -- somewhere in-between short and good
     27
     28The classification is done by the following algorithm:
     29
     30{{{
     31if link_density > MAX_LINK_DENSITY:
     32    return 'bad'
     33
     34# short blocks
     35if length < LENGTH_LOW:
     36    if link_density > 0:
     37        return 'bad'
     38    else:
     39        return 'short'
     40
     41# medium and long blocks
     42if stopwords_density > STOPWORDS_HIGH:
     43    if length > LENGTH_HIGH:
     44        return 'good'
     45    else:
     46        return 'near-good'
     47if stopwords_density > STOPWORDS_LOW:
     48    return 'near-good'
     49else:
     50    return 'bad'
     51}}}
     52
     53The length is the number of characters in the block. The link density is defined as the proportion of characters inside <a> tags. The stop words density is the proportion of stop list words (the text is tokenized into "words" by splitting at spaces).
     54
     55The algorithm takes two integers LENGHT_LOW and LENGTH_HIGH and three floating point numbers MAX_LINK_DENSITY, STOPWORDS_LOW and STOPWORDS_HIGH as parameters. The former two set the thresholds for dividing the blocks by length into short, medium-size and long. The latter two divide the blocks by the stop words density into low, medium and high. The default settings are:
     56
     57* MAX_LINK_DENSITY = 0.2
     58* LENGTH_LOW = 70
     59* LENGTH_HIGH = 200
     60* STOPWORDS_LOW = 0.30
     61* STOPWORDS_HIGH = 0.32
     62
     63These values give good results with respect to creating textual resources for corpora. They have been determined by performing a number of experiments.
     64
     65The assignment of classes for the medium and long blocks is summarised in the following table:
     66
     67||= Block size (word count) =||= stopwords density =||= class =||
     68|| medium-size || low || bad ||
     69|| long || low || bad ||
     70|| medium-size || medium || near-good ||
     71|| long || medium || near-good ||
     72|| medium-size || high || near-good ||
     73|| long || high || good ||
     74
     75
     76== Context-sensitive classification ==
     77The goal of the context-sensitive part of the algorithm is to re-classify the short and near-good blocks either as good or bad based on the classes of the surrounding blocks. The blocks already classified as good or bad serve as base stones in this stage. Their classification is considered reliable and is never changed.
     78
     79The pre-classified blocks can be viewed as sequences of short and near-good blocks delimited with good and bad blocks. Each such sequence can be surrounded by two good blocks, two bad blocks or by a good block at one side and a bad block at the other. The former two cases are handled easily. All blocks in the sequence are classified as good or bad respectively. In the latter case, a near-good block closest to the bad block serves as a delimiter of the good and bad area. All blocks between the bad block and the near-good block are classified as bad. All the others are classified as good. If all the blocks in the sequence are short (there is no near-good block) they are all classified as bad. This is illustrated on the following example:
     80
     81
     82
     83The idea behind the context-sensitive classification is that boilerplate blocks are typically surrounded by other boilerplate blocks and vice versa. The near-good blocks usually contain useful corpus data if they occur close to good blocks. The short blocks are typically only useful if they are surrounded by good blocks from both sides. They may, for instance, be a part of a dialogue where each utterance is formatted as a single block. While discarding them may not constitute a loss of significant amount of data, losing the context for the remaining nearby blocks could be a problem.
     84
     85In the description of the context-sensitive classification, one special case has been intentionally omitted in order to keep it reasonably simple. A sequence of short and near-good blocks may as well occur at the beginning or at the end of the document. This case is handled as if the edges of the documents were bad blocks as the main content is typically located in the middle of the document and the boilerplate near the borders.
     86
     87== Headings ==
     88Header blocks (those enclosed in <h1>, <h2>, <h3>, etc tags) are treated in a special way by jusText unless the NO_HEADINGS option is used. The aim is to preserve headings for the good texts.
     89
     90The algorithm adds two stages of processing for the header blocks. The first stage (preprocessing) is executed after context-free classification and before context-sensitive classification. The second stage (postprocessing) is performed after the context-sensitive classification:
     91
     92* context-free classification
     93* preprocessing of header blocks
     94* context-sensitive classification
     95* postprocessing of header blocks
     96
     97The preprocessing looks for short header blocks which precede good blocks and at the same time there is no more than MAX_HEADING_DISTANCE characters between the header block and the good block. The context-free class of such header blocks is changed from short to near-good. The purpose of this is to preserve short blocks between the heading and the good text which might otherwise be removed (classified as bad) by the context-sensitive classification.
     98
     99The postprocessing again looks for header blocks which precede good blocks and are no further than MAX_HEADING_DISTANCE away. This time, the matched headers are classified as good if their context-free class was other than bad. In other words, the bad headings remain bad, but some short and near-good headings can be classified as good if they precede good blocks, even though they would normally be classified as bad by the context-sensitive classification (e.g. they are surrounded by bad blocks). This stage preserves the "non-bad" headings of good blocks.
     100
     101Note that the postprocessing is not iterative, i.e. the header blocks re-classified as good do not affect the classification of any other preceding header blocks.