A knowledge graph-based method for detecting and evaluating pharmaceutical pollutants in water bodies

By constructing a dynamic knowledge graph and integrating multimodal data, and using DeepWalk graph embedding and gated cyclic units to generate dynamic embedding vectors, the problems of long detection time and insufficient interpretability of drug pollutants in water bodies are solved, enabling rapid and accurate risk assessment and transparent decision-making.

CN122332910APending Publication Date: 2026-07-03HEBEI RUNFENG ENVIRONMENTAL TESTING SERVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610469336.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-10
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing technologies for the detection and evaluation of pharmaceutical pollutants in water bodies suffer from problems such as long processing time, high cost, lack of multimodal information fusion, and insufficient model interpretability, making it difficult to meet the needs of rapid screening and transparent decision-making.

Method used

By constructing a dynamic knowledge graph and integrating multimodal data, and using DeepWalk graph embedding and gated recurrent units to generate dynamic embedding vectors, combined with comparative learning optimization, we can achieve rapid inference and interpretable assessment of the risks of new pollutants.

Benefits of technology

It improves the accuracy and interpretability of the detection of pharmaceutical pollutants in water bodies, can capture the dynamic evolution characteristics of pollutants, and enhances the ability to identify the risks of newly detected pollutants and the transparency of decision-making.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122332910A_ABST
    Figure CN122332910A_ABST
Patent Text Reader

Abstract

This invention discloses a method for detecting and evaluating pharmaceutical pollutants in water bodies based on a knowledge graph, comprising the following steps: acquiring monitoring data of pharmaceutical pollutants in water bodies and constructing a dynamic knowledge graph sequence; extracting the structural topological representation and textual semantic representation of compound nodes, and gating and fusing them to generate a multimodal initial representation; using DeepWalk to generate static embedding vectors for each time window; extracting temporal features through gated recurrent units to generate dynamic embedding vectors, and optimizing them using contrastive learning; inserting new pollutants into the graph and inferring their dynamic embedding vectors; calculating the similarity with known nodes to determine the risk warning level; searching for paths and converting them into natural language descriptive text, and outputting the warning level and explanatory text. This invention achieves dynamic, interpretable, and rapid evaluation of the risk of new pollutants, improving the accuracy of risk warnings and the transparency of decision-making.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of environmental monitoring technology, and in particular to a method for detecting and evaluating pharmaceutical pollutants in water bodies based on knowledge graphs. Background Technology

[0002] As emerging environmental pollutants, pharmaceutical contaminants in aquatic environments have attracted widespread attention due to their persistent presence and potential ecological risks. Methods for detecting and evaluating pharmaceutical contaminants in water bodies mainly include traditional evaluation methods based on toxicological experiments and environmental risk prediction methods based on machine learning. While traditional toxicological experimental methods yield accurate results, they are time-consuming and costly, making them unsuitable for the rapid screening of a large number of emerging pollutants. Machine learning-based risk prediction methods typically use molecular structure descriptors as input and predict the toxicity or environmental behavior of pollutants through quantitative structure-activity relationship models. However, these methods rely solely on molecular structure information and fail to fully utilize the multi-source heterogeneous knowledge accumulated in existing pollutant databases, such as environmental behavior parameters, co-occurrence relationships, and literature knowledge.

[0003] In recent years, knowledge graph technology has been applied to the field of environmental pollutant management. Existing knowledge graph-based pollutant assessment methods mostly employ static graph structures, failing to capture the dynamic evolution of pollutants in water bodies due to seasonal changes, pollution events, and other factors. When processing newly detected pollutants, existing methods lack the integration of multimodal information, and the model reasoning process lacks interpretability, making it difficult to meet the transparency requirements of environmental regulation. Furthermore, existing methods fail to fully utilize the temporal evolution of pollutants to enhance the accuracy of risk characterization.

[0004] Therefore, how to provide a method for the detection and evaluation of pharmaceutical pollutants in water based on knowledge graphs is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0005] One objective of this invention is to propose a method for detecting and evaluating pharmaceutical pollutants in water bodies based on knowledge graphs. This invention constructs a dynamic knowledge graph, integrates multimodal data, uses DeepWalk graph embedding and gated recurrent units to generate dynamic embedding vectors, and combines comparative learning optimization to achieve rapid inference and interpretable evaluation of the risks of new pollutants. It has the advantages of high accuracy, strong interpretability, and the ability to capture the dynamic evolution characteristics of pollutants.

