# A Hierarchical Orthographic Similarity Measure for Interconnected Texts Represented by Graphs
## 4 Representing a Textual Corpus as a Graph
### Graph Representation of a Textual Corpus
Top-level elements, on the other hand, are always represented by distinct nodes, each assigned a unique identifier, such that each text in the graph is uniquely identifiable._  
Starting from a set of texts \(T\), the graph-based representation for this corpus, adhering to Definition 3, can be constructed using Algorithm 1. The algorithm starts from an empty fuzzy graph and adds each text document individually to the graph. First, a preprocessing step allows the texts to be altered or simplified before they are inserted into the graph. Next, for each of these texts, a node is created with the label of the highest-level element (\(l_{|L|-1}\)). This node serves as the root node for a specific text and is also assigned a unique identifier. ```
0: A set of text documents \(T\) and a hierarchical list of units \(L=[l_{0},l_{1},\ldots,l_{n}]\)
0: A fuzzy graph \(\tilde{G}\big{(}N,\tilde{E},\rho,\lambda_{N},\lambda_{E},\sigma\big{)}\) representing the documents in \(T\)
1: Create empty fuzzy graph \(\tilde{G}\big{(}N,\tilde{E},\rho,\lambda_{N},\lambda_{E},\sigma\big{)}\)\(\triangleright\)\(\tilde{G}\) is a global object
2:for all\(t\in T\)do
3:\(t\leftarrow\textsc{Preprocess}(t)\)
4:\(i\leftarrow|L|-1\)
5: Create node \(n\)
6:\(\sigma(n,\mathrm{id})\leftarrow\textsc{UniqueID}()\)
7:\(\lambda_{N}(n)\leftarrow\{l_{i}\}\)
8: ComputeChildNodes\((t,i-1,n)\)
9:\(N\gets N\cup\{n\}\)
10:endfor
11:return\(\tilde{G}\big{(}N,\tilde{E},\rho,\lambda_{N},\lambda_{E},\sigma\big{)}\)
```  
**Algorithm 1** Graph-based text model construction algorithm. From this root node, the lower levels of the text document are computed in a recursive manner by means of Algorithm 2. For each intermediate level of the hierarchical decomposition \(L\), the text element is split up into smaller elements. The approach for splitting text elements into these smaller components depends on the current unit of discourse \(l_{i}\) and can be decided upon during implementation. For example, in the case of words, the string can be split based on white spaces within the text. For tokens or sentences, on the other hand, tokenisation [45] or sentence segmentation [46] methods can be used. Next, for each of these smaller components \(s_{j}\), it is checked whether or not a node with an identical label representing the exact same textual content as \(s_{j}\) already exists. Should this be the case, the already existing node is linked to the parent node, and no further operations or recursive steps are required. Conversely, in the absence of such node, a new node with the corresponding label is created. In case the recursion has reached the lowest label (i.e., when \(i=0\)), the node is associated with the actual textual content, and the recursion is finished. In all other cases, the ComputeChildNodes procedure is recursively called to compute the lower-level text elements at level \(i-1\). Lastly, the newly created node is connected to its parent node and is added to the graph. When the recursion, which is started in Algorithm 1, is completed, the root node of a text document is also added to the graph. This entire process is repeated until all text documents are incorporated into the graph. The resulting graph is then returned at the end of the algorithm. In order to illustrate the graph model from Definition 3 and the construction procedure in Algorithm 1, a simple example of a corpus of two small texts is given in Example 1. **Example 1**. : _Consider a set of two slightly different texts_  
\(T=\{\)\"What is this? A **first** text to **analyse**.\",\"What is this? A **second** text to **analyse**.\"\(\}\)_  
_and a list of textual units \(L=[\texttt{Word},\texttt{Sentence},\texttt{Text}]\), where elements with the label Text represent a text as a whole. Executing Algorithm 1 on this example results in the graph-based text representation displayed in Figure 1. In this example, the texts are segmented in sentences and, subsequently, the sentences are split into words based on white spaces.