PLC function block intelligent clustering and semantic generation method and system and computer equipment

By employing a multi-source fusion and ontology semantic enhancement-based intelligent clustering method for PLC function blocks, combined with multi-agent collaborative decision-making, the problems of non-standard naming, missing annotations, and low clustering accuracy of PLC function blocks are solved. This method achieves automatic classification and semantic unification of function blocks, thereby improving the reusability and intelligence level of PLC engineering projects.

CN121764475APending Publication Date: 2026-03-31HANGZHOU DIANZI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-25
Publication Date
2026-03-31

AI Technical Summary

Technical Problem

Significant differences exist in the naming conventions, semantic expressions, and functional divisions of PLC function blocks among different engineers, projects, or vendors. This leads to difficulties in repeated development and reuse, insufficient knowledge sharing, low clustering accuracy, a lack of a unified ontology semantic mechanism, and a high dependence of semantic generation results on a single prompt word.

Method used

By constructing multi-source fusion functional block semantic embedding, combining ontology semantic enhancement for context-aware clustering, and introducing a multi-agent semantic generation and adjudication mechanism, the semantic description and recommendation information of decision-making functional blocks are integrated to achieve semantic alignment and standardization across projects and domains.

Benefits of technology

It achieves automatic classification and semantic unification of functional blocks, improves the reuse efficiency of functional blocks in different engineering projects, reduces the workload of manual annotation, and improves the clustering accuracy and the stability and consistency of semantic generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121764475A_ABST
    Figure CN121764475A_ABST
Patent Text Reader

Abstract

The invention discloses a PLC function block intelligent clustering and semantic generation method and system and a computer. According to the method, multi-source fusion function block semantic embedding is constructed, context sensing clustering is carried out on the basis of ontology semantic enhancement, a multi-agent semantic generation and decision mechanism is introduced, comprehensive decision making is carried out on output results of different large language models or large language models of different roles, and the multi-source fusion function block semantic enhancement is realized. And thus, functional block semantic description and recommendation information consistent with the ontology concept is obtained. Through semantic clustering and a multi-agent decision-making mechanism, automatic classification and semantic generation of the function blocks are realized, and the intelligent level of function block multiplexing and knowledge management in a PLC engineering project is improved. The method can be widely applied to a PLC programming platform, industrial knowledge graph construction, control logic multiplexing, intelligent recommendation and other scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of industrial automation and artificial intelligence, and in particular to a method, system and computer device for intelligent clustering and semantic generation of PLC function blocks. Specifically, it relates to semantic embedding computation, cluster analysis, ontology mapping and multi-agent semantic generation and decision-making. Background Technology

[0002] In related technologies, the PLC is one of the core control devices in industrial automation systems. It is modularly encapsulated in the form of function blocks to handle different control logic, signal acquisition, processing, and device driving. However, as industrial systems continue to expand in scale, the number of function blocks in PLC projects is growing exponentially. Significant differences exist between different engineers, projects, or manufacturers in naming conventions, semantic expressions, and functional divisions, leading to difficulties in the repeated development and reuse of function blocks and insufficient knowledge sharing.

[0003] The above problems urgently need to be addressed. Summary of the Invention

[0004] To address the aforementioned shortcomings, this application provides a PLC function block intelligent clustering and semantic generation method. By constructing a multi-source fusion function block semantic embedding, context-aware clustering is performed based on ontology semantic enhancement. Furthermore, a multi-agent semantic generation and adjudication mechanism is introduced to comprehensively decide on the output results of different large language models or large language models with different roles. This results in obtaining function block semantic descriptions and recommendation information consistent with ontology concepts, thereby partially or completely improving the problems of insufficient function block semantic understanding, low clustering accuracy, lack of ontology semantic unification mechanism, and high dependence of semantic generation results on a single prompt word.

[0005] This application is implemented as follows.