[0006] A method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to an embodiment of the present invention includes the following steps: Acquire monitoring data on drug pollutants in water bodies and construct a dynamic knowledge graph sequence; The structural topological representation and textual semantic representation of compound nodes are extracted, and the structural topological representation and textual semantic representation are fused through a gating fusion mechanism to generate a multimodal initial representation; Based on the dynamic knowledge graph sequence and multimodal initial representation, the DeepWalk algorithm is used to perform random walks in each time window to generate node sequences. The node sequences are then input into the Skip-Gram model for training to obtain static embedding vectors. The static embedding vectors of the same compound node in different time windows are combined into a temporal vector sequence. The temporal features are extracted using a gated recurrent unit to generate the dynamic embedding vector of the compound node. The dynamic embedding vector is then optimized by combining the contrastive learning loss during the training process. Newly detected pollutants are inserted into the dynamic knowledge graph as new compound nodes. Based on the structural similarity edges and attribute edges of the new compound nodes, the dynamic embedding vector of the new compound nodes is inferred using gated recurrent units. Calculate the similarity between the dynamic embedding vector of the new compound node and the dynamic embedding vector of each known compound node, select a preset number of known compound nodes, and determine the risk warning level of the new compound node based on the risk labels of the known compound nodes. Search for paths from new compound nodes to the known compound nodes with the highest similarity in a static knowledge graph, filter paths that meet preset conditions, convert them into natural language description text, and output the risk warning level and natural language description text.

[0007] Optionally, the construction of the dynamic knowledge graph sequence specifically includes: Based on the acquired water pollution monitoring data, a static knowledge graph is constructed. The static knowledge graph includes a series of chain structures. Each chain is formed by connecting several nodes in sequence. Adjacent nodes in the chain are associated through type-distinguished edges. Different chains are connected through cross-chain edges to form an initial network topology. The static knowledge graph is divided into several time windows according to the time dimension. For each time window, the topological relationship between nodes and corresponding edges in the chain structure is preserved, and time information is introduced to mark the state of nodes and chains. The graph structure of each time window is arranged in chronological order to form a dynamic knowledge graph sequence. The node position order of the same chain is kept consistent in each time window. The type or state of the edges in the chain is updated over time. Different chains maintain global topological consistency through cross-chain edges.

[0008] Optionally, the gating fusion mechanism specifically includes: Obtain the neighborhood subgraph of compound nodes within each time window in the dynamic knowledge graph sequence, and generate a structural topology representation based on the type identifier of neighboring nodes and the type of connecting edges in the neighborhood subgraph; Extract text data associated with compound nodes within each time window in the dynamic knowledge graph sequence, and perform semantic encoding on the text data to generate text semantic representation; The structural topological representation and textual semantic representation are input into the gated network layer. The gated network layer contains a cross-modal interaction unit and a weight calculation unit. The cross-modal interaction unit obtains interaction features from the structural topological representation and textual semantic representation. The weight calculation unit outputs structural gating weights and textual gating weights based on the interaction features. The structural topological representation and textual semantic representation are then weighted and fused according to the structural gating weights and textual gating weights to generate the multimodal initial representation of the compound node.

[0009] Optionally, the DeepWalk algorithm specifically includes: For each time window in the dynamic knowledge graph sequence, the multimodal initial representation of each compound node within the time window is used as the initial feature of the node. A preset number of random walks are performed on the graph structure of the time window. Each random walk starts from any node and randomly selects the next node according to the edge type weight between nodes. This is repeated until the walk path length reaches the preset number of steps, generating a node sequence of fixed length. Using all node sequences as training corpus, construct a Skip-Gram model. The Skip-Gram model maintains a node embedding matrix. Each target node in the node sequence is input into the Skip-Gram model. The neighboring nodes of the target node within a preset window in the node sequence are used as prediction targets. The target node is encoded into a node embedding vector by the Skip-Gram model. The similarity between the node embedding vector and the node embedding vectors in the node embedding matrix is ​​calculated and normalized to obtain the co-occurrence probability of the target node and each node. The node embedding matrix is ​​optimized with the goal of maximizing the co-occurrence probability of the target node and its neighboring nodes within the window. The vectors corresponding to each compound node in the optimized node embedding matrix are used as the static embedding vectors of the compound nodes in the current time window.

[0010] Optionally, the optimization during training by incorporating contrastive learning loss specifically includes: The dynamic embedding vectors of each compound node in each time window are obtained. The dynamic embedding vectors of any two compound nodes that co-occur in the same time window and at the same water sampling point are constructed as the first positive sample pair. The dynamic embedding vectors of the same compound node in two adjacent time windows are constructed as the second positive sample pair. The dynamic embedding vectors of two compound nodes that meet any of the following conditions are constructed as negative sample pairs: the two compound nodes have never co-occurred at the same water body sampling point, the time window interval between the two compound nodes exceeds a preset time threshold, and the two compound nodes belong to different risk levels and have never co-occurred. The first positive sample pair, the second positive sample pair, and the negative sample pair are input into the contrastive learning module. The contrastive learning module calculates the similarity between the two dynamic embedding vectors in each sample pair. The contrastive learning loss function is constructed with the goal of maximizing the similarity between the first positive sample pair and the second positive sample pair and minimizing the similarity between the negative sample pairs. The contrastive learning loss function and the training loss function of the gated recurrent unit are weighted and summed to obtain the total loss function. The model parameters are iteratively updated until the total loss function converges.

