OPC UA automatic modeling method and system fusing large language model and static verification

CN122526558APending Publication Date: 2026-08-07WUHAN UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
WUHAN UNIV OF TECH
Filing Date
2026-05-08
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0005]现有OPC UA信息模型构建方式主要依赖人工根据点表、接口文档、配置文件或通信规范进行设计,存在建模效率低、更新成本高、模型与源代码实现脱节的问题

Benefits of technology

以工业诊断代码库为输入,结合大语言模型的代码语义理解能力和静态代码分析的事实约束能力,对源代码中的诊断语义进行自动提取、筛选和标准化建模,最终生成符合OPC UA规范的信息模型文件,实现对实现层诊断语义的自动提取、可信筛选和标准化导出,提高正确性和可靠性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122526558A_ABST
    Figure CN122526558A_ABST
Patent Text Reader

Abstract

The application discloses an OPC UA automatic modeling method and system fusing a large language model and static verification, and the method comprises the following steps: structurally analyzing input industrial diagnosis source code and cutting according to a syntax structure to form a code segment set, and constructing global context information based on the code segment set; calling the large language model to form a segment-level semantic abstract result corresponding to each code segment and a system-level object set, generate a namespace plan corresponding to each system-level object, and form an initial candidate information model; performing static analysis on the input industrial diagnosis source code to form a static fact set; matching the initial candidate information model with the static fact set to obtain a candidate information model with evidence score and type correction result; and screening and deciding the candidate information model to obtain a final OPC UA information model. The application can realize complete extraction and synchronous modeling from a source code implementation layer, and improve correctness and reliability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of industrial software information modeling and industrial automation technology, specifically relating to an OPC UA automatic modeling method and system that integrates large language models and static verification. Background Technology

[0002] Industrial diagnostic software contains a wealth of information closely related to system operating status and fault diagnosis, serving as a crucial basis for online diagnosis and fault analysis of industrial systems. To facilitate the unified representation and use of diagnostic information, standardized modeling is necessary to enhance the application capabilities of industrial software in interconnectivity, condition monitoring, and intelligent analysis scenarios.

[0003] OPC UA is a commonly used information modeling and communication standard in the field of industrial automation. It can standardize the description of key information in equipment, systems and applications through unified node and reference relationships, thereby achieving cross-platform and cross-device interconnection and interoperability. Therefore, it can provide a unified information modeling platform for industrial diagnostic software.

[0004] With the development of artificial intelligence and code analysis technologies, large language models can now be used for source code semantic understanding, functional summarization, and cross-file information aggregation. Meanwhile, static code analysis can extract program structure information and factual evidence from source code. These technological advancements provide a technical foundation for automated OPC UA modeling of source code for industrial diagnostic software.

[0005] Current methods for constructing OPC UA information models primarily rely on manual design based on point tables, interface documents, configuration files, or communication specifications. This results in low modeling efficiency, high update costs, and a disconnect between the model and the source code implementation. For information such as operational status, fault logic, and health indicators in industrial diagnostic software, existing methods struggle to fully extract and synchronously model it from the source code implementation layer, leading to incomplete model coverage and insufficient traceability. Furthermore, simply relying on large language models to extract semantics from code can easily produce candidate results inconsistent with the actual implementation due to insufficient evidence, failing to meet the requirements of correctness, reliability, and auditability in industrial scenarios. Summary of the Invention

[0006] To address the aforementioned deficiencies or improvement needs of existing technologies, this invention proposes an OPC UA automatic modeling method and system that integrates large language models and static verification. This method can completely extract and synchronously model from the source code implementation layer, thereby improving correctness and reliability.