[0006] Firstly, this application provides a method for intelligent clustering and semantic generation of PLC function blocks, comprising the following steps: S1: Analyze the name, comment text, input and output parameters and internal code logic of the PLC function block, and generate corresponding text semantic embedding, code semantic embedding, pin information semantic embedding and function block type semantic embedding respectively; S2: Fuse the multi-source semantic information generated in S1 to obtain a unified semantic representation of the functional blocks; S3: Based on the PLC domain ontology, perform concept matching and semantic enhancement on the semantic representation of the functional blocks to form a semantic vector aligned with the ontology concepts; S4: Construct a call relationship or engineering dependency graph between functional blocks, and use a graph neural network to enhance the context of the semantic vector obtained in S3; S5: Perform cluster analysis based on the context-enhanced semantic representation to obtain the cluster categories of the functional blocks; S6: For each cluster category, summarize the functional block names, existing annotations, input / output pin descriptions, and functional block logic code summaries within that category to construct category-level input information; S7: Input the category-level input information from S6 into multiple category-level semantic generation agents to generate candidate category names, and then use a scoring and adjudication agent to comprehensively evaluate the candidate category names to determine the final category name; S8: Input the final category name obtained in S7, the function block name, the existing annotation of the function block, the internal logic code of the function block, and the input / output pin information into multiple function block-level semantic generation agents to generate candidate names and candidate annotations for the function blocks respectively. Then, the candidate function block names and candidate annotations are comprehensively evaluated by the scoring and adjudication agent to determine the final function block name and function block annotation.

[0007] In the above implementation process, the function block data is acquired and semantic embedding is constructed. Function block description information from the PLC project is obtained, including the function block name, comment text, input / output parameters, and nested logic structure. Generally, function block information simultaneously contains natural language, structured data, and logic code. This application can improve the multi-source fusion semantic representation method, integrating text semantics, code logic, and pin structure to achieve cross-modal semantic understanding.

[0008] In conjunction with the first aspect, in some possible implementations, the generation of the multi-source semantic embedding includes the following steps: S101: Encode the name and annotation of the function block using a text encoding model to obtain a text semantic vector; S102: Perform semantic parsing on the ladder diagram or structured text code, and generate a code semantic vector through a code embedding model; S103: Parametrically represent the type, direction, data length, and other attributes of the input and output pins of the function block, and encode them into pin information semantic vectors; S104: Perform embedding modeling on the function type or category to which the function block belongs, and generate a function block type semantic vector.

[0009] In conjunction with the first aspect, in some possible implementations, the ontology semantic enhancement of S3 includes the following process: S201: Extract ontology concept vectors such as functions, categories, actions, controlled objects, and signal types from the PLC domain ontology; S202: Perform similarity calculation and align the semantic representation of the function block obtained in S2 with the ontology concept vectors; S203: Perform weighted enhancement on the semantic representation of the function block according to the alignment weights to obtain the semantically enhanced function block vector.

[0010] In conjunction with the first aspect, in some possible implementations, the context enhancement of S4 includes: Construct a functional block dependency graph, where nodes represent functional blocks and edges represent calling relationships, data interaction relationships, or project layout relationships; use a graph neural network to aggregate the semantic representations of adjacent nodes in the dependency graph to obtain context-enhanced semantic representations of functional blocks.

[0011] In the above implementation process, the ontology semantic mapping and vector enhancement can avoid initial semantic vector deviations caused by incomplete original information, non-standard naming, or missing annotations of functional blocks. This application introduces a semantic correction mechanism in the semantic vector construction and ontology mapping process. During the ontology semantic enhancement stage, the functional block vectors do not directly depend on the initial clustering labels, but are softly aligned based on the similarity between the semantic vectors and the ontology concept vectors. Through enhancement, the semantic representation of the functional block can automatically converge towards the closest ontology concept, achieving adaptive correction of the semantic space. This mechanism ensures that even if the initial clustering stage results in category inference errors due to textual noise, ontology enhancement can still reposition the semantics of the functional blocks through the directional information of the concept vectors, thereby effectively avoiding the problem of cumulative amplification of clustering errors.

[0012] In conjunction with the first aspect, in some possible implementations, the category-level semantic generation agent of S7 includes: Expert semantic generation agent based on rule templates and ontology concepts; Generating intelligent agents based on category names from a large language model; A phrase extraction agent based on statistical features of functional block names and annotations within a class.

[0013] In conjunction with the first aspect, in some possible implementations, the functional block-level semantic generation agent of S8 includes: The key information extraction agent is used to extract the control objects, actions, and key parameters involved in the function block; the logic summary agent is used to summarize the logic of the function block code and generate function block description text; and the normalization generation agent is used to generate function block names and comments that conform to the engineering naming conventions under the category name constraint.

[0014] In conjunction with the first aspect, in some possible implementations, the scoring and adjudicating agents of S7 and S8 perform a comprehensive evaluation based on the following indicators: Consistency with ontology concepts; semantic matching with cluster categories; coverage of functional block logical semantics; linguistic standardization and engineering readability of candidate names and annotations.