[0011] Optionally, inserting newly detected pollutants as new compound nodes into the dynamic knowledge graph specifically includes: Newly detected pollutants are inserted as new compound nodes into the dynamic knowledge graph of the current time window, node identifiers are created for the new compound nodes, and associations are established between the new compound nodes and the time nodes of the current time window. Based on the molecular structure information of the new compound node, the similarity is calculated with the molecular structure information of each known compound node in the dynamic knowledge graph. Known compound nodes with similarity greater than the preset similarity threshold are selected, and structural similarity edges are established between the new compound node and the selected known compound nodes. Based on the predicted physicochemical properties of the new compound node, attribute nodes that match the predicted physicochemical properties are retrieved in the dynamic knowledge graph, and attribute edges are established between the new compound node and the retrieved attribute nodes.

[0012] Optionally, the gated loop unit specifically includes: During the training phase, the static embedding vectors of the same compound node in each time window are arranged in the order of the time window to form a temporal vector sequence. The temporal vector sequence is then input into the gated recurrent unit. At each time step, the gated recurrent unit receives the static embedding vector of the current time step and the hidden state of the previous time step, outputs the hidden state of the current time step, and uses the hidden state output by the last time step as the dynamic embedding vector of the compound node. During the inference phase, the static embedding vectors of known compound nodes connected to the structurally similar edges of the new compound node in the current time window are obtained, and the type codes of attribute nodes connected to the attribute edges of the new compound node in the current time window are obtained. All obtained static embedding vectors and all type codes are concatenated to generate the feature vector of the new compound node in the current time window. The hidden state of the new compound node in the previous time window is initialized to a zero vector. The feature vector is input into a trained gated recurrent unit. The gated recurrent unit receives the feature vector and the hidden state of the previous time window, and outputs the hidden state of the current time window as the dynamic embedding vector of the new compound node in the current time window.

[0013] Optionally, the conversion to natural language descriptive text specifically includes: Obtain the known compound node with the highest similarity, and retrieve the toxic endpoint node connected to the known compound node in the static knowledge graph. Starting from the new compound node and taking the retrieved toxic endpoint node as the target node, perform a bidirectional breadth-first search. Expand the neighboring nodes layer by layer from the starting point and expand the neighboring nodes in reverse from the target node until the two searches meet. Record the node sequence and edge sequence from the starting point to the target node when they meet to form a candidate path set. For each path in the candidate path set, select the three shortest paths as the explanation paths; For each selected explanation path, nodes are mapped to preset phrase templates and edges are mapped to preset connectors according to the types of nodes and edges in the path. Natural language sentences are generated by concatenating the nodes in the order they appear in the path. The natural language sentences corresponding to the three explanation paths are combined into a natural language description text, and the risk warning level and natural language description text are output.

[0014] The beneficial effects of this invention are: (1) This invention constructs a dynamic knowledge graph sequence and extracts the evolutionary features of pollutants in the time dimension to generate dynamic embedding vectors, which can capture the dynamic evolution of pollutants with seasonal changes and pollution events, overcome the defect that the existing static knowledge graph cannot reflect the temporal changes, and improve the timeliness and accuracy of risk assessment.

[0015] (2) This invention generates a multimodal initial representation by fusing structural topological representation and text semantic representation, optimizes it by combining contrastive learning loss, enhances the vector aggregation degree of similar risk pollutants by utilizing water co-occurrence relationship and pollutant temporal evolution relationship, and improves the discrimination ability of newly detected pollutant risk matching.

[0016] (3) This invention overcomes the lack of interpretability of existing machine learning methods by searching the path from the new compound node to the toxic endpoint node and converting it into natural language description text, and outputting interpretable risk inference basis, thereby improving decision-making transparency and regulatory acceptability. Attached Figure Description

[0017] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a knowledge graph-based method for detecting and evaluating pharmaceutical pollutants in water, as proposed in this invention. Figure 2 This is a flowchart illustrating the multimodal initial representation generation process of a knowledge graph-based method for detecting and evaluating pharmaceutical pollutants in water. Figure 3 This is a comparative learning optimization flowchart for a knowledge graph-based method for detecting and evaluating pharmaceutical pollutants in water. Detailed Implementation

[0018] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0019] refer to Figures 1-3 A method for detecting and evaluating pharmaceutical pollutants in water bodies based on knowledge graphs, comprising the following steps: Acquire monitoring data on drug pollutants in water bodies and construct a dynamic knowledge graph sequence; The structural topological representation and textual semantic representation of compound nodes are extracted, and the structural topological representation and textual semantic representation are fused through a gating fusion mechanism to generate a multimodal initial representation; Based on the dynamic knowledge graph sequence and multimodal initial representation, the DeepWalk algorithm is used to perform random walks in each time window to generate node sequences. The node sequences are then input into the Skip-Gram model for training to obtain static embedding vectors. The static embedding vectors of the same compound node in different time windows are combined into a temporal vector sequence. The temporal features are extracted using a gated recurrent unit to generate the dynamic embedding vector of the compound node. The dynamic embedding vector is then optimized by combining the contrastive learning loss during the training process. Newly detected pollutants are inserted into the dynamic knowledge graph as new compound nodes. Based on the structural similarity edges and attribute edges of the new compound nodes, the dynamic embedding vector of the new compound nodes is inferred using gated recurrent units. Calculate the similarity between the dynamic embedding vector of the new compound node and the dynamic embedding vector of each known compound node, select a preset number of known compound nodes, and determine the risk warning level of the new compound node based on the risk labels of the known compound nodes. Search for paths from new compound nodes to the known compound nodes with the highest similarity in a static knowledge graph, filter paths that meet preset conditions, convert them into natural language description text, and output the risk warning level and natural language description text.