[0007] To achieve the above objectives, according to one aspect of the present invention, an automatic OPC UA modeling method integrating large language models and static verification is provided, comprising the following steps: S1. Code preprocessing: The input industrial diagnostic source code is structured and segmented according to its syntax to form a set of code fragments. Global context information is then constructed based on the set of code fragments. S2. Semantic Extraction and Aggregation: Based on the code snippet set and global context information, a large language model is invoked to perform semantic understanding on each code snippet, extract semantic information related to industrial diagnosis, and form a snippet-level semantic summary result for each code snippet; the large language model is used to aggregate the snippet-level semantic summary results across snippets to obtain a system-level object set, and generate a namespace plan for each system-level object; using the subordinate relationships between objects in the system-level object set, a corresponding hierarchical organization relationship is generated to form an initial candidate information model; System-level objects include object name, object description, field set, method set, and source code variable name; The initial candidate information model includes candidate object nodes, candidate variable nodes, and candidate method nodes; the object names in the system-level objects are mapped to candidate object nodes, the object status fields and indicator fields in the field set are mapped to candidate variable nodes, and the method set is mapped to candidate method nodes. S3. Evidence Extraction and Static Verification: Static analysis is performed on the input industrial diagnostic source code based on abstract syntax tree to extract verifiable program facts and form a static fact set. The initial candidate information model is matched with the static fact set to construct a set of evidence items corresponding to each candidate variable node and candidate method node in the initial candidate information model. Evidence scores are performed on the candidate variable nodes and candidate method nodes based on evidence type and evidence weight. At the same time, data type correction is performed on the candidate variable nodes according to the evidence type to obtain a candidate information model with evidence scores and type correction results. S4. Model Generation and Export: Based on the evidence score, candidate information models are screened and decided, and candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships are retained to obtain the final OPC UA information model.

[0008] Following the method described above, Each candidate node is also assigned a browsing name, node identifier, and namespace information; In S2, duplicate candidate variable nodes are merged and deduplicated based on the source code variable name and the parent object to which the candidate variable node belongs.

[0009] The merging and deduplication process described above specifically includes: The candidate variable nodes are matched based on the combination of the source code variable name and its parent object. When two candidate variable nodes have the same source code variable name and correspond to the same parent object, they are determined to be duplicate candidate variable nodes and are merged.

[0010] Using the method described above, each code snippet in S1 retains its corresponding position index; In S3, each static fact retains the source code variable name associated with that static fact and its position index in the source code; The location index is an element in the static fact set.

[0011] According to the above method, each static fact in the static fact set should include at least: function and method call relationships, variable write relationships, variable read relationships, object state fields, log or print output fields, and type hint information; Each piece of evidence in the evidence set includes: evidence type, the source code variable name associated with the evidence, the index of the evidence in the source code, and the weight of the corresponding evidence type.

[0012] According to the above method, the evidence scoring specifically includes: For candidate nodes Record its type of evidence The following set of evidence items is The set of evidence types is Then the total set of evidence items for the candidate nodes is:

[0013] Candidate Nodes Candidate variable nodes or candidate method nodes; Define the evidence type hit indicator function:

[0014] The static evidence score is then:

[0015] in, Indicates the first Weight of evidence of a class.

[0016] According to the above method, type correction specifically includes: Candidate variable nodes The initial data type is denoted as ; The data type suggested by static analysis is the fact set. The fact matching predicate is ; Candidate variable nodes Matchable data type hint set Defined as:

[0017] in , To infer the data type, For static inference confidence level, Source location identifier; when When the static inference confidence is highest, the inferred data type is taken as the type correction result.

[0018] According to the above method, S4 specifically includes: Candidate Nodes The evidence score is ; Introducing a Reality Gating Function For variable nodes, when at least one type of matching static evidence exists among write evidence, status field evidence, print evidence, or log evidence, For method nodes, when there is evidence of invocation, In other cases ; Candidate Nodes The final decision score is:

[0019] Candidate elements are mapped to a three-stage decision outcome using a dual-threshold mechanism. D(x) :

[0020] in , These are the acceptance threshold and the review threshold, respectively. By satisfying The candidate nodes and their corresponding hierarchical organizational relationships are used to obtain the final OPC UA information model.

[0021] Following the above method, it will satisfy Candidate node records are recorded as items to be reviewed, for manual spot checks or subsequent rule expansion.

