A structured code generation method, electronic device, and storage medium based on multi-role intent sketch fusion
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-25
- Publication Date
- 2026-08-14
AI Technical Summary
[0003]一是缺乏对跨角色需求表达的结构化统一建模能力;
[0013] Compared with existing technologies, this invention identifies and integrates heterogeneous intent sketches submitted by different roles, constructs "structured semantic intent" through clustering, intent normalization, and structured expression, and uses this as the driving force to realize task code generation, test generation, and consistency verification. Based on this, a ternary mapping of "intent-task code-test" is established, supporting tracking, verification, and conflict prompts. This not only effectively solves the problems of existing development tools, such as lack of cross-role requirement modeling, lack of end-to-end logical alignment and module connectivity, and lack of traceability of task code, tests, and original business intent, but also significantly improves collaborative development efficiency and consistency. It also has high versatility and scalability, and has outstanding engineering transformation value.
Smart Images

Figure CN122569887A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software development technology, and in particular to a structured code generation method, electronic device and storage medium based on multi-role intent sketch fusion. Background Technology
[0002] Code generation technologies in the software development field today have significantly improved development efficiency and software quality through automation. However, existing technologies have the following shortcomings when dealing with multi-role information processing:
[0003] First, there is a lack of structured and unified modeling capabilities for expressing cross-role requirements; Second, the generated content often remains at the fragment level, lacking end-to-end logical alignment and module connectivity; Third, the lack of a traceable and verifiable consistency mapping mechanism between code, tests, and original business intent makes the generated content difficult to maintain and verify. Summary of the Invention
[0004] Therefore, the purpose of this invention is to provide a structured code generation method based on the fusion of multi-role intent sketches. This method extracts intent sketch expressions from multiple roles such as front-end, back-end, and testing to construct a "structured semantic intent", and uses this as the driving force to realize code generation, test generation and consistency verification; it is used to solve key problems such as isolated fragments, broken intents and untraceable mappings in existing technologies.
[0005] A structured code generation method based on multi-role intent sketch fusion includes the following steps: S10: Preprocess the obtained character intention sketches to obtain a multi-character intention material pool; S20: Align, semantically normalize, and aggregate cross-role intentions in the multi-role intention material pool to obtain a structured semantic intention spectrum; S30: Drive the association generation of multi-role corresponding codes with structured semantic intent spectrum, and generate complete task code that integrates the logical chain of multiple roles; S40: Generate test cases based on the structured semantic intent spectrum and construct semantic link verification logic to verify whether the task code is consistent with the input-output relationship, business constraint relationship, and semantic link relationship in the structured semantic intent spectrum. If they match, proceed to step S50; If there is no consistency, an anomaly is identified: S50: Based on the structured semantic intent spectrum and the generated task code and test cases, the mapping relationship between the structured semantic intent spectrum, task code and test cases is associated and stored to establish a structured "intent-task code-test" ternary mapping graph.
[0006] Furthermore, the preprocessing in step S10 includes the following sub-steps: SA1: Define each role and generate a role set; SA2: Summarize all intent sketches submitted by each role and generate a set of intent sketches for each role; SA3: Perform type identification on the intention sketch set of each character and generate an intention sketch type set for each character; SA4: Using a unified standardization function, the intent sketches of each character are processed into a unified format through type recognition and format conversion, resulting in a multi-character intent material pool and a standardized multi-character intent sketch set.
[0007] Further, step S20 includes the following sub-steps: S21: Perform semantic vectorization on each intention sketch in the standardized multi-role intention sketch set to obtain the semantic vector of each intention sketch; S22: Convert the semantic vectors of each intention sketch into high-dimensional semantic vectors to obtain the high-dimensional semantic vectors of each intention sketch; S23: Calculate the cosine similarity of the high-dimensional semantic vectors of any intention sketch pair. If the cosine similarity is greater than or equal to the similarity threshold, then set the intention sketch pair as a semantically related intention sketch pair. S24: Construct a semantic similarity graph G=(V,E) based on the semantic association intent sketch, and obtain several semantic clusters Ci; S25: Extract "intent semantic tags" based on semantic clustering results, generate structured intent nodes and node relationships, and construct a structured semantic intent spectrum.
[0008] Furthermore, the "intent semantic tag" in step S25 is obtained in the following manner: Keyword co-occurrence analysis: High-frequency verb-object pairs are extracted from all intent sketch descriptions within each semantic cluster Ci, and their frequency of occurrence and co-occurrence patterns are statistically analyzed; Semantic representation of cluster center vectors: The mean of the semantic vectors of all intent sketches within each semantic cluster Ci is calculated, and this mean is used as the cluster center v of that semantic cluster Ci. i-center ; The keyword co-occurrence analysis results are combined with the semantic representation results of the cluster center vector, and a standardized label is generated by template induction as the "intent semantic label" of the cluster. The "intent semantic label" is used to characterize the business intent semantic category corresponding to the semantic cluster Ci. The structured intent node is obtained in the following way: Based on the "intent semantic label" corresponding to each semantic cluster Ci and the intent sketch content in the cluster, the triggering behavior, input data items, output result items, participating roles and source fragment information are extracted to generate the corresponding structured intent node, and a unique intent identifier is configured for the structured intent node; the unique intent identifier is used to realize node association, relationship reference, code mapping, test binding and semantic chain tracing in the structured semantic intent spectrum.
[0009] Furthermore, step S20 also includes: S26: Calculate the relationship between each high-dimensional semantic vector and the cluster center v in semantic clustering Ci. i-center The cosine similarity, if If the sample is a semantically drifted sample, the high-dimensional semantic vector will be removed from the current cluster.
[0010] Further, step S24 includes the following sub-steps: S241: Construct a semantic similarity graph G=(V,E) based on the semantically associated intent sketches, where: V is the set of high-dimensional semantic vectors of the intent sketches; E is the set of edges that satisfy the cosine similarity greater than or equal to the similarity threshold; the weight of the edge is the cosine similarity. S242: Use HDBSCAN to perform density clustering on the semantic similarity graph G=(V,E).
[0011] Further, step S30 includes the following sub-steps: S31: Extract various types of structured intents from the structured semantic intent spectrum; S32: Generate rules for the structured behaviors corresponding to each role for each type of structured intent; S33: Associate and arrange the structured behavior generation rules of different roles belonging to the same structured intent node according to the "trigger-input-output" logic to generate a complete functional logic chain across roles and corresponding task code; Step S40 includes the following sub-steps: S41: Generate test cases and test assertions based on the structured intents of the structured semantic intent spectrum. The test assertions refer to the result verification logic generated by the output result items in the structured intents, which are used to verify whether the execution result of the task code conforms to the expected output corresponding to the structured intents. S42: Compare the output of the current node and the input of the next node in the cross-intent link of the test case: If the output item of the current node has a field correspondence or semantic association with the input data item of the next node, a semantic chain closed loop is formed, and step S50 is executed; If the output item of the current node does not have a field correspondence and no semantic relationship with the input data item of the next node, an anomaly is detected, and an anomaly message or repair suggestion is output.
[0012] Furthermore, it also includes step S60: S60: Compare the static analysis results of the intent field in the "intent-task code-test" ternary graph with the task code mapped to the intent one by one to detect whether there are any generation omissions, logical conflicts, or semantic drifts. If it does not exist, record a structured "intent-task code-test" ternary graph; If an error or conflict exists, a missing or conflict warning will be generated, along with suggested fixes.
[0013] Compared with existing technologies, this invention identifies and integrates heterogeneous intent sketches submitted by different roles, constructs "structured semantic intent" through clustering, intent normalization, and structured expression, and uses this as the driving force to realize task code generation, test generation, and consistency verification. Based on this, a ternary mapping of "intent-task code-test" is established, supporting tracking, verification, and conflict prompts. This not only effectively solves the problems of existing development tools, such as lack of cross-role requirement modeling, lack of end-to-end logical alignment and module connectivity, and lack of traceability of task code, tests, and original business intent, but also significantly improves collaborative development efficiency and consistency. It also has high versatility and scalability, and has outstanding engineering transformation value. Attached Figure Description
[0014] To better understand and implement this invention, the following detailed description is provided in conjunction with the accompanying drawings.
[0015] Figure 1 This is a flowchart of the structured code generation method based on multi-role intent sketch fusion according to the present invention. Detailed Implementation
[0016] The technical solutions of the present invention will now be clearly and completely described with reference to the accompanying drawings of the embodiments of the present invention. The described embodiments are merely some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the protection scope of the present invention.
[0017] Please see Figure 1 The structured code generation method based on multi-role intent sketch fusion described in this invention specifically includes the following steps.
[0018] S10: Preprocess the obtained character intent sketches to obtain a multi-character intent material pool.
[0019] In practice, various forms of intent sketches are obtained from different roles, including but not limited to front-end developers, back-end developers, and test engineers. The forms of intent sketches include but are not limited to natural language descriptions, flowcharts, pseudocode, structured comments, speech-to-text, and OCR images and text generated from handwritten sketches through image recognition.
[0020] Specifically, each role can express its work intent in any of the following forms: natural language description, hand-drawn or flowchart sketches, pseudocode snippets, structured comments, voice narration, or handwritten notes.
[0021] The preprocessing includes parsing the intent sketch, type identification, and standardization conversion, as detailed below.
[0022] SA1: Define each role and generate a set of roles.
[0023] Example: The set of characters is represented as R= ={Frontend, Backend, Test, ...}.
[0024] SA2: Summarize all intent sketches submitted by each role and generate a set of intent sketches for each role.
[0025] Example: The set of intention sketches for a character is represented as Sr= .
[0026] SA3: Perform type identification on the intention sketch set of each character and generate an intention sketch type set for each character.
[0027] Example: The set of intent sketch types for a certain character is represented as T={natural language, pseudocode, flowchart, annotation, voice text, OCR text}, with a one-to-one correspondence between the types and the intent sketch set.
[0028] SA4: Using a unified standardization function, the intent sketches of each character are processed into a unified format through type recognition and format conversion, resulting in a multi-character intent material pool and a standardized multi-character intent sketch set.
[0029] Example: Using a uniformly normalized function: Norm( →UnifiedFormat( This function converts all intent sketches in a character's intent sketch set into a unified format (si). .
[0030] The standardized multi-role intent sketch set is represented as: .
[0031] The fields for each intent sketch data entry interface are shown in Table 1.
[0032] Table 1
[0033] The intent sketches of each character are standardized and formatted as JSON, serving as one resource in the multi-character intent resource pool. An example of a character's intent sketch in the intent resource pool is shown below: { "role": "frontend", "type": "flowchart", "raw_input": "base64-encoded image", "normalized": { "nodes": ["input box", "submit button"], # indicates two identified graphical elements "edges": [["input box", "submit button"]]# This indicates that an arrow is drawn in the image, pointing from the "input box" to the "submit button"; }, "timestamp": "2025-05-16T14:30:00Z", "source": "Image OCR" }
[0034] S20: Align, semantically normalize, and aggregate cross-role intents in the multi-role intent material pool to obtain a structured semantic intent spectrum.
[0035] In practice, cross-source and cross-modal semantic fusion is performed on the intent sketches submitted by front-end, back-end, and testing roles. Specifically, through vectorized modeling, semantic matching, and structural alignment techniques, the partial views submitted by front-end, back-end, and testing roles are merged into a unified "structured semantic intent spectrum." This process not only solves problems such as information redundancy, inconsistent terminology, and process segmentation, but also constructs a semantically driven structured technical intent view as a prerequisite structure for code generation and verification.
[0036] S21: Perform semantic vectorization on each intention sketch in the standardized multi-role intention sketch set to obtain the semantic vector of each intention sketch.
[0037] Specifically, a multimodal coding model, such as CLIP + NLP encoder, is used to convert intention sketches such as natural language, flowcharts, and pseudocode into semantic vectors: E( = Encoder( ), Example, when ∈{Front-end intent sketches, test pseudocode, back-end descriptions, etc.}; Then the corresponding E( The meaning of ) is represented as E( = [Function description vector, Element category vector, Operation type vector] S22: Convert the semantic vectors of each intention sketch into high-dimensional semantic vectors to obtain the high-dimensional semantic vectors of each intention sketch.
[0038] Specifically, the Sentence-BERT encoder is used to transform the semantic vector of each intent sketch into a high-dimensional semantic vector: .
[0039] S23: Calculate the cosine similarity of the high-dimensional semantic vectors of any intention sketch pair. If the cosine similarity is greater than or equal to the similarity threshold, then set the intention sketch pair as a semantically related intention sketch pair.
[0040] like and The cosine similarity is expressed as ,like ,but This is a sketch pair of semantic association intentions.
[0041] The similarity threshold The threshold is adjustable and is typically set to 0.85.
[0042] S24: Construct a semantic similarity graph G=(V,E) based on the semantic association intent sketch, and obtain several semantic clusters Ci.
[0043] Specifically, it includes the following steps: S241: Construct a semantic similarity graph G=(V,E) based on the semantically associated intent sketches, where: V is the set of high-dimensional semantic vectors of the intent sketches; E is the set of edges that satisfy the cosine similarity greater than or equal to the similarity threshold; the weight of the edges is the cosine similarity.
[0044] The use of graph structures reflects which intentional sketches are semantically "of the same kind" or "similar," which is used for subsequent clustering or semantic merging.
[0045] Example: V set: each node A high-dimensional semantic vector representing an intent sketch; V = { v1: "Click the submit button", v2: "form submission", v3: "Username cannot be empty", ... } E: Edge set satisfy: The edge is This indicates that the two intention sketches are very close in semantic space; The weight of the edge is the cosine similarity. ; Construct a "semantic edge network": "Click the submit button" -- 0.91 -- "Form submission" │ 0.47 │ Username cannot be empty. S242: Use HDBSCAN to perform density clustering on the semantic similarity graph G=(V,E).
[0046] In the semantic similarity graph G=(V,E), the high-dimensional semantic vectors of all intent sketches are normalized, and cosine distance (cosine distance = 1 - ...) is used. This is used as a metric; then HDBSCAN is used for clustering to automatically divide semantic intent clusters with similar densities. C1,C2,...,Ci,...,Ck←HDBSCAN(G) Each cluster C i This represents a group of sketches that are semantically similar and can be categorized into the same intent category.
[0047] Clustered example: { "Cluster 1": ["Click the submit button", "form submission", "Click to query redirect"], "Cluster 2": ["Input Validation", "Username Cannot Be Empty", "Field Validation Prompt"], "Cluster 3": ["Invoking API to retrieve data", "Query request", "Retrieving list data"] } Furthermore, to improve clustering results, for image / voice-based intent sketches, such as UI flowcharts and voice annotations, the original information is often incomplete or lacks structural labels. Therefore, the following multimodal completion is performed before clustering: For image intent sketches: use structured OCR + image recognition models, such as LayoutLMv3 / PP-Structure, to extract key structural content; combine semantic scenarios, for example, a button labeled "Submit" + a form area → infer "form submission"; For speech intent sketches: the process is speech transcription → text preprocessing → noise removal + sentence segmentation → integration into semantic vector modeling.
[0048] S25: Extract "intent semantic tags" based on semantic clustering results, generate structured intent nodes and node relationships, and construct a structured semantic intent spectrum.
[0049] Specifically, for each semantic cluster Ci, representative "intent semantic labels" for each semantic cluster Ci are extracted through keyword co-occurrence analysis, semantic representation of cluster center vectors, and normalized label generation. Furthermore, based on these "intent semantic labels" and the intent sketch content in the corresponding cluster, structured intent nodes are generated. Then, by combining the triggering relationships, data dependency relationships, interface call relationships, or page jump relationships between different structured intent nodes, a structured semantic intent spectrum is constructed to facilitate subsequent structure unification, code generation, test generation, and semantic chain verification.
[0050] The keyword co-occurrence analysis refers to extracting high-frequency verb-object pairs, such as "click to submit", "input verification", and "request interface", from all intent sketch descriptions within each semantic cluster Ci, and statistically analyzing their frequency and co-occurrence patterns.
[0051] The semantic representation of the cluster center vector refers to taking the mean of the semantic vectors of all intent sketches within each semantic cluster Ci, using this mean as the cluster center vector vi-center of the semantic cluster Ci, and performing nearest neighbor matching with the preset intent label space to enhance semantic stability.
[0052] The normalized label generation refers to combining the keyword co-occurrence analysis results with the semantic representation results of the cluster center vector, and using template induction to generate normalized labels as abstract "intent semantic labels" for the cluster.
[0053] The structured intent node generation refers to extracting triggering behavior, input data items, output result items, participating roles, and source fragment information based on the "intent semantic label" corresponding to each semantic cluster Ci and the intent sketch content in the cluster, generating corresponding structured intent nodes, and configuring a unique intent identifier for each structured intent node; wherein, the unique intent identifier is used to realize node association, relationship reference, code mapping, test binding, and semantic chain tracing in the structured semantic intent spectrum.
[0054] The structured intent node includes at least: intent_id: A unique identifier for the intent; intent_label: semantic label of intent; trigger: triggers an action; inputs: Input data items; outputs: Output items; responsible_roles: Participating roles; source_fragments: A collection of source fragment images; The intent_label represents the semantic label corresponding to the semantic cluster, used to characterize the business intent semantic category corresponding to that semantic cluster; the intent_label is obtained through keyword co-occurrence analysis, semantic representation of cluster center vectors, and normalized label generation processing; for example, the intent_label may include: Submit the registration form; Front-end input validation; Interface data query; User login verification.
[0055] The intent_id represents a unique identifier for a structured intent node, used to implement node association, relationship referencing, code mapping, test binding, and semantic chain tracing in the structured semantic intent spectrum; for example: { "intent_id": "register_submit", "intent_label": "Registration form submitted" }
[0056] The construction of the structured semantic intent spectrum refers to establishing association edges between structured intent nodes based on the input-output semantic association, trigger behavior association, interface call relationship, or page jump relationship between different structured intent nodes, forming a structured semantic intent spectrum composed of structured intent nodes and node association edges.
[0057] Specifically, if the output item of the first structured intent node and the input data item of the second structured intent node have a field correspondence or semantic association, a data dependency relationship is established between the two structured intent nodes; if the triggering behavior of the first structured intent node is associated with the execution precondition of the second structured intent node, a trigger flow relationship is established between the two structured intent nodes.
[0058] The resulting structured semantic intent spectrum can not only serve as an anchor point for semantic normalization and structural unification, but also support upstream and downstream binding in subsequent processes such as code generation, test generation, semantic chain verification, conflict detection, consistency analysis, and intent-code-test mapping tracing.
[0059] For an example, please see Table 2.
[0060] Table 2
[0061] Furthermore, in order to ensure the consistency and robustness of the semantics within the clustering results, consistency verification and anomaly removal are also included after clustering is completed, as shown in step S26.
[0062] S26: Calculate the relationship between each high-dimensional semantic vector and the cluster center v in semantic clustering Ci. i-center The cosine similarity, if If the sample is a semantically drifted sample, the high-dimensional semantic vector will be removed from the current cluster.
[0063] Specifically, Set it to 0.75.
[0064] S30: Drive the association generation of multi-role corresponding codes with structured semantic intent spectrum, and generate complete task code that integrates the logical chain of multiple roles.
[0065] Driven by "structured semantic intent spectrum", it automatically generates and arranges the associated code snippets of multiple roles and generates end-to-end task code, including front-end logic, interface definition, test scripts, etc., and automatically completes dependencies, data flow and call relationships.
[0066] Specifically, it includes the following steps: S31: Extract various structured intents from the structured semantic intent spectrum.
[0067] The structured intent is an intent cluster, as shown in the following example: { "intent_id": "register_submit", "intent_label": "Registration form submission", "trigger": ["Click the submit button"], "inputs": ["username", "password", "email"], "outputs": ["Status code 200", "User ID"], "responsible_roles": ["frontend", "backend", "testing"], "source_fragments": ["s_01", "s_14", "s_27"] }
[0068] S32: Generate rules for the structured behaviors corresponding to each role for each type of structured intent mapping.
[0069] For example, if the structured intent is "Registration Form Submission", the code snippets generated by the structured behavior generation rules for each role are as follows: (1) Backend generated fragment: @app.route(" / register", methods=["POST"]) def register_user(): data = request.json If not data["username"]: return {"error": "Username cannot be empty"} user_id = db.save(data) return {"status": 200, "user_id": user_id}.
[0070] (2) Front-end generated fragment: function submitRegister() { if (!input.username) { alert("Username cannot be empty"); return;} axios.post(" / register", {...}).then(res =>showUserID(res.user_id)); }
[0071] (3) Test generated fragment: def test_register_api(): payload = {"username": "Zhang San", "password": "123456", "email": "test@test.com"} res = requests.post(" / register", json=payload) assert res.status_code == 200 assert "user_id" in res.json().
[0072] S33: Associate and arrange the structured behavior generation rules of different roles belonging to the same structured intent node according to the "trigger-input-output" logic to generate a complete functional logic chain and corresponding task code across roles.
[0073] Specifically, it includes the following steps: S331: Aggregate cross-role intent sketch image segments based on "intent semantic tags" and merge them into the same intent unit.
[0074] For example, summarizing "semantic fragments" from roles such as front-end, back-end, and testing.
[0075] S332: Construct logical association links based on trigger-input-output within the same intent unit.
[0076] Example: { "intent_id": "register_submit", "front_end": { "trigger": "Click the submit button", "outputs": ["Calling / api / register"] }, "back_end": { "trigger": "Received API request", "inputs": ["username", "password"], "outputs": ["Written to database", "Returned status code 200"] }, "test": { "trigger": "API response", "inputs": ["Status code 200"], "outputs": ["Assert that user_id exists"] } } After being orchestrated, a complete logical execution chain is formed: user click → trigger interface → backend processing → data writing → response return → test verification.
[0077] Furthermore, if there are conflicts in interface, variable naming, or format during the generation of logical chain associations, these conflicts can be automatically repaired through unified naming rules or generative rewriting before being concatenated.
[0078] For example, if the front-end, back-end, or testing interfaces have inconsistent naming conventions / parameters, such as one using / register and the other using / user_register, a unified naming template or semantic rewrite model can be used to automatically standardize the interface name, parameters, and return format. Generative automatic rewriting can be done through LLM, for example, standardizing both "regUser" and "createUser" to / api / register.
[0079] Connect the "semantic puzzle pieces" scattered among different roles into a complete functional flow, and fix interface naming / variable conflicts to ensure semantic consistency, data consistency, and process consistency in front-end and back-end testing.
[0080] S34: Generate code snippets from the structured behavior generation rules corresponding to the role according to the associated functional logic chain, and output them as a standardized directory structure.
[0081] The standardized directory structure is used to record the mapping relationship between intents and code files, as shown below: / generated_code / ├── frontend / │└── register_form.js ├── backend / │└── register_api.py ├── tests / │└── test_register.py └── mapping.json.
[0082] Each file originates from a structured intent transformation of the corresponding role sketch, ensuring that the code organization and semantic consistency are consistent.
[0083] Furthermore, to ensure the traceability and semantic consistency of the generated code, a structured mapping record of "intent-role sketch-generated code" is constructed simultaneously.
[0084] Specifically, the structured mapping record of "Intent - Character Sketch - Generated Code" is as follows: { "intent_id": "register_submit", "files": { "frontend": "register_form.js", "backend": "register_api.py", "test": "test_register.py" }, "linked_fragments": ["s_01", "s_14", "s_27"] }
[0085] The linked_fragments section records the IDs of all grass image segments involved in generating this intent, supporting subsequent semantic graph display and conflict alerts.
[0086] S40: Generate test cases based on the structured semantic intent spectrum and construct semantic link verification logic to verify whether the task code is consistent with the input-output relationship, business constraint relationship, and semantic link relationship in the structured semantic intent spectrum. If they match, proceed to step S50; If there is a discrepancy, an anomaly is detected, and an anomaly message or repair suggestion is output.
[0087] Specifically, it includes the following steps: S41: Generate test cases and test assertions based on the structured intents of the structured semantic intent spectrum. The test assertions refer to the result verification logic generated by the output result items in the structured intents, which are used to verify whether the execution result of the task code conforms to the expected output corresponding to the structured intents.
[0088] Test cases are generated based on the following fields: trigger: Generates the preceding behavior in the test, such as click or input; inputs: Automatically completes necessary test data, including boundary values, null values, etc. outputs: Assert expected results, including page prompts, API responses, etc.
[0089] Example: Structured intent: { "intent_id": "register_submit", "trigger": ["Click the submit button"], "inputs": ["username", "password", "email"], "outputs": ["Status code 200", "User ID"] } Generate test steps, expressed using Python + pytest: def test_register_submit(): driver.get("http: / / example.com / register") driver.find_element(...).send_keys("test_user") driver.find_element(...).send_keys("123456") driver.find_element(...).send_keys("test@example.com") driver.find_element(...).click() response = get_last_api_response() assert response.status_code == 200 assert "user_id" in response.json() S42: Compare the output of the current node and the input of the next node in the cross-intent link of the test case: If the output item of the current node has a field correspondence or semantic association with the input data item of the next node, a semantic chain closed loop is formed, and step S50 is executed; If the output item of the current node does not have a field correspondence and no semantic relationship with the input data item of the next node, an anomaly is detected, and an anomaly message or repair suggestion is output.
[0090] This will verify the consistency of data items (naming, type, source) and the closed-loop nature of the call order between links, and will be used to alert users of conflict or link break risks when mismatches are found.
[0091] Specifically, the error message is as follows: If the fields on the front end and back end are inconsistent, a data misalignment warning will be displayed; for example, "userID" vs "user_id". If the source cannot be traced or the successor node is missing, it indicates a broken link; If an intent exists but no test assertion is generated, a message will be displayed indicating that the test is missing.
[0092] The test assertion refers to the result verification logic generated by the output result item in the structured intent node, used to verify whether the interface response, page state, returned fields or data results meet expectations.
[0093] The repair recommendations are as follows: For misaligned data, fields will be automatically renamed and aligned. For a broken link, infer possible intentions to complete the path; For missing tests, complete the test assertion template.
[0094] S50: Based on the structured semantic intent spectrum and the generated task code and test cases, the mapping relationship between the structured semantic intent spectrum, task code and test cases is associated and stored to establish a structured "intent-task code-test" ternary mapping graph.
[0095] After completing the generation of multi-role task code and test results, based on the structured semantic intent spectrum and the generated task code and test cases, the mapping relationship between the structured semantic intent spectrum, task code and test cases is associated and stored to establish a structured "intent-task code-test" ternary mapping graph, which is used to realize code tracing, intent alignment, consistency detection and conflict prompts, thereby ensuring the structural transparency and logical consistency of the end-to-end development process.
[0096] An example of the structure of the "intent-task code-test" ternary graph is as follows: { "intent_id": "register_submit", "intent_label": "User registration submitted", "trigger": ["Click the submit button"], "inputs": ["username", "password", "email"], "outputs": ["Status code 200", "User ID"], "mapping": { "frontend": "frontend / register_form.js", "backend": "backend / register_api.py", "test": "tests / test_register.py" }, "source_fragments": ["Intent Sketch_14", "Intent Sketch_27", "Intent Sketch_35"] } All ternary graph relationships are serialized and saved as a JSON list, which will be used for consistency checks, debugging mappings, and quickly locating the source of generation.
[0097] Furthermore, it also includes a consistency detection step S60.
[0098] S60: Compare the static analysis results of the intent field in the "intent-task code-test" ternary graph with the task code mapped to the intent one by one to detect whether there are any generation omissions, logical conflicts, or semantic drifts. If it does not exist, record a structured "intent-task code-test" ternary graph; If an error or conflict exists, a missing or conflict warning will be generated, along with suggested fixes.
[0099] The structured intent fields, such as trigger, inputs, outputs, etc.
[0100] Examples of the comparison methods are shown in Table 3.
[0101] Table 3
[0102] For the detected issues, remediation suggestions include completing interface parameters, completing test assertions, and standardizing field names. Specifically, these include: If inconsistencies in variable / field naming are detected, unify the naming to standardize the fields; If a missing assertion is detected in the output field, a test assertion template is generated for developers to use. If using LLM, missing segments can be filled in based on the intent structure and existing code, and suggestions or candidate code can be generated.
[0103] The semantic drift refers to the inconsistency between the generated code and the input-output dependencies, state transition relationships, or business constraints in the structured semantic intent spectrum.
[0104] Compared to existing technologies, this invention can unify and integrate various forms of sketches, such as natural language, pseudocode, and flowcharts, submitted by multiple roles (e.g., front-end, back-end, and testers), automatically extracting and aggregating them into structured semantic intents, thereby driving end-to-end code and test generation. It effectively solves key problems in existing technologies such as isolated fragments, broken intents, and untraceable mappings. Compared to traditional methods that focus only on a single perspective or local generation, this method achieves an automated development closed loop with multi-role collaboration, full-process coverage, intent alignment, and traceable verification, possessing higher maintainability, consistency, and automation, effectively improving development efficiency and quality control capabilities.
[0105] Meanwhile, the structured code generation method based on multi-role intention sketch fusion is stored in an electronic device and executed by the electronic device to generate structured code based on multi-role intention sketch fusion.
[0106] The electronic devices include, but are not limited to, memory, processor, and network interface that can communicate with each other via a system bus.
[0107] The electronic device can be a rack server, blade server, tower server, or cabinet server, or other computing device. The electronic device can be a standalone server or a server cluster composed of multiple servers.
[0108] The memory includes at least an SD card and an electrically erasable programmable read-only memory (EEPROM). The memory can be an internal storage unit of the electronic device, such as a hard drive or RAM. The memory can also be an external storage device of the electronic device, such as a plug-in hard drive or a Secure Digital (SD) card. The memory may also include both internal and external storage units of the electronic device.
[0109] The processor can be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. This processor is typically used to control the overall operation of the electronic device, such as performing control and processing related to data interaction or communication with the electronic device. The processor is used to run program code stored in the memory or process data, such as running the structured code generation method based on multi-role intent sketch fusion.
[0110] The network interface may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the electronic device and other electronic devices. For example, the network interface is used to connect the electronic device to an external data platform via a network, establishing a data transmission channel and communication connection between the electronic device and the external data platform. The network may be an intranet, the Internet, Global System for Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, or other wireless or wired networks.
[0111] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indication will also change accordingly.
[0112] Furthermore, the use of terms such as "first" and "second" in this invention is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. Additionally, the technical solutions of the various embodiments can be combined with each other, but only on the basis of being achievable by those skilled in the art. If the combination of technical solutions is contradictory or impossible to implement, such a combination of technical solutions should be considered non-existent and not within the scope of protection claimed by this invention.
[0113] The embodiments described above are merely examples of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and the present invention also intends to include these modifications and variations.
Claims
1. A structured code generation method based on multi-role intent sketch fusion, characterized in that, Includes the following steps: S10: Preprocess the obtained character intention sketches to obtain a multi-character intention material pool; S20: Align, semantically normalize, and aggregate cross-role intentions in the multi-role intention material pool to obtain a structured semantic intention spectrum; S30: Drive the association generation of multi-role corresponding codes with structured semantic intent spectrum, and generate complete task code that integrates the logical chain of multiple roles; S40: Generate test cases based on the structured semantic intent spectrum and construct semantic link verification logic to verify whether the task code is consistent with the input-output relationship, business constraint relationship, and semantic link relationship in the structured semantic intent spectrum. If they match, proceed to step S50; If there is a discrepancy, an anomaly is identified: S50: Based on the structured semantic intent spectrum and the generated task code and test cases, the mapping relationship between the structured semantic intent spectrum, task code and test cases is associated and stored to establish a structured "intent-task code-test" ternary mapping graph.
2. The structured code generation method based on multi-role intent sketch fusion according to claim 1, characterized in that, The preprocessing in step S10 includes the following sub-steps: SA1: Define each role and generate a role set; SA2: Summarize all intent sketches submitted by each role and generate a set of intent sketches for each role; SA3: Perform type identification on the intention sketch set of each character and generate an intention sketch type set for each character; SA4: Using a unified standardization function, the intent sketches of each character are processed into a unified format through type recognition and format conversion, resulting in a multi-character intent material pool and a standardized multi-character intent sketch set.
3. The structured code generation method based on multi-role intent sketch fusion according to claim 2, characterized in that, Step S20 includes the following sub-steps: S21: Perform semantic vectorization on each intention sketch in the standardized multi-role intention sketch set to obtain the semantic vector of each intention sketch; S22: Convert the semantic vectors of each intention sketch into high-dimensional semantic vectors to obtain the high-dimensional semantic vectors of each intention sketch; S23: Calculate the cosine similarity of the high-dimensional semantic vectors of any intention sketch pair. If the cosine similarity is greater than or equal to the similarity threshold, then set the intention sketch pair as a semantically related intention sketch pair. S24: Construct a semantic similarity graph G=(V,E) based on the semantic association intent sketch, and obtain several semantic clusters Ci; S25: Extract "intent semantic tags" based on semantic clustering results, generate structured intent nodes and node relationships, and construct a structured semantic intent spectrum.
4. The structured code generation method based on multi-role intent sketch fusion according to claim 3, characterized in that, The "intent semantic tag" in step S25 is obtained in the following way: Keyword co-occurrence analysis: High-frequency verb-object pairs are extracted from all intent sketch descriptions within each semantic cluster Ci, and their frequency of occurrence and co-occurrence patterns are statistically analyzed; Semantic representation of cluster center vectors: The mean of the semantic vectors of all intent sketches within each semantic cluster Ci is calculated, and this mean is used as the cluster center v of that semantic cluster Ci. i-center ; The keyword co-occurrence analysis results are combined with the semantic representation results of the cluster center vector, and a standardized label is generated by template induction as the "intent semantic label" of the cluster. The "intent semantic label" is used to characterize the business intent semantic category corresponding to the semantic cluster Ci. The structured intent node is obtained in the following way: Based on the "intent semantic label" corresponding to each semantic cluster Ci and the intent sketch content in the cluster, the triggering behavior, input data items, output result items, participating roles and source fragment information are extracted to generate the corresponding structured intent node, and a unique intent identifier is configured for the structured intent node; the unique intent identifier is used to realize node association, relationship reference, code mapping, test binding and semantic chain tracing in the structured semantic intent spectrum.
5. The structured code generation method based on multi-role intent sketch fusion according to claim 4, characterized in that, Step S20 further includes: S26: Calculate the relationship between each high-dimensional semantic vector and the cluster center v in semantic clustering Ci. i-center The cosine similarity, if If the sample is a semantically drifted sample, the high-dimensional semantic vector will be removed from the current cluster.
6. The structured code generation method based on multi-role intent sketch fusion according to claim 3, characterized in that, Step S24 includes the following sub-steps: S241: Construct a semantic similarity graph G=(V,E) based on the semantically associated intent sketches, where: V is the set of high-dimensional semantic vectors of the intent sketches; E is the set of edges that satisfy the cosine similarity greater than or equal to the similarity threshold; the weight of the edge is the cosine similarity. S242: Use HDBSCAN to perform density clustering on the semantic similarity graph G=(V,E).
7. The structured code generation method based on multi-role intent sketch fusion according to claim 1, characterized in that, Step S30 includes the following sub-steps: S31: Extract various types of structured intents from the structured semantic intent spectrum; S32: Generate rules for the structured behaviors corresponding to each role for each type of structured intent; S33: Associate and arrange the structured behavior generation rules of different roles belonging to the same structured intent node according to the "trigger-input-output" logic to generate a complete functional logic chain across roles and corresponding task code; Step S40 includes the following sub-steps: S41: Generate test cases and test assertions based on the structured intents of the structured semantic intent spectrum. The test assertions refer to the result verification logic generated by the output result items in the structured intents, which are used to verify whether the execution result of the task code conforms to the expected output corresponding to the structured intents. S42: Compare the output of the current node and the input of the next node in the cross-intent link of the test case: If the output item of the current node has a field correspondence or semantic association with the input data item of the next node, a semantic chain closed loop is formed, and step S50 is executed; If the output item of the current node does not have a field correspondence and no semantic relationship with the input data item of the next node, an anomaly is detected, and an anomaly message or repair suggestion is output.
8. The structured code generation method based on multi-role intent sketch fusion according to claim 1, characterized in that, It also includes step S60: S60: Compare the static analysis results of the intent field in the "intent-task code-test" ternary graph with the task code mapped to the intent one by one to detect whether there are any generation omissions, logical conflicts, or semantic drifts. If it does not exist, record a structured "intent-task code-test" ternary graph; If an error or conflict exists, a missing or conflict warning will be generated, along with suggested fixes.
9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory storing programs or instructions that can run on the processor, the programs or instructions being executed by the processor to implement the steps of the structured code generation method based on multi-role intent sketch fusion as described in any one of claims 1 to 8.
10. A readable storage medium, characterized in that, The program or instructions are stored on the readable storage medium, and when the program or instructions are executed by a processor, they implement the steps of the structured code generation method based on multi-role intent sketch fusion as described in any one of claims 1 to 8.