[0015] In the above implementation process, a context enhancement mechanism is introduced based on semantic embedding, and a functional block dependency graph is constructed using the nested logical structure and calling relationships between functional blocks. Graph neural networks are used to model the contextual interactions between functional blocks, obtaining context-enhanced semantic representations. The set of context-enhanced semantic embeddings is then used to cluster functional block categories. The clustering objective is to maximize the semantic similarity of functional blocks within the same category and maximize the semantic gap between different categories, thereby obtaining a semantically consistent and engineering-interpretable functional block category division.

[0016] In the above implementation process, after completing the functional block clustering and ontology concept matching, this application adopts a multi-agent collaborative mechanism to automatically determine the cluster category name and intelligently generate information such as the names and annotations of each functional block within the category. This mechanism includes multiple semantic generation agents and semantic adjudication agents. The semantic generation agents generate multiple candidate semantic results for each category or functional block based on different generation strategies such as rule templates, language models, or phrase extraction. The semantic adjudication agents comprehensively evaluate each candidate name or annotation and select the final result that best meets the requirements of semantic consistency, ontology constraints, and engineering specifications. This achieves multi-agent collaborative semantic generation and decision optimization.

[0017] Secondly, this application provides a PLC function block intelligent clustering and semantic generation system, including: a multi-source semantic embedding module, a semantic fusion module, an ontology semantic enhancement module, a context enhancement module, a clustering analysis module, a category-level semantic generation module, a function block-level semantic generation module, and a scoring and adjudication module.

[0018] In the above implementation process, the semantic embedding module is used to acquire the text information, logic code and pin structure of the functional blocks and generate multimodal semantic vector representations; the ontology mapping module is used to align the semantic vectors of the functional blocks with ontology concepts in the field of industrial control to complete semantic enhancement and correction; the clustering analysis module is used to cluster the functional blocks based on the enhanced semantic vectors to obtain a set of categories; and the semantic generation module is used to generate category names and names and annotations of each functional block within a category based on a multi-agent collaborative mechanism, including candidate semantic generation and scoring adjudication processes.

[0019] In conjunction with the second aspect, in some possible implementations, the multi-source semantic embedding module includes: Text semantic processing unit; code semantic processing unit; pin information semantic processing unit; function block type semantic processing unit.

[0020] Thirdly, this application provides a computer device including a processor and a memory, wherein the memory stores a program, and the program employs the aforementioned PLC function block intelligent clustering and semantic generation method when the processor performs its work, and / or the aforementioned PLC function block intelligent clustering and semantic generation system of the computer device.

[0021] The beneficial effects of this invention are: By combining ontology semantic mapping and semantic embedding, this application achieves semantic alignment and standardization of functional blocks across projects and domains to a certain extent. This application can be widely applied to scenarios such as PLC programming platforms, industrial knowledge graph construction, control logic reuse, and intelligent recommendation, and has significant engineering practical value and promotional significance. Attached Figure Description

[0022] Figure 1 This is a schematic diagram of the overall process of a PLC function block intelligent clustering and semantic generation method provided in an embodiment of the present invention.

[0023] Figure 2 This is a flowchart illustrating the multi-source semantic embedding construction process of functional blocks provided in an embodiment of the present invention.

[0024] Figure 3 This is a schematic diagram of the context enhancement and semantic clustering analysis process provided in the embodiments of the present invention.

[0025] Figure 4 This is a schematic diagram of the multi-agent collaborative semantic generation and scoring adjudication process provided in an embodiment of the present invention. Detailed Implementation

[0026] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0027] It should be noted that in this article, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, without necessarily requiring or implying any such actual relationship or order between these entities or operations. Similarly, words such as "a" or "one" do not indicate a quantity limitation, but rather the presence of at least one; "multiple" indicates two or more. Likewise, words such as "step one" and "step two" are used only to indicate a feature or operation, without necessarily requiring or implying a relationship or order between these features or operations.

[0028] In this application, the term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0029] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.