[0022] According to another aspect of the present invention, an OPC UA automatic modeling system integrating large language models and static verification is provided, comprising: The code preprocessing module is used to perform structured parsing of the input industrial diagnostic source code and segment it according to the syntax structure to form a set of code fragments, and to build global context information based on the set of code fragments; The semantic extraction and aggregation module is used to perform semantic understanding on each code segment based on the code segment set and global context information, and to extract semantic information related to industrial diagnosis, forming segment-level semantic summary results for each code segment; it then uses the large language model to aggregate the segment-level semantic summary results across segments to obtain a system-level object set, and generates a namespace plan for each system-level object; finally, it uses the hierarchical relationships between objects in the system-level object set to generate corresponding hierarchical organizational relationships, forming an initial candidate information model. System-level objects include object name, object description, field set, method set, and source code variable name; The initial candidate information model includes candidate object nodes, candidate variable nodes, and candidate method nodes; the object names in the system-level objects are mapped to candidate object nodes, the object status fields and indicator fields in the field set are mapped to candidate variable nodes, and the method set is mapped to candidate method nodes. The evidence extraction and static verification module is used to perform static analysis on the input industrial diagnostic source code based on the abstract syntax tree, extract verifiable program facts, and form a static fact set. It matches the initial candidate information model with the static fact set to construct the evidence item set corresponding to each candidate variable node and candidate method node in the initial candidate information model. It scores the candidate variable nodes and candidate method nodes based on evidence type and evidence weight, and corrects the data type of the candidate variable nodes according to the evidence type to obtain a candidate information model with evidence scoring and type correction results. The model generation and export module is used to screen and decide on candidate information models based on evidence scores, retain candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships, and obtain the final OPC UA information model.

[0023] In summary, compared with the prior art, the above-described technical solutions conceived by this invention can achieve the following beneficial effects: Using an industrial diagnostic code library as input, and combining the code semantic understanding capabilities of a large language model with the factual constraint capabilities of static code analysis, the diagnostic semantics in the source code are automatically extracted, filtered, and standardized in modeling. Finally, an information model file conforming to the OPC UA specification is generated, enabling automatic extraction, reliable filtering, and standardized export of diagnostic semantics at the implementation layer, thereby improving correctness and reliability. Attached Figure Description

[0024] Figure 1 This is a flowchart of a method provided in an embodiment of the present invention.

[0025] Figure 2 This is a system architecture diagram provided in an embodiment of the present invention.

[0026] Figure 3 This is a detailed step diagram of a method provided in an embodiment of the present invention.

[0027] Figure 4 This is a flowchart of the automated modeling process for UDP diagnostic code provided in an embodiment of the present invention.

[0028] Figure 5 This is a schematic diagram of the OPC UA information model automatically generated from UDP diagnostic code provided in this embodiment of the invention. Detailed Implementation

[0029] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.

[0030] This invention aims to provide an automated OPC UA modeling method that integrates source code, semantic-driven approach, and factual evidence constraints. While reducing the cost of manual modeling, it enables automatic extraction, reliable filtering, and standardized export of diagnostic semantics at the implementation layer, generating a deployable OPC UA information model.

[0031] This invention provides an automatic OPC UA modeling method that integrates large language models and static verification, applicable to industrial diagnostic code primarily based on Python. This method takes an industrial diagnostic code library as input, combining the code semantic understanding capabilities of a large language model with the factual constraint capabilities of static code analysis to automatically extract, filter, and standardize the diagnostic semantics in the source code, ultimately generating an information model file conforming to the OPC UA specification and exporting an address space instance that can be deployed on the server side.

[0032] The overall framework of this method is as follows: Figure 1 and Figure 3 As shown, it includes the following steps: S1. Code Preprocessing: The input industrial diagnostic source code is parsed in a structured manner and segmented according to the syntax structure to form a set of code fragments. Global context information is then constructed based on the set of code fragments.

[0033] The code preprocessing step primarily addresses the heterogeneity and context dispersion issues of large-scale codebases. First, the input code undergoes structured parsing, and the source code is segmented according to its syntactic structure, forming a set of code fragments. Based on this, global context information is further constructed. The segmentation is primarily based on code syntactic structure, ensuring relative semantic integrity within each fragment while avoiding comprehension degradation caused by excessively long contexts. Simultaneously, the code fragments output in this step, along with their source location indices, provide a unified localization benchmark for subsequent semantic and evidence stages, improving the traceability of model elements.