[0020] In this embodiment, constructing a dynamic knowledge graph sequence specifically includes: Based on the acquired water pollution monitoring data, a static knowledge graph is constructed. The static knowledge graph includes a series of chain structures. Each chain is formed by connecting several nodes in sequence. Adjacent nodes in the chain are associated through type-distinguished edges. Different chains are connected through cross-chain edges to form an initial network topology. The static knowledge graph is divided into several time windows according to the time dimension. For each time window, the topological relationship between nodes and corresponding edges in the chain structure is preserved, and time information is introduced to mark the state of nodes and chains. The graph structure of each time window is arranged in chronological order to form a dynamic knowledge graph sequence. The node position order of the same chain is kept consistent in each time window. The type or state of the edges in the chain is updated over time. Different chains maintain global topological consistency through cross-chain edges.

[0021] Using drug contaminants as compound nodes, octanol water partition coefficient, biodegradation half-life, photolysis half-life, and adsorption coefficient as attribute nodes, algal half-inhibitory concentration, fish half-lethal concentration, and endocrine disruption activity grading as toxicity endpoint nodes, literature abstract text as text nodes, and sampling time as time node, an entity set is constructed. For each time window, extract the edges corresponding to all time nodes within that time window, obtain all compound nodes, attribute nodes, toxicity endpoint nodes, and text nodes detected within the time window, extract the structural similarity edges and co-occurrence edges in water bodies between compound nodes within the time window, construct the static knowledge graph subgraph corresponding to the time window, and the co-occurrence edges in water bodies are the edges established between any two compound nodes detected at the same sampling point and the same sampling time.

[0022] In this embodiment, the gating fusion mechanism specifically includes: Obtain the neighborhood subgraph of compound nodes within each time window in the dynamic knowledge graph sequence. Generate a structural topological representation based on the type identifier of neighboring nodes and the type of connecting edges in the neighborhood subgraph. Group the neighboring nodes by edge type, encode and aggregate the node type identifiers within the same group to obtain the structural feature vectors corresponding to each edge type. Concatenate the structural feature vectors of all edge types to form a structural topological representation. Extract text data associated with compound nodes within each time window in the dynamic knowledge graph sequence, perform semantic encoding on the text data to generate text semantic representation; extract all text nodes associated with the compound node, input the literature abstract text corresponding to each text node into the semantic encoding network to obtain the semantic vector of each text node, and calculate the arithmetic mean of all semantic vectors as the text semantic representation. The structural topological representation and textual semantic representation are input into the gated network layer. The gated network layer contains a cross-modal interaction unit and a weight calculation unit. The cross-modal interaction unit obtains interaction features from the structural topological representation and textual semantic representation. The weight calculation unit outputs structural gating weights and textual gating weights based on the interaction features. The structural topological representation and textual semantic representation are then weighted and fused according to the structural gating weights and textual gating weights to generate the multimodal initial representation of the compound node.

[0023] The cross-modal interaction unit takes structural topological representation and textual semantic representation as input. It calculates the attention weights of the structural topological representation to the textual semantic representation using a multi-head attention mechanism, and then performs a weighted summation of the textual semantic representations based on these attention weights to generate a structure-guided text-enhanced representation. It then calculates the attention weights of the textual semantic representation to the structural topological representation using the same multi-head attention mechanism, and performs a weighted summation of the structural topological representations based on these attention weights to generate a text-guided structure-enhanced representation. Finally, it concatenates the structure-guided text-enhanced representations with the text-guided structure-enhanced representations to obtain the fused interactive features. The weight calculation unit takes the fused interaction features as input, and sequentially passes the fused interaction features through the first fully connected layer for dimensionality reduction mapping, through the second fully connected layer for nonlinear transformation, and through the third fully connected layer for mapping to a two-dimensional vector. The two-dimensional vector is then input into the Softmax function for normalization to obtain the structure-gated weights and the text-gated weights. The sum of the structure-gated weights and the text-gated weights is 1.