[0030] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0031] PLC function blocks are the core units of modular programming in industrial automation control systems. They achieve efficient control by encapsulating reusable logic, and their core value lies in code reusability, standardized process design, and ease of maintenance. A function block is an independent unit that encapsulates specific control logic, supports parameterized calls, significantly improves code reusability, and reduces redundancy. For example, the FB block in the Mitsubishi FX5U can encapsulate motor start / stop logic and call it multiple times. Specifically, function blocks include input / output interfaces, internal variable storage, and logic processing functions, supporting dynamic instantiation. PLC function blocks include basic function modules, such as a counter module for industrial counting scenarios, such as a beverage filling line using CTU instructions to count 600 bottles per minute; and an edge detection module for generating scan cycle pulse signals. In addition, PLC function blocks include complex control modules, such as the Omron CP1W-AD042 module for analog signal processing, which converts 4-20mA signals to digital signals, including filtering and range conversion logic; and a PID control module for temperature closed-loop control. PLC function blocks are also widely used in industrial scenarios. For example, data recording function blocks for production monitoring store floating-point numbers into arrays for analyzing equipment operation trends. Equipment control can integrate solenoid valve control, position detection, and fault alarms using standardized cylinder control modules, reducing repetitive development costs. Quality control can achieve analog quantity engineering value conversion through SCL instructions, ensuring the accuracy of pressure sensor data.

[0032] The inventors believe that existing functional block classification and management methods mainly rely on manual experience for classification, labeling, and maintenance. For example, functional blocks are manually categorized based on their names, annotations, or logical connections. These methods suffer from the following problems: high reliance on manual intervention, requiring developers to possess strong professional experience and domain knowledge, making it difficult to adapt to the rapid management needs of thousands of functional blocks in large-scale PLC projects; weak semantic understanding, as functional block names and annotations often contain abbreviations, ambiguities, or cross-domain terminology differences, making it difficult for keyword-based classification methods to accurately capture their deep semantic relationships; lack of a unified knowledge system, with different companies or projects lacking a common semantic ontology for functional blocks, leading to semantic inconsistencies between functional blocks and hindering cross-project or cross-industry knowledge reuse; low clustering accuracy, as traditional clustering algorithms rely solely on surface features or vector distances, making it difficult to combine the contextual semantics and control logic structure information of functional blocks, resulting in unstable clustering results; and insufficient automatic naming and annotation capabilities, as the lack of unified semantic representation and naming conventions often leads to verbose, unclear, or non-compliant functional block names, hindering project collaboration and later maintenance.

[0033] In summary, existing technologies for semantic clustering and intelligent generation of PLC function blocks have the following shortcomings: the professional semantic structures and ontology knowledge systems of the industrial control field have not been fully constructed and utilized; multimodal information such as function block logic, text, and interfaces lacks unified modeling and fusion; and the semantic generation results lack ontology-based consistency constraints and decision-making mechanisms, heavily relying on single prompt words. Therefore, a new intelligent clustering and semantic generation method for PLC function blocks is urgently needed, which can combine ontology semantics with multi-agent collaborative decision-making mechanisms to achieve automatic classification, semantic unification, and intelligent recommendation of function blocks, thereby improving the reusability, scalability, and intelligence level of industrial automation systems.

[0034] To address the aforementioned technical issues, this application provides a novel intelligent clustering and semantic generation method for PLC function blocks. By combining ontology semantics with a multi-agent collaborative decision-making mechanism, it addresses to some extent the problems of insufficient semantic understanding of function blocks, low clustering accuracy, lack of a unified ontology semantic mechanism, and high dependence of semantic generation results on a single prompt word.

[0035] For details, please refer to Figure 1 , Figure 1 This is a schematic diagram illustrating the overall process of a PLC function block intelligent clustering and semantic generation method provided in an embodiment of the present invention. As shown in the figure, the PLC function block intelligent clustering and semantic generation method includes at least the following steps: S1 Function Block Data Acquisition and Semantic Embedding Construction: Collect relevant information about function blocks from PLC engineering projects, including function block name, comment text, input / output parameter types, signal direction, internal ST code or ladder logic, and the type of function block. After preprocessing the above multi-source information, text semantic embedding, code semantic embedding, pin information semantic embedding, and function block type semantic embedding are generated respectively. S2 Ontology Semantic Mapping and Vector Enhancement: Based on the ontology of PLC and industrial control, an ontology concept set such as function type, control object, signal type, and process link is constructed. The semantic vector of the function block obtained in step S1 is similar to the ontology concept vector and softly aligned to form the semantic representation of the function block after ontology enhancement, thereby realizing semantic correction.

[0036] S3 Context Enhancement and Semantic Clustering Analysis: A functional block dependency graph is constructed using the calling, nesting, or signal interaction relationships between functional blocks in a PLC project. The ontology-enhanced semantic vectors obtained in step S2 are then enhanced with context based on a graph neural network. Finally, clustering analysis is performed on the context-enhanced semantic vectors to obtain a set of cluster categories for the functional blocks.