[0034] In some embodiments, the input industrial diagnostic source code is preprocessed, including structured parsing of the source code and segmentation of the source code according to its syntactic structure to obtain multiple code snippets. Global context information is extracted by combining information such as file structure, global imports, key classes, and entry points. Each code snippet retains its corresponding source location index for unified positioning in subsequent semantic extraction and evidence extraction stages, thereby improving the traceability of model elements. This step outputs a set of code snippets and global context information.

[0035] S2. Semantic Extraction and Aggregation: Based on the code fragment set and global context information, the large language model is invoked to perform semantic understanding on each code fragment, extract semantic information related to industrial diagnosis, and form fragment-level semantic summary results for each code fragment; the large language model is used to aggregate the fragment-level semantic summary results across fragments to obtain a system-level object set, and generate a namespace plan corresponding to each system-level object; using the subordinate relationships between objects in the system-level object set, the corresponding hierarchical organization relationship is generated to form an initial candidate information model.

[0036] The semantic extraction and aggregation step takes code snippets and global context as input, and calls a large language model to perform semantic understanding on each snippet, extracting the functions of each module in the industrial diagnostic source code and diagnostic-related information. Based on the extracted semantic summary, cross-snippet aggregation is further performed to merge the scattered semantics into a unified system-level object representation and generate a corresponding namespace plan, providing a consistent semantic perspective for subsequent candidate node mapping. This step solves the problem of code fragmentation, enabling diagnostic information to not be limited to the level of a single function, but to form a modelable system-level structure.

[0037] In some embodiments, a set of code snippets and global context information are input into a large language model to perform semantic understanding on each code snippet, identify the role and responsibility of the snippet in the diagnostic system, and extract semantic information related to industrial diagnostics, such as state variables, log output, observable indicators and method capabilities, to form a snippet-level semantic summary result for each code snippet, thus forming a snippet-level semantic summary set.

[0038] The obtained fragment-level semantic summarization results are then input into a large language model for cross-fragment aggregation. Diagnostic semantics scattered across different files and functions are consolidated into system-level object representations, and corresponding namespace planning is generated. The system-level object includes at least an object name, object description, field set, method set, and source code variable name mapping. The system-level object set and namespace planning results are then obtained.

[0039] Based on the obtained system-level object set, objects, fields, and methods are mapped to candidate OPC UA nodes and their hierarchical relationships, forming an initial candidate information model. Specifically, diagnostic modules or subsystem entities in industrial diagnostic software are mapped to candidate object nodes, object status fields and indicator fields are mapped to candidate variable nodes, and method capabilities are mapped to candidate method nodes. The corresponding hierarchical organizational relationships are generated by combining the subordinate relationships between objects, and each candidate node is assigned a browsing name, node identifier, and namespace information. The candidate object nodes are automatically generated (mapped) based on the object names in the system-level objects aggregated from the large language model.

[0040] In some embodiments, duplicate candidate variable nodes in the candidate information model are merged and deduplicated based on the source code variable name and its parent object. Specifically, the system uses the combination of source code variable name and parent object as the deduplication criterion to match candidate variable nodes. When two candidate variable nodes have the same source code variable name and correspond to the same parent object, they are determined to be duplicate candidate variable nodes and merged. This reduces redundant nodes caused by different code snippets repeatedly describing the same variable or the same implementation location, and avoids the erroneous merging of variables with the same name across modules. The output of this step is the deduplicated initial candidate information model.

[0041] S3. Evidence Extraction and Static Verification: Based on the abstract syntax tree, static analysis is performed on the input industrial diagnostic source code to extract verifiable program facts and form a static fact set. The initial candidate information model is matched with the static fact set to construct the evidence item set corresponding to each candidate variable node and candidate method node in the initial candidate information model. The candidate variable nodes and candidate method nodes are scored based on evidence type and evidence weight. At the same time, the data type of the candidate variable nodes is corrected according to the evidence type to obtain a candidate information model with evidence scoring and type correction results.

[0042] To meet the requirements of industrial scenarios, the evidence extraction and static verification steps are based on static code analysis to construct a verifiable set of factual evidence. The system obtains facts such as function call relationships, variable read / write behaviors, object state fields, and log output through AST traversal and structured extraction. These facts are then analyzed and compared with candidate modeling elements to provide factual basis for candidate information models. Based on this, candidate variable nodes undergo deduplication, evidence scoring, and type correction to improve the quality of the final model.

