A computer implemented method of hierarchically segmenting a sequence of elements associated with a digital version of a document for layout analysis comprising: a) obtaining a sequence of elements representing the document, each element comprising one of a page, a line, a block, a word, or a column; b) defining a set of named features associated with each element of the sequence of elements, each named feature defined by a feature value type; c) computing a set of feature values associated with the set of named features for each element of the sequence, each feature value comprising a value corresponding to a named feature; d) generating a set of n-grams from the sequence of elements, an n-gram including an ordered sequence of n features provided by a sequence of n named elements; e) electing sequential n-grams from the set of n-grams, the sequential n-grams defined as similar contiguous n-grams; f) selecting the most frequent sequential n-gram from the elected sequential n-grams; g1) matching the selected most frequent sequential n-gram against the sequence of elements to determine all sub-sequences of n contiguous elements which are matched by the selected n-gram, wherein the selected n-gram matches a sub-sequence if each ith feature of the n-gram is included in the set of features of the ith element of the sub-sequence; g2) enriching the determined sub-sequences, wherein enriching comprising generating n-grams for each sub-sequence; and g3) generating a new sequence of elements by replacing each sub-sequence of contiguous matched elements with a respective new node, the new node comprising the selected n-gram, and associating the matched elements of the sequence of elements as children of the respective new node. a) obtaining a sequence of elements representing the document, each element comprising one of a page, a line, a block, a word, or a column; b) defining a set of named features associated with each element of the sequence of elements, each named feature defined by a feature value type; c) computing a set of feature values associated with the set of named features for each element of the sequence, each feature value comprising a value corresponding to a named feature; d) generating a set of n-grams from the sequence of elements, an n-gram including an ordered sequence of n features provided by a sequence of n named elements; e) electing sequential n-grams from the set of n-grams, the sequential n-grams defined as similar contiguous n-grams; f) selecting the most frequent sequential n-gram from the elected sequential n-grams; g1) matching the selected most frequent sequential n-gram against the sequence of elements to determine all sub-sequences of n contiguous elements which are matched by the selected n-gram, wherein the selected n-gram matches a sub-sequence if each ith feature of the n-gram is included in the set of features of the ith element of the sub-sequence; g2) enriching the determined sub-sequences, wherein enriching comprising generating n-grams for each sub-sequence; and g3) generating a new sequence of elements by replacing each sub-sequence of contiguous matched elements with a respective new node, the new node comprising the selected n-gram, and associating the matched elements of the sequence of elements as children of the respective new node.