[0037] S4 multi-agent collaborative semantic generation, based on clustering results, summarizes the functional block names, original annotations, input / output pin descriptions, and logic code summaries within each cluster to form category-level input information. This input information is then fed into multiple category-level semantic generation agents to obtain multiple candidate category names. A scoring and adjudicating agent then determines the final category name. Subsequently, the final category name, along with the functional block names, original annotations, logic code summaries, and input / output pin information, is fed into multiple functional block-level semantic generation agents to generate multiple candidate functional block names and candidate annotations. The scoring and adjudicating agent then comprehensively scores these candidate names and outputs the final functional block name and functional block annotation.

[0038] Through the above steps, automatic classification and semantic unification of PLC function blocks are achieved, reducing the workload of manual annotation and improving the reuse efficiency of function blocks in different engineering projects.

[0039] like Figure 2 This is a flowchart illustrating the construction process of multi-source semantic embedding of functional blocks provided in an embodiment of this application. Figure 2 As shown, this exemplary embodiment first collects data from the function blocks in the PLC project. The collected data includes the function block name and comment text, the internal logic of the function block (text code or ladder diagram), input / output pin information, and the toolbox to which the function block belongs. After data collection, the following sub-steps are executed: S101 text information embedding concatenates the function block name with the annotation text to form the input text, which is then input into the BERT text encoding model to obtain the text embedding vector.

[0040] The vector is used to capture the semantic features of the function block's purpose, application scenario, and functional intent.

[0041] S102 code logic embedding: Optionally, if the functional block contains ST or other text-based code, then input it into the CodeBERT model to obtain a code-level semantic vector.

[0042] Optionally, if the functional block is represented by a ladder diagram, the contacts, coils, and logic operators in the ladder diagram are converted into graph nodes, and then the signal flow and control flow relationships are converted into graph edges to construct a logical semantic graph. GraphCodeBERT is then used to extract the semantic embedding of the graph structure.

[0043] The S103 pin embeds input / output information, converting the input / output ports into natural language descriptions according to templates. In some possible implementations, such as "IN1 is REAL input; OUT is BOOL output ...", this information is input into the BERT model to obtain the interface semantic vector.

[0044] S104 function block category embedding maps discrete category labels to trainable continuous vectors.

[0045] in This is the category embedding matrix.

[0046] S105 Multi-Source Feature Fusion: Multi-source features are fused using trainable weights.

[0047] in, Let be the semantic vector of the i-th functional block. For trainable weights, their initial values ​​can be set to uniform distribution or random initialization.

[0048] During the training phase, this application embodiment constructs three types of training signals and integrates the three types of signals into a joint loss function to optimize the fusion weights and modality vectors.

[0049] Specifically, (1) Contrastive learning loss: In order to capture the semantic similarity between different functional blocks, this invention constructs positive and negative sample pairs, wherein positive sample pairs are functional blocks from the same category, the same ontology concept, or with similar uses, and negative sample pairs are functional blocks with large semantic differences. An InfoNCE-type contrastive loss function is adopted:

[0050] Where cos(·) is the cosine similarity; This refers to the temperature parameter. Through contrastive learning, the model can automatically enhance semantically critical modalities (such as code or pin information) and reduce the influence of irrelevant noise modalities (such as partial annotation noise). (2) Ontology Consistency Loss: In order to ensure that the semantic vectors are consistent with the semantic system of industrial control, this embodiment introduces ontology concept vectors. As semantic anchors, the consistency loss is calculated between the semantic vector of the functional block and its corresponding ontology concept vector:

[0051] in This represents the set of ontology concepts that have semantic correspondence with functional blocks, including functional type concepts, control object concepts, signal category concepts, etc. This loss enables the model to automatically enhance the feature modalities most relevant to the domain semantics, making the final fused vector more professional and stable.

[0052] (3) Classification loss: If the training set contains manually labeled or historical project function category labels. Cross-entropy loss can be added:

[0053] in This is the category prediction matrix. This loss provides additional supervision signals, improving training stability, and is especially suitable for engineering scenarios with complex functional block type structures.

[0054] This application synthesizes the above losses into a joint loss function:

[0055] in , , As adjustable hyperparameters, the weights of different losses can be adjusted according to task requirements. Adam is used for parameter updates, and iterative optimization is performed according to the following formula:

