# E-SAWM: A Semantic Analysis-Based ODF Watermarking Algorithm for Edge Cloud Scenarios
## 3 Model and Algorithm
### Dynamic Watermarking Algorithm for OFD
#### 3.2.2 OFD Watermarking Algorithm Based on Semantic Analysis  
Word2 vec is a widely utilized concept across various domains. [PERSON] introduced doc2 vec, an algorithm that enables the representation of sentences or short texts as vectors by considering sentences of different lengths as training samples [21]. In the field of biology, [PERSON] and [PERSON] proposed BioVec for the analysis of biological sequence word vectors [22]. For OFD, the structural documents consist of statements that adhere to specific rules. Here, we use the term \"structural statements\" to refer to the structural information present in OFD files. By treating these statements as natural languages, it becomes possible to generate a context specific to each structural document. Consequently, we devised a sophisticated watermark-embedding algorithm by leveraging semantic analysis. In the case of contextual datasets, the process involves mapping word separation to word vectors distributed in a high-dimensional space using word2 vec. This mapping enables the evaluation of word similarity. When dealing with known contexts, we utilize the word2 vec model to transform them, resulting in \(k\) words that closely resemble the original context words. Subsequently, these words are distributed embedded within the original structural document, serving as watermark carriers. Our approach capitalizes on semantic analysis to develop a highly covert watermark-embedding algorithm. The algorithm follows the flow depicted in Figure 9 and is divided into four main modules:  
1. Semantic analysis model trainingConstruct a pseudo structural library based on the original structural library of OFD. Gather \(n\) instances of context data from structured documents in OFD format. Utilizing these context data, along with the pseudo structure body library, generate \(n^{\prime}\) instances of the context dataset with pseudo structure bodies. These contextual datasets are then trained separately using the CBOW model and the Skip-gram model to develop the semantic analysis model. When conducting semantic analysis on an OFD-structured document, the context is initially extracted. For a context dataset containing a higher frequency of low-frequency structural bodies, the Skip-gram model is preferred for semantic analysis due to its improved performance and efficiency. On the other hand, for the contextual dataset containing a higher frequency of high-frequency structures, CBOW is used for semantic analysis. Assume that \(m\) structural files with embeddable watermarks are extracted for an OFD file that requires watermark addition.\(V_{i}\) structural keywords are extracted from file \(F_{i}\), and the training window size is \(K\). In such cases, the time complexity for training using the CBOW model can be calculated as follows:  
\[T_{\text{CBOW}}=V_{0}+V_{1}+\dots+V_{m-1}=O(\sum_{i=0}^{m-1}V_{i}) \tag{6}\]  
The time complexity for training using the Skip-gram model is as follows:  
\[T_{\text{skip-gram}}=K\cdot V_{0}+K\cdot V_{1}+\dots+K\cdot V_{m-1}=O(K\sum_{ i=0}^{m-1}V_{i}) \tag{7}\]  
Based on the size of the text words, we set the threshold (\(\tau\)) to select the model with the best training effect for calculation:  
\[\text{model}=\left\{ \begin{array}{ll}\text{skip-gram},&\sum_{i=0}^{m-1}V_{i }<\tau\\ \text{CBOW},&\sum_{i=0}^{m-1}V_{i}<\tau\end{array} \right. \tag{8}\]As mentioned in Section 3.2.1, the Skip-gram model exhibited higher accuracy compared to the CBOW model in our experiments. In particular, when the time consumed is similar, the Skip-gram model outperforms CBOW. In our work, this occurred when \(\tau\) had a value of 1000. 2. Watermark content processing. Encrypt the watermark text (_originalInfo_) using the SM4 algorithm with a key derived from the combination of the file name (_fileName_) of the watermarked file, and a custom string (myString) provided by the adder. This encryption process is represented by Equation (9).