[0043] In some embodiments, the static facts include at least function and method call relationships, variable write relationships, variable read relationships, object state fields, log or print output fields, and type hints. Each static fact retains the source code variable name associated with that fact and its position index in the source code for subsequent evidence alignment, type correction, and candidate model validation.

[0044] The deduplicated initial candidate information model is matched with the static fact set to construct the evidence item set corresponding to the candidate node, and the candidate node is scored based on evidence type and evidence weight. Simultaneously, type correction is performed on the candidate variable nodes according to the type hint information to improve the consistency between the candidate nodes and the source code implementation. The output of this step is a candidate information model with evidence scores and type correction results.

[0045] Furthermore, let the set of static facts be denoted as For any candidate variable node or candidate method node Construct its corresponding set of evidence items. Each piece of evidence is represented as a quadruple:

[0046] in, Indicate the type of evidence. This indicates the source code variable name associated with this piece of evidence. This indicates the index of the evidence item in the source code. This indicates the weight of the corresponding evidence type.

[0047] For candidate nodes Record its type of evidence The following set of evidence items is The set of evidence types is Then the total set of evidence items for the candidate nodes is:

[0048] Define the evidence type hit indicator function:

[0049] The static evidence score is then:

[0050] in, Indicates the first Weight of evidence of a class.

[0051] For candidate variable nodes Its initial data type from the semantic reasoning stage is denoted as Let the set of data type hints obtained from static analysis be denoted as . The fact matching predicate is Then candidate variable nodes The set of matching data type hints is defined as follows:

[0052] in , To infer the data type, For static inference confidence level, This is the source location identifier. When... When the static inference data type with the highest confidence is selected, the correction result is taken.

[0053] S4. Model Generation and Derivation: Based on the evidence score, candidate information models are screened and decided, and candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships are retained to obtain the final OPC UA information model.

[0054] Under the joint constraints of semantic candidates and static evidence, the model generation and export steps construct candidate OPC UA nodes and their reference relationships. The final model elements are selected through evidence scoring and threshold decision-making, generating a standardized OPC UA information model. The final result is exported in XML format, and a server-side integrable deployment file is also generated, achieving automated conversion from source code diagnostic information to a standardized information model.

[0055] In some embodiments, candidate information models are screened and decided upon based on the obtained evidence scoring results. Candidate nodes and their corresponding structures that meet the set conditions are retained to determine the final OPC UA information model, thereby achieving factual constraints and credible screening of candidate results for the large language model. The output of this step is the final OPC UA information model.

[0056] Specifically, for candidate nodes Its evidence score is determined by Given this, a realism gating function is introduced. For variable nodes, a matching static evidence of at least one type is required, including write evidence, status field evidence, print evidence, or log evidence. For method nodes, when evidence of invocation is required, In other cases Based on the aforementioned authenticity gating function, candidate nodes are defined. The final decision score is:

[0057] Furthermore, a dual-threshold mechanism is used to map candidate nodes to a three-stage decision outcome:

[0058] in , These are the acceptance threshold and the review threshold, respectively. , The final retained set consists of all that satisfy... The candidate composition. In Candidates in the interval are recorded as items to be reviewed, for manual spot checks or subsequent rule expansion, but are not included in the final exported results.

[0059] The final OPC UA information model obtained in step S8 is exported as an XML file conforming to the OPC UA specification, and server-side integrable deployment files are generated simultaneously, including node mapping files and code frameworks that can be used for server-side integration to build a runnable address space instance. The output of this step is a standardized information model file and the corresponding deployment results.

[0060] The method of this invention will be described below with reference to the UDP diagnostic code. The UDP diagnostic code implements a UDP network communication diagnostic system, including a server-side packet reception statistics module and a client-side sending test module. Its code structure is relatively regular and suitable for demonstrating the automatic modeling process of this invention from source code to OPC UA information model.