[0056] All weights converge automatically during training without the need for manual intervention.

[0057] The S2 ontology semantic mapping and vector enhancement: To address the semantic bias caused by non-standard naming of PLC function blocks and missing comments, this invention introduces an ontology enhancement mechanism.

[0058] Generally, constructing an industrial control ontology concept includes: (1) Function type (counting, timing, PID, etc.) (2) Controlled objects (motors, valves, handling equipment) (3) Signal type (analog signal, digital signal, alarm signal) (4) Process actions (heating, cooling, conveying, etc.) Input the ontology text into BERT to obtain the ontology vector:

[0059] And calculate the soft alignment between the function block and the body:

[0060] This enables the semantic vectors of functional blocks to automatically converge to the nearest domain concept, achieving semantic correction and unification.

[0061] like Figure 3 The diagram shown is a schematic of the context enhancement and semantic clustering analysis process provided in an embodiment of the present invention.

[0062] like Figure 4 The diagram shown is a schematic of the multi-agent collaborative semantic generation and scoring adjudication process provided in an embodiment of the present invention.

[0063] By leveraging the call relationships between other functional blocks within the code of a functional block, and combining information such as variable read / write and ontology mapping, a heterogeneous graph is constructed, and HGT is used for contextual semantic enhancement.

[0064] Specifically, it includes the following steps: S301 Function Block Call Relationship Extraction: The call relationship between function blocks not only exists in structured text-based programming languages, but also widely exists in graphical programming languages ​​of PLC engineering projects, such as ladder diagrams and function block diagrams.

[0065] To unify the handling of different representation forms, this invention performs lightweight static parsing on both types of code and abstracts the parsing results into a unified call relationship triple:

[0066] in The object representing the starting point of the relationship. Represents the endpoint of the relationship. Indicates the relationship type between objects, used to describe and The semantic meanings between them, such as "call" (to invoke) and "called_by" (to be invoked).

[0067] The extraction results from textual and graphical languages ​​are unified and merged into a set of relations.

[0068] This set will serve as the foundational data for the heterogeneous graph construction phase.

[0069] S302 Constructs a heterogeneous graph structure, building a function block dependency graph based on the set of relationships:

[0070] in A set of functional block nodes. Indicates nesting or calling relationships.

[0071] S303 Graph Neural Network Context Enhancement: In Semantic Embedding Building upon this foundation, a context enhancement mechanism is introduced. Through a graph neural network, the call relationships between functional blocks, variable read / write relationships, and program structure relationships all contribute to the semantic representation. After context enhancement, the following is obtained:

[0072] The GNN can employ a Heterogeneous Graph Transformer (HGT) to distinguish different node types and relationship types, and learn the contributions of neighboring nodes to the current node based on an attention mechanism. Through HGT, the semantic vector of a functional block will fuse its upstream and downstream semantics, control link information, and ontology association information.

[0073] The final set of context-enhanced semantic embeddings is obtained as follows:

[0074] S304 Clustering Analysis: Context-enhanced semantic embeddings are input into the unsupervised clustering algorithm DBSCAN. DBSCAN automatically identifies the semantic density structure between functional blocks, maximizing semantic similarity within a class and increasing semantic distance between classes. Abnormal or isolated functional blocks are automatically separated as noise points. The final result is a set of functional block categories with good semantic interpretability and engineering consistency.

[0075] The present invention utilizes a multi-agent collaborative decision-making mechanism to achieve semantic generation at two levels. Specifically, one is to generate category names for the category-level semantics obtained from clustering, and the other is to generate functional block names and annotations for each functional block within the category.

[0076] Among them, category-level semantic naming is the first stage, which first constructs a class-level context based on the set of functional blocks corresponding to the category. and will Input a multi-agent collaborative decision-making mechanism to determine the final category name for that category.

[0077] After obtaining the category names, the function block name and annotation generation serves as the second stage, combining the determined category names with the semantic information of the function blocks themselves to form the input. Then, the multi-agent collaborative decision-making mechanism is input again. Through the collaborative action of multiple semantic generation agents and scoring and adjudication agents, the final name and annotation of each functional block are obtained.

[0078] Therefore, the multi-agent mechanism of this invention forms a two-level semantic generation structure of "class level first, then block level", which not only ensures the consistency and stability of class-level semantics, but also ensures the professionalism and accuracy of functional block-level names and annotations.

[0079] The two stages will be explained in detail below.