[0024] In this embodiment, the DeepWalk algorithm specifically includes: For each time window in the dynamic knowledge graph sequence, the multimodal initial representation of each compound node within the time window is used as the initial feature of the node. A preset number of random walks are performed on the graph structure of the time window. Each random walk starts from any node and randomly selects the next node according to the edge type weight between nodes. This is repeated until the walk path length reaches the preset number of steps, generating a node sequence of fixed length. Using all node sequences as training corpus, construct a Skip-Gram model. The Skip-Gram model maintains a node embedding matrix. Each target node in the node sequence is input into the Skip-Gram model. The neighboring nodes of the target node within a preset window in the node sequence are used as prediction targets. The target node is encoded into a node embedding vector by the Skip-Gram model. The similarity between the node embedding vector and the node embedding vectors in the node embedding matrix is ​​calculated and normalized to obtain the co-occurrence probability of the target node and each node. The node embedding matrix is ​​optimized with the goal of maximizing the co-occurrence probability of the target node and its neighboring nodes within the window. The vectors corresponding to each compound node in the optimized node embedding matrix are used as the static embedding vectors of the compound nodes in the current time window.

[0025] The preset number of random walks is 50, and the preset number of steps for the walk path length is 10. The type weights of edges between nodes are preset according to the importance of edge types. The preset window range in the Skip-Gram model is 5. When optimizing the node embedding matrix, a negative sampling method is used, with cross-entropy loss as the optimization objective.

[0026] In this embodiment, optimization during training by incorporating contrastive learning loss specifically includes: The dynamic embedding vectors of each compound node in each time window are obtained. The dynamic embedding vectors of any two compound nodes that co-occur in the same time window and at the same water sampling point are constructed as the first positive sample pair. The dynamic embedding vectors of the same compound node in two adjacent time windows are constructed as the second positive sample pair. Two adjacent time windows are defined as time window indices that differ by 1 and the time interval between the two time windows does not exceed 90 days. Two compound nodes whose dynamic embedding vectors meet any of the following conditions are constructed as negative sample pairs: the two compound nodes have never co-occurred at the same water body sampling point; the time window interval between the two compound nodes exceeds a preset time threshold; the two compound nodes belong to different risk levels and have never co-occurred. The preset time threshold is 365 days. Different risk levels refer to the three categories of high risk, medium risk, and low risk based on known toxicity data. Never co-occurring at the same water body sampling point means that there are no records in all historical monitoring data of two compound nodes being detected at the same sampling point and in the same time window. The first positive sample pair, the second positive sample pair, and the negative sample pair are input into the contrastive learning module. The contrastive learning module calculates the similarity between the two dynamic embedding vectors in each sample pair. The contrastive learning loss function is constructed with the goal of maximizing the similarity between the first positive sample pair and the second positive sample pair and minimizing the similarity between the negative sample pairs. The contrastive learning loss function and the training loss function of the gated recurrent unit are weighted and summed to obtain the total loss function. The model parameters are iteratively updated until the total loss function converges. The similarity is calculated using cosine similarity. The contrastive learning loss function adopts the InfoNCE loss form.

[0027] In this embodiment, inserting newly detected pollutants as new compound nodes into the dynamic knowledge graph specifically includes: Newly detected pollutants are inserted as new compound nodes into the dynamic knowledge graph of the current time window, node identifiers are created for the new compound nodes, and associations are established between the new compound nodes and the time nodes of the current time window. Based on the molecular structure information of the new compound node, similarity is calculated between it and the molecular structure information of each known compound node in the dynamic knowledge graph. Known compound nodes with similarity greater than a preset similarity threshold are selected, and structural similarity edges are established between the new compound node and the selected known compound nodes. Molecular structure information is encoded using Morgan molecular fingerprints, which have a radius of 2 and a length of 2048 bits. The similarity calculation uses the Tanimoto coefficient, which is calculated by dividing the intersection of two molecular fingerprints by their union. The preset similarity threshold is 0.7. When the Tanimoto coefficient between the new compound node and a known compound node is greater than 0.7, a structural similarity edge is established between the new compound node and that known compound node. Based on the predicted physicochemical properties of the new compound node, attribute nodes that match the predicted physicochemical properties are retrieved in the dynamic knowledge graph, and attribute edges are established between the new compound node and the retrieved attribute nodes. Each attribute node is pre-divided into discrete intervals according to the attribute value range. The predicted physicochemical properties of the new compound node are calculated through the quantitative structure-activity relationship model. The predicted values ​​are compared with the attribute value range of each attribute node. When the predicted value falls within the attribute value range of the attribute node, an attribute edge is established between the new compound node and the attribute node.

[0028] In this embodiment, the gated loop unit specifically includes: During the training phase, the static embedding vectors of the same compound node in each time window are arranged in the order of the time window to form a temporal vector sequence. The temporal vector sequence is then input into the gated recurrent unit. At each time step, the gated recurrent unit receives the static embedding vector of the current time step and the hidden state of the previous time step, outputs the hidden state of the current time step, and uses the hidden state output by the last time step as the dynamic embedding vector of the compound node. During the inference phase, the static embedding vectors of known compound nodes connected to the structurally similar edges of the new compound node in the current time window are obtained, and the type codes of attribute nodes connected to the attribute edges of the new compound node in the current time window are obtained. All obtained static embedding vectors and all type codes are concatenated to generate the feature vector of the new compound node in the current time window. The hidden state of the new compound node in the previous time window is initialized to a zero vector. The feature vector is input into a trained gated recurrent unit. The gated recurrent unit receives the feature vector and the hidden state of the previous time window, and outputs the hidden state of the current time window as the dynamic embedding vector of the new compound node in the current time window.