[0061] In this embodiment, to reduce the impact of fluctuations in a single run on the results, the automatic modeling process is run independently 10 times, and the following results are all the average of the 10 runs. Figure 4 As shown, the UDP diagnostic code was preprocessed and segmented into 17 code fragments. During the candidate generation stage, the large language model generated an average of 20.1 candidate nodes. After deduplication, the number of nodes was reduced to 18.9. Finally, after static validation, evidence scoring, and decision screening, an average of 12.3 nodes were retained for the final OPC UA information model.

[0062] Furthermore, such as Figure 5As shown in the figure, the correspondence between nodes in the generated XML file and key diagnostic semantics in the UDP diagnostic code is illustrated. It can be seen that the final retained OPC UA nodes are not abstract constructs detached from the implementation context, but rather establish a clear semantic mapping relationship with the key diagnostic information in the source code. This demonstrates that the present invention, while automatically generating standard XML files, retains good source code traceability and implementation interpretability. Furthermore, the figure also shows that after loading the generated XML model onto the OPC UA server, the corresponding nodes can be correctly browsed and accessed in standard clients, indicating that the information model generated by the present invention not only has semantic rationality but also possesses practical deployment and service-oriented publishing capabilities.

[0063] According to another aspect of the present invention, this embodiment also provides an OPC UA automatic modeling system that integrates large language models and static verification, such as... Figure 2 As shown, it includes a code preprocessing module, a semantic extraction and aggregation module, an evidence extraction and static verification module, and a model generation and export module.

[0064] The code preprocessing module is used to perform structured parsing of the input industrial diagnostic source code and segment it according to the syntax structure to form a set of code fragments, and to build global context information based on the set of code fragments.

[0065] The semantic extraction and aggregation module is used to perform semantic understanding on each code segment based on the code segment set and global context information, and to extract semantic information related to industrial diagnosis, forming segment-level semantic summary results for each code segment. The module then uses the large language model to aggregate the segment-level semantic summary results across segments to obtain a system-level object set and generates a namespace plan for each system-level object. Finally, it uses the hierarchical relationships between objects in the system-level object set to generate corresponding hierarchical organizational relationships, forming an initial candidate information model.

[0066] The evidence extraction and static verification module is used to perform static analysis on the input industrial diagnostic source code based on the abstract syntax tree, extract verifiable program facts, and form a static fact set. It matches the initial candidate information model with the static fact set to construct a set of evidence items corresponding to each candidate variable node and candidate method node in each candidate information model in the initial candidate information model. It then scores each candidate variable node and candidate method node in the candidate information model based on evidence type and evidence weight, and corrects the data type of the candidate variable nodes according to the evidence type, thus obtaining a candidate information model with evidence scoring and type correction results.

[0067] The model generation and export module is used to screen and decide on candidate information models based on evidence scores, retain candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships, and obtain the final OPC UA information model.

[0068] The key innovations of this invention are: using the source code of industrial diagnostic software as the direct semantic input for OPC UA automatic modeling, instead of relying solely on point tables, interface documents, configuration files, or communication specifications; utilizing a large language model to complete semantic extraction of code fragments and aggregation of system-level objects, achieving automatic conversion from scattered code semantics to system-level modeling objects; further introducing a static fact extraction and static verification mechanism based on abstract syntax trees to perform deduplication, evidence scoring, and type correction on candidate models, thereby improving the correctness, traceability, and auditability of the generated results; and combining semantic extraction, fact constraints, and model export to directly generate XML files conforming to the OPC UA specification and deployable results on the server side, achieving automated conversion from source code to a deployable OPC UA information model.

[0069] In other embodiments, the input source code of this invention is not limited to Python, but can also be C, C++, Java, or other industrial software implementation languages ​​capable of structured parsing and static analysis. For different languages, corresponding static analysis methods can be used to extract program structure information and factual evidence. For example, for C and C++ code, function relationships, variable definitions, and access relationships can be extracted by combining compiler front-ends such as Clang, syntax tree analysis, and symbol table information; for Java code, program semantics and structural facts can be obtained by combining class structure analysis, method call analysis, and field access analysis; for other languages, structured parsing and static analysis methods adapted to their syntax and compilation mechanisms can also be used to achieve the same purpose. Furthermore, the application of this invention is not limited to industrial diagnostic software source code, but also applicable to other industrial software code that requires standardized information modeling. For example, industrial monitoring software, equipment control software, status monitoring software, fault early warning software, and industrial communication management software all contain status information, control relationships, and monitoring indicators that can be uniformly modeled. For the above-mentioned code, this invention can also complete semantic extraction, factual constraints, and model derivation to generate an information model conforming to the OPC UA specification. Therefore, this invention is not limited to diagnostic semantic modeling, but can be extended to multiple types of modeling objects in the implementation layer of industrial software.