[0080] (a) Class-level semantic naming For each category First, we summarize the relevant information of all functional blocks in this category and construct its class-level context set:

[0081] (1) Generation of candidate class names by multi-agent system Set up K class-level semantic generation agents:

[0082] in, The number of agents generated for class-level semantics; the agent for the k-th class. Different generation strategies can be used, for example: : Rule-based and module-based expert agents, which use predefined naming templates and ontology concepts to... Perform matching to generate candidate category names that are biased towards normalization; Generative agents based on language models, with a pre-trained large language model as the core, according to... Natural language descriptions are used to generate category names and descriptions; A phrase-based agent extracts high-frequency phrases or typical expressions from the names and annotations of functional blocks within a class as candidate class names.

[0083] In practical implementation, the aforementioned agents can be implemented using the same large-scale language model with different prompt word templates, input feature selections, and decoding parameter configurations. No. An intelligent agent For the input, generate a candidate category name and its description:

[0084] in, For intelligent agents For category The given candidate class names.

[0085] Optionally, the scoring agent decides the final class name, including setting up a scoring and deciding agent E to comprehensively evaluate each candidate class name. The scoring process is as follows:

[0086] For the scoring agent, the candidate class names The overall score.

[0087] The final category name and description are obtained by selecting the candidate with the highest score:

[0088]

[0089] in For category The optimal candidate index; For category The final category name.

[0090] Optionally, the generation of function block names and annotations includes categories. Functional blocks within The semantic generation input is:

[0091] Optionally, the multi-agent generation of candidate names and annotations includes setting... Each functional block generates an intelligent agent:

[0092] in Indicates the first A large language model intelligent agent.

[0093] Optionally, the first A smart agent Different generation strategies can be used. For example, Key information extraction agent, used to extract key information from... The system automatically identifies the elements involved in the function block, such as the controlled object, controlled variable, main action, and key parameters. Based on the extracted key information, it generates structured phrases to form candidate function block names and brief annotations. Logical summary agents are used to summarize data. The key points of the function block logic code or ladder diagram summary and input / output pin information are summarized to generate a natural language description that can fully reflect the control logic of the function block. Then, a concise name is extracted from the description and a more detailed annotation is given. Normalization and compression of intelligent agents, by category name Constrained by the preset project naming conventions, the candidate texts extracted or summarized from B1 and B2 are rewritten in a standardized manner and their lengths are compressed to generate shorter names and concise comments that are more in line with the company's naming conventions and suitable for use in the program.

[0094] Each agent is based on input Generate a candidate name and comment:

[0095] in Candidate function block name, Comment out the candidate function block.

[0096] Optionally, the final name and annotation of the scoring agent's decision include setting the scoring agent. Used for a comprehensive evaluation of candidate names and annotations:

[0097] in, The evaluation criteria for the candidate names and comments include the degree to which they reflect the logic code, whether they accurately explain the meaning of the pins, and whether they conform to the category name. Its semantic features, language norms, etc.

[0098] The final function block name and annotation are as follows:

[0099]

[0100] in, Functional block The final name; Function block The final annotation.

[0101] pass Figure 1 As shown in the overall process, this invention can realize multimodal semantic modeling, context structure enhancement, unsupervised clustering, and multi-agent collaborative generation of PLC function blocks, thereby completing the automatic classification, semantic unification, and naming standardization of function blocks.

[0102] By combining ontology semantic mapping and semantic embedding, this invention achieves semantic alignment and standardization of functional blocks across projects and domains, possessing semantic correction capabilities. Through the soft alignment mechanism of ontology concept vectors, the semantic vectors of functional blocks can automatically converge to the correct semantic category even when the initial text information is incomplete, the naming noise is large, or the annotation is distorted, thereby significantly improving the stability and accuracy of clustering and semantic generation. By introducing a multi-agent collaborative semantic generation and adjudication mechanism, multiple candidate semantic results are comprehensively scored and selected, significantly improving the accuracy, stability, and consistency of the large language model in semantic generation tasks in the PLC domain. Through semantic clustering and multi-agent decision-making mechanisms, automatic classification and semantic generation of functional blocks are achieved, improving the level of intelligent functional block reuse and knowledge management in PLC engineering projects.

[0103] This invention can be widely applied to scenarios such as PLC programming platforms, industrial knowledge graph construction, control logic reuse and intelligent recommendation, and has significant engineering practical value and promotion significance.