[0029] Obtain the dynamic embedding vector of the new compound node in the current time window from the trained gated recurrent unit, and obtain the dynamic embedding vectors of all known compound nodes in the dynamic knowledge graph in the same time window; calculate the cosine similarity between the dynamic embedding vector of the new compound node and the dynamic embedding vector of each known compound node. After the calculation is completed, all known compound nodes are sorted from high to low according to cosine similarity, and the top 5 known compound nodes are selected as similarity reference nodes. Obtain the risk labels for the five selected known compound nodes. The risk labels are divided into three categories: high risk, medium risk, and low risk. Count the frequency of each type of risk label in the five known compound nodes. The risk level with the highest frequency is taken as the risk warning level of the new compound node. When the highest frequency is tied, the higher risk level is taken as the warning level. Finally, output the risk warning level of the new compound node.

[0030] In this embodiment, converting to natural language descriptive text specifically includes: The system obtains the known compound node with the highest similarity and retrieves the toxic endpoint node connected to this known compound node in the static knowledge graph. Starting from the new compound node and using the retrieved toxic endpoint node as the target node, it performs a bidirectional breadth-first search. It expands the neighboring nodes layer by layer from the starting point and expands the neighboring nodes in reverse from the target node until the two searches meet. It records the node sequence and edge sequence from the starting point to the target node when they meet, forming a candidate path set. The upper limit of the expansion depth of the bidirectional breadth-first search is 10 layers. For each path in the candidate path set, select the three shortest paths as the explanation paths; For each selected explanation path, nodes are mapped to preset phrase templates and edges are mapped to preset connectors according to the types of nodes and edges in the path. Natural language sentences are generated by concatenating the nodes in the order they appear in the path. The natural language sentences corresponding to the three explanation paths are combined into a natural language description text, and the risk warning level and natural language description text are output.

[0031] The mapping relationship between node types and phrase templates is as follows: compound nodes are mapped to "pollutant [node name]", attribute nodes are mapped to "possessing [attribute name] characteristics", toxicity endpoint nodes are mapped to "leading to [toxicity name] risk", and text nodes are mapped to "recorded in literature [literature title]". The mapping relationship between edge types and conjunctions is as follows: structural similarity edges are mapped to "and", attribute edges are mapped to "and", leading edges are mapped to "furthermore", co-occurrence in water bodies edges are mapped to "detected simultaneously with ...", and occurrence in edges are mapped to "detected in [time window]". When splicing to generate natural language sentences, node phrases and conjunctions are arranged alternately, starting with the starting node phrase and ending with the target node phrase to form a complete explanatory sentence.

[0032] In practical applications, newly detected drug-related pollutants may lack complete toxicological data. The association information in the knowledge graph mainly relies on structural similarity and physicochemical property predictions. Therefore, the risk warning level output by the method of this invention is only an inference result based on the existing knowledge graph, and its accuracy is limited by the coverage of known compound nodes and the reliability of structural similarity calculation. Nevertheless, this method can provide valuable risk references for environmental monitoring personnel and help identify new pollutants that need to be focused on. For new compounds with confirmed risk levels, their complete toxicity data and property information can be manually added to the knowledge graph to expand the set of known compound nodes.

[0033] Example 1: To verify the feasibility of this invention in practice, it was applied to the detection and risk assessment of pharmaceutical pollutants in water bodies. In this scenario, various pharmaceutical residues may exist in the water. Existing detection methods mainly include traditional toxicological experimental evaluation methods and machine learning prediction methods based on molecular structure descriptors. While traditional toxicological methods are accurate, they are time-consuming and difficult to process large numbers of newly detected compounds quickly; structure prediction methods are faster, but the prediction results depend on molecular characteristics and lack sufficient interpretability and time-series dynamic analysis capabilities.

[0034] This invention constructs a dynamic knowledge graph to integrate information on drug-related pollutants in water bodies across different time windows. It then utilizes a multimodal fusion mechanism to extract the structural topological and textual semantic representations of compound nodes, generating initial embedding vectors. Subsequently, the DeepWalk algorithm is used to perform random walks on each time window and train a Skip-Gram model to obtain static embedding vectors. These static vectors are then input into a gated recurrent unit to extract temporal features and generate dynamic embedding vectors. Combined with contrastive learning optimization, this results in higher vector clustering for compounds of similar risk and more distinct vector distributions for nodes of different risk levels. When a new pollutant is detected, it is inserted into the dynamic knowledge graph. Edge relationships are established through structural similarity and attribute matching, and the dynamic embedding vector is inferred. The similarity to known compounds is calculated to quickly determine the risk level, while simultaneously outputting a natural language explanatory text.