[0070] Compared to traditional techniques that rely primarily on point tables, interface documents, configuration files, or manual sorting to build OPC UA information models, this invention directly uses industrial software source code as modeling input. It can extract key information such as operating status, fault logic, health indicators, and log output from the implementation layer. Therefore, it can improve the consistency between the information model and the actual software implementation, reduce the workload of manual analysis and modeling, improve modeling efficiency, and reduce maintenance costs caused by model update delays.

[0071] This invention introduces a large language model into the source code semantic extraction process, enabling the understanding and aggregation of diagnostic semantics scattered across different files and functions. This transforms implementation-level information, which is difficult to model directly, into system-level objects and candidate modeling elements. Simultaneously, it combines static fact extraction and static verification mechanisms to deduplicate candidate results, score evidence, and correct types. Therefore, it reduces the risk of misidentification arising from relying solely on semantic generation, improving the correctness, traceability, and auditability of the final model. In practical implementation, this invention allows for gradual convergence and reliability screening of candidate modeling results, resulting in a more stable final model structure.

[0072] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0073] It should be noted that, depending on the implementation needs, the various steps described in this application can be broken down into more steps, or two or more steps or parts of the steps can be combined into new steps to achieve the purpose of this invention.

[0074] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. An automatic OPC UA modeling method integrating large language models and static verification, characterized in that: Includes the following steps: S1. Code preprocessing: The input industrial diagnostic source code is structured and segmented according to its syntax to form a set of code fragments. Global context information is then constructed based on the set of code fragments. S2. Semantic Extraction and Aggregation: Based on the code snippet set and global context information, a large language model is invoked to perform semantic understanding on each code snippet, extract semantic information related to industrial diagnosis, and form a snippet-level semantic summary result for each code snippet; the large language model is used to aggregate the snippet-level semantic summary results across snippets to obtain a system-level object set, and generate a namespace plan for each system-level object; using the subordinate relationships between objects in the system-level object set, a corresponding hierarchical organization relationship is generated to form an initial candidate information model; System-level objects include object name, object description, field set, method set, and source code variable name; The initial candidate information model includes candidate object nodes, candidate variable nodes, and candidate method nodes; the object names in the system-level objects are mapped to candidate object nodes, the object status fields and indicator fields in the field set are mapped to candidate variable nodes, and the method set is mapped to candidate method nodes. S3. Evidence Extraction and Static Verification: Static analysis is performed on the input industrial diagnostic source code based on abstract syntax tree to extract verifiable program facts and form a static fact set. The initial candidate information model is matched with the static fact set to construct a set of evidence items corresponding to each candidate variable node and candidate method node in the initial candidate information model. Evidence scores are performed on the candidate variable nodes and candidate method nodes based on evidence type and evidence weight. At the same time, data type correction is performed on the candidate variable nodes according to the evidence type to obtain a candidate information model with evidence scores and type correction results. S4. Model Generation and Export: Based on the evidence score, candidate information models are screened and decided, and candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships are retained to obtain the final OPC UA information model.

2. The OPC UA automatic modeling method integrating large language models and static verification according to claim 1, characterized in that: Each candidate node is also assigned a browsing name, node identifier, and namespace information; In S2, duplicate candidate variable nodes are merged and deduplicated based on the source code variable name and the parent object to which the candidate variable node belongs.

3. The OPC UA automatic modeling method integrating large language models and static verification according to claim 2, characterized in that: Merging and deduplication specifically includes: The candidate variable nodes are matched based on the combination of the source code variable name and its parent object. When two candidate variable nodes have the same source code variable name and correspond to the same parent object, they are determined to be duplicate candidate variable nodes and are merged.