[0104] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for PLC function block intelligent clustering and semantic generation, characterized in that, Comprising the following steps: S1: Analyzing the name, comment text, input and output parameters and internal code logic of the PLC function block, respectively generating corresponding text semantic embedding, code semantic embedding, pin information semantic embedding and function block type semantic embedding; S2: Fusing the multi-source semantic information generated by S1 to obtain a unified function block semantic representation; S3: Based on the PLC domain ontology, concept matching and semantic enhancement are performed on the function block semantic representation to form a semantic vector aligned with the ontology concept; S4: Building a calling relationship or engineering dependency graph between function blocks, and using a graph neural network to enhance the context of the semantic vector obtained in S3; S5: Based on the context-enhanced semantic representation, clustering analysis is performed to obtain the clustering category of the function block; S6: For each clustering category, the function block name, existing function block annotation, input and output pin description and function block logic code summary in the category are summarized to build a category-level input information; S7: The category-level input information of S6 is input into multiple category-level semantic generation agents to generate candidate category names, and the candidate category names are comprehensively evaluated by a scoring arbitration agent to determine the final category name; S8: The final category name obtained in S7 and the function block name, existing function block annotation, function block internal logic code and input and output pin information are input into multiple function block-level semantic generation agents to generate candidate function block names and candidate annotations, and the candidate function block names and candidate annotations are comprehensively evaluated by a scoring arbitration agent to determine the final function block name and function block annotation.

2. The method of claim 1, wherein the method further comprises: The generation of the multi-source semantic embedding comprises the following steps: S101: The function block name and annotation are encoded using a text encoding model to obtain a text semantic vector; S102: The ladder diagram or structured text code is semantically parsed to generate a code semantic vector through a code embedding model; S103: The type, direction, data length and other attributes of the input and output pins of the function block are parameterized and represented, and are encoded into a pin information semantic vector; S104: The function type or category to which the function block belongs is embedded and modeled to generate a function block type semantic vector.

3. The method of claim 1, wherein the method further comprises: The ontology semantic enhancement of S3 includes the following processes: S201: Extracting function, category, action, control object, signal type and other ontology concept vectors from the PLC domain ontology; S202: Through similarity calculation, the function block semantic representation obtained in S2 is conceptually aligned with the ontology concept vector; S203: The function block semantic representation is weighted and enhanced according to the alignment weight to obtain the function block vector after semantic enhancement.

4. The method of claim 1, wherein the method further comprises: The context enhancement of S4 includes: Building a function block dependency graph, in which the nodes represent function blocks and the edges represent calling relationships, data interaction relationships or engineering arrangement relationships; Using a graph neural network to aggregate the semantic representations of adjacent nodes in the dependency graph to obtain the context-enhanced function block semantic representation.

5. The method of claim 1, wherein the method further comprises: The category-level semantic generation agent of S7 includes: An expert-type semantic generation agent based on rule templates and ontology concepts; A category name generation agent based on a large language model; A phrase extraction agent based on intra-class function block name and annotation statistical features.

6. The method of claim 1, wherein the method further comprises: The function block level semantic generation agent of S8 comprises: A key information extraction agent for extracting control objects, actions and key parameters involved in the function block; a logic summary agent for summarizing the function block code logic to generate function block description text; and a normalization generation agent for generating function block names and annotations conforming to engineering naming specifications under the constraint of category names.

7. The method of claim 1, wherein the method further comprises: The scoring and ruling agent of S7 and S8 is based on the following indicators for comprehensive evaluation: Consistency with ontology concepts; semantic matching degree with clustered categories; coverage degree of function block logic semantics; language specification and engineering readability of candidate names and annotations.

8. A PLC function block intelligent clustering and semantic generation system, comprising the method of any one of claims 1 to 7, characterized in that, Comprise: A multi-source semantic embedding module, a semantic fusion module, an ontology semantic enhancement module, a context enhancement module, a clustering analysis module, a category level semantic generation module, a function block level semantic generation module, and a scoring and ruling module.

9. The PLC function block intelligent clustering and semantic generation system of claim 8, wherein, The multi-source semantic embedding module comprises: A text semantic processing unit; a code semantic processing unit; a pin information semantic processing unit; and a function block type semantic processing unit.

10. A computer device comprising a processor and a memory, wherein the memory stores a program, and the program adopts the method of any one of claims 1-7 when the processor executes the program, and / or the computer device comprises the PLC function block intelligent clustering and semantic generation system of claim 9.