# Innovative Application of Blockchain Technology for Digital Recipe Copyright Protection
## 4 Text Similarity Detection
### Improved SimHash Algorithm  
The current SimHash has some limitations in terms of semantics and word importance when dealing with natural language processing problems, so we propose an improved P-SimHash algorithm (as shown in Figure 5), the goal of which is to more accurately capture semantic similarities between texts. This improved SimHash algorithm combines dependency parsing and the PageRank algorithm for weight computation based on the traditional SimHash algorithm. In the preprocessing stage, we perform lexical segmentation on the text and lexical lemmatization with WordNetLemmatizer [28] for English text in order to transform words with different morphologies into their original forms (The Chinese dataset does not need to use lemmatization). Then, we adopt the dependency parsing technique to construct a co-occurrence network based on the dependencies between words. In this network, nodes represent words and edges represent dependencies between words. Sentences are parsed using spaCy [29], and directed graphs are constructed based on word dependencies. Next, we score each node in the co-occurrence network using the PageRank algorithm. The PageRank score represents the importance of the word in the text, i.e., its centrality in the dependency network. We also use the TF-IDF method to calculate the weights of the words, and the TF-IDF values reflect the uniqueness of the words. Our improvement is to combine the PageRank score and TF-IDF weights to generate a composite weight. This composite weight considers both the importance and uniqueness of the word. We replace the frequency count in the traditional SimHash algorithm with the improved combined weight to calculate the SimHash value. Unlike the conventional SimHash algorithm, our SimHash value is a weighted hash code whose weights reflect the importance and uniqueness of words. To solve the relationship between semantics, we introduce a pretrained word model [29] in natural processing that learns the contextual information of words in a large-scale corpus and maps each subword to a fixed-size vector space. The subword contains semantic and syntactic relations of common contexts, which enables us to compute text similarity much faster. Common pretrained models include Word2 Vec [30], GloVe [31], BERT [32], etc. Each sentence is the average of the corresponding word vectors of all the words. Then, this representation is used to compute the cosine similarity of the two sentences. Both cosine similarity and Hamming distance are key measures of similarity between texts. Among them, cosine similarity [33] quantifies the angle between two text vectors in a multidimensional space, which captures the semantic similarity of the texts. Hamming distance [34] measures the structural differences of the texts by calculating the number of different characters in the corresponding positions between two equal-length strings. To fully utilize the respective advantages of these two metrics, we input them as features into a support vector machine (SVM) [35] model for binary classification tasks, as described in Algorithm 3. \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Iteration** & **PR(The1)** & **PR(Cat)** & **PR(Sitting)** & **PR(On)** & **PR(Mat)** & **PR(The2)** \\ \hline
0 & 0.0250 & 0.0250 & 0.0250 & 0.0250 & 0.0250 & 0.0250 \\
1 & 0.0250 & 0.0569 & 0.0975 & 0.0975 & 0.0569 & 0.0250 \\
2 & 0.0250 & 0.0704 & 0.1263 & 0.1263 & 0.0704 & 0.0250 \\
3 & 0.0250 & 0.0801 & 0.1427 & 0.1427 & 0.0801 & 0.0250 \\
4 & 0.0250 & 0.0859 & 0.1509 & 0.1509 & 0.0859 & 0.0250 \\
5 & 0.0250 & 0.0895 & 0.1555 & 0.1555 & 0.0895 & 0.0250 \\
6 & 0.0250 & 0.0919 & 0.1581 & 0.1581 & 0.0919 & 0.0250 \\
7 & 0.0250 & 0.0934 & 0.1597 & 0.1597 & 0.0934 & 0.0250 \\
8 & 0.0250 & 0.0944 & 0.1607 & 0.1607 & 0.0944 & 0.0250 \\
9 & 0.0250 & 0.0951 & 0.1612 & 0.1612 & 0.0951 & 0.0250 \\
10 & 0.0250 & 0.0955 & 0.1615 & 0.1615 & 0.0955 & 0.0250 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Iterative calculation of PageRank scores.