4. The OPC UA automatic modeling method integrating large language models and static verification according to claim 2, characterized in that: In S1, each code snippet retains its corresponding position index; In S3, each static fact retains the source code variable name associated with that static fact and its position index in the source code; The location index is an element in the static fact set.

5. The OPC UA automatic modeling method integrating large language models and static verification according to claim 4, characterized in that: Each static fact in the static fact set includes at least: function and method call relationships, variable write relationships, variable read relationships, object state fields, log or print output fields, and type hint information; Each piece of evidence in the evidence set includes: evidence type, the source code variable name associated with the evidence, the index of the evidence in the source code, and the weight of the corresponding evidence type.

6. The OPC UA automatic modeling method integrating large language models and static verification according to claim 4, characterized in that: The evidence scoring specifically includes: For candidate nodes Record its type of evidence The following set of evidence items is The set of evidence types is Then the total set of evidence items for the candidate nodes is: Candidate Nodes Candidate variable nodes or candidate method nodes; Define the evidence type hit indicator function: The static evidence score is then: in, Indicates the first Weight of evidence of a class.

7. The OPC UA automatic modeling method integrating large language models and static verification according to claim 4, characterized in that: Type correction specifically includes: Candidate variable nodes The initial data type is denoted as ; The data type suggested by static analysis is the fact set. The fact matching predicate is ; Candidate variable nodes Matchable data type hint set Defined as: in , To infer the data type, For static inference confidence level, Source location identifier; when When the static inference confidence is highest, the inferred data type is taken as the type correction result.

8. The OPC UA automatic modeling method integrating large language models and static verification according to claim 6, characterized in that: S4 specifically includes: Candidate Nodes The evidence score is ; Introducing a Reality Gating Function For variable nodes, when at least one type of matching static evidence exists among write evidence, status field evidence, print evidence, or log evidence, For method nodes, when there is evidence of invocation, In other cases ; Candidate Nodes The final decision score is: Candidate elements are mapped to a three-stage decision outcome using a dual-threshold mechanism. D(x) : in , These are the acceptance threshold and the review threshold, respectively. By satisfying The candidate nodes and their corresponding hierarchical organizational relationships are used to obtain the final OPC UA information model.

9. The OPC UA automatic modeling method integrating large language models and static verification according to claim 8, characterized in that: Will satisfy Candidate node records are recorded as items to be reviewed, for manual spot checks or subsequent rule expansion.

10. An OPC UA automatic modeling system integrating large language models and static verification, characterized in that: include: The code preprocessing module is used to perform structured parsing of the input industrial diagnostic source code and segment it according to the syntax structure to form a set of code fragments, and to build global context information based on the set of code fragments; The semantic extraction and aggregation module is used to perform semantic understanding on each code segment based on the code segment set and global context information, and to extract semantic information related to industrial diagnosis, forming segment-level semantic summary results for each code segment; it then uses the large language model to aggregate the segment-level semantic summary results across segments to obtain a system-level object set, and generates a namespace plan for each system-level object; finally, it uses the hierarchical relationships between objects in the system-level object set to generate corresponding hierarchical organizational relationships, forming an initial candidate information model. System-level objects include object name, object description, field set, method set, and source code variable name; The initial candidate information model includes candidate object nodes, candidate variable nodes, and candidate method nodes; the object names in the system-level objects are mapped to candidate object nodes, the object status fields and indicator fields in the field set are mapped to candidate variable nodes, and the method set is mapped to candidate method nodes. The evidence extraction and static verification module is used to perform static analysis on the input industrial diagnostic source code based on the abstract syntax tree, extract verifiable program facts, and form a static fact set. It matches the initial candidate information model with the static fact set to construct the evidence item set corresponding to each candidate variable node and candidate method node in the initial candidate information model. It scores the candidate variable nodes and candidate method nodes based on evidence type and evidence weight, and corrects the data type of the candidate variable nodes according to the evidence type to obtain a candidate information model with evidence scoring and type correction results. The model generation and export module is used to screen and decide on candidate information models based on evidence scores, retain candidate nodes that meet the set conditions and their corresponding hierarchical organizational relationships, and obtain the final OPC UA information model.