[0035] In comparative experiments, the method of this invention was evaluated against traditional toxicology experiments and structure prediction methods. Experimental metrics included prediction accuracy, risk warning coverage, average processing time, and interpretability score. Results showed that the method of this invention slightly outperformed traditional toxicology methods in accuracy and was significantly faster in terms of experimental cycle. Regarding interpretability, due to its reliance on multimodal information and path-generated natural language descriptions, it was slightly lower than traditional experimental methods, but still provided regulatory personnel with the ability to understand the information. Compared to structure prediction methods, the method of this invention improved both accuracy and risk coverage while shortening processing time.

[0036] In summary, the method of this invention can not only rapidly assess the risk of newly detected pollutants, but also dynamically capture the temporal evolution characteristics of pollutants in water bodies. Through multimodal fusion and comparative learning, it improves the accuracy of identifying similar risky compounds. Compared to traditional methods, this invention has a significant advantage in processing time, enabling risk prediction to be completed on the same day, providing a reliable tool for environmental monitoring and rapid response. It also maintains a high level of interpretability, meeting the needs of regulatory applications.

[0037] Table 1: Comparison of drug detection effects of different methods As shown in the table, the method of this invention slightly outperforms traditional toxicology methods in prediction accuracy, improving it by only 2 percentage points. However, it surpasses traditional methods in risk warning coverage, enabling rapid identification of most high-risk compounds. In terms of processing time, the method of this invention requires an average of only 0.5 days, significantly shorter than the 14 days of traditional toxicology, demonstrating its advantages in rapid response and efficient assessment. Although the interpretability score is slightly lower than traditional experimental methods, the natural language interpretation still provides regulatory personnel with clear risk assessment criteria. Compared to methods relying solely on molecular structure prediction, this invention has advantages in both accuracy and coverage, with a significantly reduced processing time, demonstrating the important value of dynamic knowledge graphs, multimodal fusion, and time-series analysis for rapid risk assessment.

[0038] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A method for detecting and evaluating pharmaceutical pollutants in water bodies based on knowledge graphs, characterized in that, Includes the following steps: Acquire monitoring data on drug pollutants in water bodies and construct a dynamic knowledge graph sequence; The structural topological representation and textual semantic representation of compound nodes are extracted, and the structural topological representation and textual semantic representation are fused through a gating fusion mechanism to generate a multimodal initial representation; Based on the dynamic knowledge graph sequence and multimodal initial representation, the DeepWalk algorithm is used to perform random walks in each time window to generate node sequences. The node sequences are then input into the Skip-Gram model for training to obtain static embedding vectors. The static embedding vectors of the same compound node in different time windows are combined into a temporal vector sequence. The temporal features are extracted using a gated recurrent unit to generate the dynamic embedding vector of the compound node. The dynamic embedding vector is then optimized by combining the contrastive learning loss during the training process. Newly detected pollutants are inserted into the dynamic knowledge graph as new compound nodes. Based on the structural similarity edges and attribute edges of the new compound nodes, the dynamic embedding vector of the new compound nodes is inferred using gated recurrent units. Calculate the similarity between the dynamic embedding vector of the new compound node and the dynamic embedding vector of each known compound node, select a preset number of known compound nodes, and determine the risk warning level of the new compound node based on the risk labels of the known compound nodes. Search for paths from new compound nodes to the known compound nodes with the highest similarity in a static knowledge graph, filter paths that meet preset conditions, convert them into natural language description text, and output the risk warning level and natural language description text.

2. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 1, characterized in that, The construction of the dynamic knowledge graph sequence specifically includes: Based on the acquired water pollution monitoring data, a static knowledge graph is constructed. The static knowledge graph includes a series of chain structures. Each chain is formed by connecting several nodes in sequence. Adjacent nodes in the chain are associated through type-distinguished edges. Different chains are connected through cross-chain edges to form an initial network topology. The static knowledge graph is divided into several time windows according to the time dimension. For each time window, the topological relationship between nodes and corresponding edges in the chain structure is preserved, and time information is introduced to mark the state of nodes and chains. The graph structure of each time window is arranged in chronological order to form a dynamic knowledge graph sequence. The node position order of the same chain is kept consistent in each time window. The type or state of the edges in the chain is updated over time. Different chains maintain global topological consistency through cross-chain edges.

3. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 2, characterized in that, The gating fusion mechanism specifically includes: Obtain the neighborhood subgraph of compound nodes within each time window in the dynamic knowledge graph sequence, and generate a structural topology representation based on the type identifier of neighboring nodes and the type of connecting edges in the neighborhood subgraph; Extract text data associated with compound nodes within each time window in the dynamic knowledge graph sequence, and perform semantic encoding on the text data to generate text semantic representation; The structural topological representation and textual semantic representation are input into the gated network layer. The gated network layer contains a cross-modal interaction unit and a weight calculation unit. The cross-modal interaction unit obtains interaction features from the structural topological representation and textual semantic representation. The weight calculation unit outputs structural gating weights and textual gating weights based on the interaction features. The structural topological representation and textual semantic representation are then weighted and fused according to the structural gating weights and textual gating weights to generate the multimodal initial representation of the compound node.

4. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 3, characterized in that, The DeepWalk algorithm specifically includes: For each time window in the dynamic knowledge graph sequence, the multimodal initial representation of each compound node within the time window is used as the initial feature of the node. A preset number of random walks are performed on the graph structure of the time window. Each random walk starts from any node and randomly selects the next node according to the edge type weight between nodes. This is repeated until the walk path length reaches the preset number of steps, generating a node sequence of fixed length. Using all node sequences as training corpus, construct a Skip-Gram model. The Skip-Gram model maintains a node embedding matrix. Each target node in the node sequence is input into the Skip-Gram model. The neighboring nodes of the target node within a preset window in the node sequence are used as prediction targets. The target node is encoded into a node embedding vector by the Skip-Gram model. The similarity between the node embedding vector and the node embedding vectors in the node embedding matrix is ​​calculated and normalized to obtain the co-occurrence probability of the target node and each node. The node embedding matrix is ​​optimized with the goal of maximizing the co-occurrence probability of the target node and its neighboring nodes within the window. The vectors corresponding to each compound node in the optimized node embedding matrix are used as the static embedding vectors of the compound nodes in the current time window.

5. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 4, characterized in that, The optimization during training by incorporating contrastive learning loss specifically includes: The dynamic embedding vectors of each compound node in each time window are obtained. The dynamic embedding vectors of any two compound nodes that co-occur in the same time window and at the same water sampling point are constructed as the first positive sample pair. The dynamic embedding vectors of the same compound node in two adjacent time windows are constructed as the second positive sample pair. The dynamic embedding vectors of two compound nodes that meet any of the following conditions are constructed as negative sample pairs: the two compound nodes have never co-occurred at the same water body sampling point, the time window interval between the two compound nodes exceeds a preset time threshold, and the two compound nodes belong to different risk levels and have never co-occurred. The first positive sample pair, the second positive sample pair, and the negative sample pair are input into the contrastive learning module. The contrastive learning module calculates the similarity between the two dynamic embedding vectors in each sample pair. The contrastive learning loss function is constructed with the goal of maximizing the similarity between the first positive sample pair and the second positive sample pair and minimizing the similarity between the negative sample pairs. The contrastive learning loss function and the training loss function of the gated recurrent unit are weighted and summed to obtain the total loss function. The model parameters are iteratively updated until the total loss function converges.

6. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 5, characterized in that, The specific steps of inserting newly detected pollutants as new compound nodes into the dynamic knowledge graph include: Newly detected pollutants are inserted as new compound nodes into the dynamic knowledge graph of the current time window, node identifiers are created for the new compound nodes, and associations are established between the new compound nodes and the time nodes of the current time window. Based on the molecular structure information of the new compound node, the similarity is calculated with the molecular structure information of each known compound node in the dynamic knowledge graph. Known compound nodes with similarity greater than the preset similarity threshold are selected, and structural similarity edges are established between the new compound node and the selected known compound nodes. Based on the predicted physicochemical properties of the new compound node, attribute nodes that match the predicted physicochemical properties are retrieved in the dynamic knowledge graph, and attribute edges are established between the new compound node and the retrieved attribute nodes.

7. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 6, characterized in that, The gated loop unit specifically includes: During the training phase, the static embedding vectors of the same compound node in each time window are arranged in the order of the time window to form a temporal vector sequence. The temporal vector sequence is then input into the gated recurrent unit. At each time step, the gated recurrent unit receives the static embedding vector of the current time step and the hidden state of the previous time step, outputs the hidden state of the current time step, and uses the hidden state output by the last time step as the dynamic embedding vector of the compound node. During the inference phase, the static embedding vectors of known compound nodes connected to the structurally similar edges of the new compound node in the current time window are obtained, and the type codes of attribute nodes connected to the attribute edges of the new compound node in the current time window are obtained. All obtained static embedding vectors and all type codes are concatenated to generate the feature vector of the new compound node in the current time window. The hidden state of the new compound node in the previous time window is initialized to a zero vector. The feature vector is input into a trained gated recurrent unit. The gated recurrent unit receives the feature vector and the hidden state of the previous time window, and outputs the hidden state of the current time window as the dynamic embedding vector of the new compound node in the current time window.

8. The method for detecting and evaluating pharmaceutical pollutants in water based on knowledge graphs according to claim 7, characterized in that, The conversion to natural language descriptive text specifically includes: Obtain the known compound node with the highest similarity, and retrieve the toxic endpoint node connected to the known compound node in the static knowledge graph. Starting from the new compound node and taking the retrieved toxic endpoint node as the target node, perform a bidirectional breadth-first search. Expand the neighboring nodes layer by layer from the starting point and expand the neighboring nodes in reverse from the target node until the two searches meet. Record the node sequence and edge sequence from the starting point to the target node when they meet to form a candidate path set. For each path in the candidate path set, select the three shortest paths as the explanation paths; For each selected explanation path, nodes are mapped to preset phrase templates and edges are mapped to preset connectors according to the types of nodes and edges in the path. Natural language sentences are generated by concatenating the nodes in the order they appear in the path. The natural language sentences corresponding to the three explanation paths are combined into a natural language description text, and the risk warning level and natural language description text are output.